Home | History | Annotate | Line # | Download | only in host-mkdep
host-mkdep.in revision 1.11
      1   1.4   thorpej #!@BSHELL@ -
      2   1.1        tv #
      3  1.11       dsl #	$NetBSD: host-mkdep.in,v 1.11 2003/11/10 17:57:43 dsl 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.11       dsl MERGE=false
     41  1.11       dsl OPTIONAL=false
     42  1.11       dsl AWK_OPTIONAL=
     43  1.11       dsl QUIET=false
     44   1.1        tv CPPFLAGS=
     45   1.1        tv NEWEXT=.o
     46   1.1        tv OUTFILE=.depend
     47   1.1        tv SRCS=
     48  1.11       dsl USAGE="Usage: $0 [-a] [-d] [-o] [-p] [-q] [-s suffix] [-f makefile] [flags] file ..."
     49  1.11       dsl 
     50  1.11       dsl set_objlist()
     51  1.11       dsl {
     52  1.11       dsl 	if [ -n "$NEWEXT" ]; then
     53  1.11       dsl 		oifs="$IFS"
     54  1.11       dsl 		IFS=" ,"
     55  1.11       dsl 		set -- $NEWEXT
     56  1.11       dsl 		IFS="$oifs"
     57  1.11       dsl 		objlist=
     58  1.11       dsl 		for suf in $*; do
     59  1.11       dsl 			objlist="$objlist${objlist:+ }$file$suf"
     60  1.11       dsl 		done
     61  1.11       dsl 	else
     62  1.11       dsl 		objlist="$file"
     63  1.11       dsl 	fi
     64  1.11       dsl }
     65   1.1        tv 
     66   1.1        tv while [ $# -gt 0 ]; do
     67   1.1        tv 	case "$1" in
     68   1.6  christos 	-a)	APPEND=true
     69   1.6  christos 		shift
     70   1.6  christos 		;;
     71   1.6  christos 
     72  1.11       dsl 	-d)	MERGE=true
     73  1.11       dsl 		shift
     74  1.11       dsl 		;;
     75  1.11       dsl 
     76   1.6  christos 	-f)	OUTFILE=$2
     77   1.6  christos 		shift 2
     78   1.6  christos 		;;
     79   1.6  christos 
     80  1.11       dsl 	-o)	OPTIONAL=true
     81  1.11       dsl 		AWK_OPTIONAL='print ".OPTIONAL:" $0'
     82  1.11       dsl 		shift
     83  1.11       dsl 		;;
     84  1.11       dsl 
     85   1.6  christos 	-p)	NEWEXT=
     86   1.6  christos 		shift
     87   1.6  christos 		;;
     88   1.1        tv 
     89  1.11       dsl 	-q)	QUIET=true
     90  1.11       dsl 		shift
     91  1.11       dsl 		;;
     92  1.11       dsl 
     93  1.11       dsl 	-s)	NEWEXT="$2"
     94  1.11       dsl 		shift 2
     95  1.11       dsl 		;;
     96  1.11       dsl 
     97  1.11       dsl 	-*)	$MERGE || break;
     98  1.11       dsl 		echo "$USAGE" >&2
     99  1.11       dsl 		exit 1
    100  1.11       dsl 		;;
    101  1.11       dsl 
    102   1.6  christos 	*)	break
    103   1.6  christos 		;;
    104   1.1        tv 	esac
    105   1.1        tv done
    106   1.1        tv 
    107   1.6  christos if [ $# = 0 ]; then
    108   1.6  christos 	echo "$USAGE" 1>&2
    109   1.1        tv 	exit 1
    110   1.1        tv fi
    111   1.1        tv 
    112  1.11       dsl if $MERGE; then
    113  1.11       dsl 	SRCS="$*"
    114  1.11       dsl else
    115  1.11       dsl 	while [ $# -gt 0 ]; do
    116  1.11       dsl 		case "$1" in
    117  1.11       dsl 		-L)			# takes an arg, but ignored
    118  1.11       dsl 				shift 2
    119  1.11       dsl 				;;
    120  1.11       dsl 
    121  1.11       dsl 		-c|-[lLMOW]*)		# takes no extra args
    122  1.11       dsl 				shift
    123  1.11       dsl 				;;
    124  1.11       dsl 
    125  1.11       dsl 		-[IDU]*)
    126  1.11       dsl 				CPPFLAGS="$CPPFLAGS $1"
    127  1.11       dsl 				shift
    128  1.11       dsl 				;;
    129  1.11       dsl 
    130  1.11       dsl 		-[IDU]|-include|-isystem)
    131  1.11       dsl 				CPPFLAGS="$CPPFLAGS $1 $2"
    132  1.11       dsl 				shift 2
    133  1.11       dsl 				;;
    134  1.11       dsl 
    135  1.11       dsl 		-no-cpp-precomp)	# This is a Darwin-specific option.
    136   1.6  christos 				CPPFLAGS="$CPPFLAGS $1"
    137  1.11       dsl 				shift
    138  1.11       dsl 				;;
    139  1.11       dsl 
    140  1.11       dsl 		-nostdinc*)	# This is a gcc/g++ ism; ignore if not gcc/g++
    141  1.11       dsl 				case "@CFLAGS@" in
    142  1.11       dsl 				*-O2*)	# Autoconf puts -O2 when gcc only
    143  1.11       dsl 					CPPFLAGS="$CPPFLAGS $1"
    144  1.11       dsl 					;;
    145  1.11       dsl 				esac	
    146  1.11       dsl 				shift
    147   1.6  christos 				;;
    148  1.11       dsl 
    149  1.11       dsl 		-*)		
    150  1.11       dsl 				echo "$0: Unknown option: $1" 1>&2 # all other -options
    151  1.11       dsl 				exit 1
    152  1.11       dsl 				;;
    153  1.11       dsl 
    154  1.11       dsl 		*)	
    155  1.11       dsl 				SRCS="$SRCS $1"	# source file
    156  1.11       dsl 				shift
    157  1.11       dsl 				;;
    158  1.11       dsl 		esac
    159  1.11       dsl 	done
    160  1.11       dsl fi
    161   1.1        tv 
    162   1.6  christos if [ -z "$SRCS" ]; then
    163  1.10  christos 	echo "$USAGE" 1>&2
    164  1.10  christos 	exit 1
    165   1.6  christos fi
    166   1.6  christos 
    167   1.1        tv TMP=/tmp/mkdep$$
    168   1.1        tv rm -f $TMP
    169   1.1        tv 
    170   1.1        tv trap 'rm -f $TMP; exit 1' 1 2 3 13 15
    171   1.1        tv 
    172  1.11       dsl if $MERGE; then
    173  1.11       dsl 	for f in $SRCS; do
    174  1.11       dsl 		if [ ! -f "$f" ]; then
    175  1.11       dsl 			if ! $QUIET; then echo "$0: Ignoring $f" >&2; fi
    176  1.11       dsl 			continue
    177  1.11       dsl 		fi
    178  1.11       dsl 		while IFS=':'; read target dependants; do
    179  1.11       dsl 			IFS=
    180  1.11       dsl 			t1="${target#* }"
    181  1.11       dsl 			file="${target%.o}"
    182  1.11       dsl 			if [ "$t" = "$target" -a "$file" != "$target" ]; then
    183  1.11       dsl 				set_objlist $file
    184  1.11       dsl 				target="$objlist"
    185  1.11       dsl 			fi
    186  1.11       dsl 			echo "$target:$dependants"
    187  1.11       dsl 			if "$OPTIONAL"; then
    188  1.11       dsl 				echo ".OPTIONAL:$dependants"
    189  1.11       dsl 			fi
    190  1.11       dsl 		done <$f
    191  1.11       dsl 	done >$TMP
    192  1.11       dsl else
    193  1.11       dsl 	for f in $SRCS; do
    194  1.11       dsl 		file=${f##*/}
    195  1.11       dsl 		file=${file%.*}
    196  1.11       dsl 		set_objlist $file
    197  1.11       dsl 
    198  1.11       dsl 		@CPP@ $CPPFLAGS $f | @AWK@ '
    199  1.11       dsl 			/^#/ {
    200  1.11       dsl 				# Be as tolerant as possible.
    201  1.11       dsl 				sub(/^#(line)? [ 0-9]*\"?/, "")
    202  1.11       dsl 				sub(/^#(pragma).*/, "")
    203  1.11       dsl 				sub(/^<.*/, "")
    204  1.11       dsl 				sub(/\".*$/, "")
    205  1.11       dsl 				sub(/ [ 0-9]*$/, "")
    206  1.11       dsl 
    207  1.11       dsl 				if ($0 in seenfiles) next
    208  1.11       dsl 				if ($0 ~ /y.tab.c/) next
    209  1.11       dsl 
    210  1.11       dsl 				seenfiles[$0] = 1
    211  1.11       dsl 				print "'"$objlist"'" ": " $0
    212  1.11       dsl 				'"$AWK_OPTIONAL"'
    213  1.11       dsl 			}
    214  1.11       dsl 		' >> $TMP
    215  1.11       dsl 	done
    216  1.11       dsl fi
    217   1.1        tv 
    218   1.1        tv if $APPEND; then
    219   1.6  christos 	cat $TMP >> $OUTFILE
    220   1.1        tv else
    221   1.6  christos 	cat $TMP > $OUTFILE
    222   1.1        tv fi
    223   1.1        tv 
    224   1.1        tv rm -f $TMP
    225   1.1        tv exit 0
    226