Home | History | Annotate | Line # | Download | only in host-mkdep
host-mkdep.in revision 1.8
      1  1.4   thorpej #!@BSHELL@ -
      2  1.1        tv #
      3  1.8  christos #	$NetBSD: host-mkdep.in,v 1.8 2003/06/10 20:40:39 christos Exp $
      4  1.1        tv #
      5  1.1        tv # Copyright (c) 1991, 1993
      6  1.1        tv #	The Regents of the University of California.  All rights reserved.
      7  1.1        tv #
      8  1.1        tv # Redistribution and use in source and binary forms, with or without
      9  1.1        tv # modification, are permitted provided that the following conditions
     10  1.1        tv # are met:
     11  1.1        tv # 1. Redistributions of source code must retain the above copyright
     12  1.1        tv #    notice, this list of conditions and the following disclaimer.
     13  1.1        tv # 2. Redistributions in binary form must reproduce the above copyright
     14  1.1        tv #    notice, this list of conditions and the following disclaimer in the
     15  1.1        tv #    documentation and/or other materials provided with the distribution.
     16  1.1        tv # 3. All advertising materials mentioning features or use of this software
     17  1.1        tv #    must display the following acknowledgement:
     18  1.1        tv #	This product includes software developed by the University of
     19  1.1        tv #	California, Berkeley and its contributors.
     20  1.1        tv # 4. Neither the name of the University nor the names of its contributors
     21  1.1        tv #    may be used to endorse or promote products derived from this software
     22  1.1        tv #    without specific prior written permission.
     23  1.1        tv #
     24  1.1        tv # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1        tv # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1        tv # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1        tv # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1        tv # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1        tv # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1        tv # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1        tv # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1        tv # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1        tv # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1        tv # SUCH DAMAGE.
     35  1.1        tv #
     36  1.1        tv #	@(#)mkdep.old.compiler	8.1 (Berkeley) 6/6/93
     37  1.1        tv #
     38  1.1        tv 
     39  1.1        tv APPEND=false
     40  1.1        tv CPPFLAGS=
     41  1.1        tv NEWEXT=.o
     42  1.1        tv OUTFILE=.depend
     43  1.1        tv SRCS=
     44  1.6  christos USAGE="Usage: $0 [-a] [-p] [-f makefile] [flags] file ..."
     45  1.1        tv 
     46  1.1        tv while [ $# -gt 0 ]; do
     47  1.1        tv 	case "$1" in
     48  1.6  christos 	-a)	APPEND=true
     49  1.6  christos 		shift
     50  1.6  christos 		;;
     51  1.6  christos 
     52  1.6  christos 	-f)	OUTFILE=$2
     53  1.6  christos 		shift 2
     54  1.6  christos 		;;
     55  1.6  christos 
     56  1.6  christos 	-p)	NEWEXT=
     57  1.6  christos 		shift
     58  1.6  christos 		;;
     59  1.1        tv 
     60  1.6  christos 	*)	break
     61  1.6  christos 		;;
     62  1.1        tv 	esac
     63  1.1        tv done
     64  1.1        tv 
     65  1.6  christos if [ $# = 0 ]; then
     66  1.6  christos 	echo "$USAGE" 1>&2
     67  1.1        tv 	exit 1
     68  1.1        tv fi
     69  1.1        tv 
     70  1.1        tv while [ $# -gt 0 ]; do
     71  1.1        tv 	case "$1" in
     72  1.6  christos 	-L)			# takes an arg, but ignored
     73  1.6  christos 			shift 2
     74  1.6  christos 			;;
     75  1.6  christos 
     76  1.6  christos 	-c|-[lLMOW]*)		# takes no extra args
     77  1.6  christos 			shift
     78  1.6  christos 			;;
     79  1.6  christos 
     80  1.6  christos 	-[IDU]*)
     81  1.6  christos 			CPPFLAGS="$CPPFLAGS $1"
     82  1.6  christos 			shift
     83  1.6  christos 			;;
     84  1.1        tv 
     85  1.8  christos 	-[IDU]|-include|-isystem)
     86  1.6  christos 			CPPFLAGS="$CPPFLAGS $1 $2"
     87  1.6  christos 			shift 2
     88  1.6  christos 			;;
     89  1.6  christos 
     90  1.6  christos 	-no-cpp-precomp)	# This is a Darwin-specific option.
     91  1.6  christos 			CPPFLAGS="$CPPFLAGS $1"
     92  1.6  christos 			shift
     93  1.6  christos 			;;
     94  1.6  christos 
     95  1.8  christos 	-nostdinc*)	# This is a gcc/g++ ism; ignore if not gcc/g++
     96  1.6  christos 			case "@CFLAGS@" in
     97  1.6  christos 			*-O2*)	# Autoconf puts -O2 when gcc only
     98  1.6  christos 				CPPFLAGS="$CPPFLAGS $1"
     99  1.6  christos 				;;
    100  1.6  christos 			esac	
    101  1.6  christos 			shift
    102  1.6  christos 			;;
    103  1.6  christos 
    104  1.6  christos 	-*)		
    105  1.6  christos 			echo "$0: Unknown option: $1" 1>&2 # all other -options
    106  1.6  christos 			exit 1
    107  1.6  christos 			;;
    108  1.6  christos 
    109  1.6  christos 	*)	
    110  1.6  christos 			SRCS="$SRCS $1"	# source file
    111  1.6  christos 			shift
    112  1.6  christos 			;;
    113  1.1        tv 	esac
    114  1.1        tv done
    115  1.1        tv 
    116  1.6  christos if [ -z "$SRCS" ]; then
    117  1.6  christos 	echo "$USAGE" 1>&2
    118  1.6  christos 	exit 1
    119  1.6  christos fi
    120  1.6  christos 
    121  1.1        tv TMP=/tmp/mkdep$$
    122  1.1        tv rm -f $TMP
    123  1.1        tv 
    124  1.1        tv trap 'rm -f $TMP; exit 1' 1 2 3 13 15
    125  1.1        tv 
    126  1.1        tv for f in $SRCS; do
    127  1.1        tv 	@CPP@ $CPPFLAGS $f | @AWK@ '
    128  1.1        tv 		BEGIN {
    129  1.1        tv 			objfile = "'$f'"
    130  1.1        tv 			sub(/^.*\//, "", objfile)
    131  1.1        tv 			sub(/\.(c|cc|m)$/, "'$NEWEXT'", objfile)
    132  1.1        tv 		}
    133  1.1        tv 		/^#/ {
    134  1.1        tv 			# Be as tolerant as possible.
    135  1.2        tv 			sub(/^#(line)? [ 0-9]*\"?/, "")
    136  1.3   thorpej 			sub(/^#(pragma).*/, "")
    137  1.3   thorpej 			sub(/^<.*/, "")
    138  1.1        tv 			sub(/\".*$/, "")
    139  1.1        tv 			sub(/ [ 0-9]*$/, "")
    140  1.1        tv 
    141  1.1        tv 			if ($0 in seenfiles) next
    142  1.1        tv 			if ($0 ~ /y.tab.c/) next
    143  1.1        tv 
    144  1.1        tv 			seenfiles[$0] = 1
    145  1.1        tv 			print objfile ": " $0
    146  1.1        tv 		}
    147  1.6  christos 	' >> $TMP
    148  1.1        tv done
    149  1.1        tv 
    150  1.1        tv if $APPEND; then
    151  1.6  christos 	cat $TMP >> $OUTFILE
    152  1.1        tv else
    153  1.6  christos 	cat $TMP > $OUTFILE
    154  1.1        tv fi
    155  1.1        tv 
    156  1.1        tv rm -f $TMP
    157  1.1        tv exit 0
    158