host-mkdep.in revision 1.5       1  1.4  thorpej #!@BSHELL@ -
      2  1.1       tv #
      3  1.5  thorpej #	$NetBSD: host-mkdep.in,v 1.5 2003/03/13 04:40:45 thorpej 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.1       tv 
     45  1.1       tv while [ $# -gt 0 ]; do
     46  1.1       tv 	case "$1" in
     47  1.1       tv 	-a)	APPEND=true; shift;;
     48  1.1       tv 
     49  1.1       tv 	-f)	OUTFILE=$2; shift; shift;;
     50  1.1       tv 
     51  1.1       tv 	-p)	NEWEXT=; shift;;
     52  1.1       tv 
     53  1.1       tv 	*)	break;;
     54  1.1       tv 	esac
     55  1.1       tv done
     56  1.1       tv 
     57  1.1       tv if [ $# = 0 ] ; then
     58  1.1       tv 	echo "usage: $0 [-a] [-p] [-f makefile] [flags] file ..."
     59  1.1       tv 	exit 1
     60  1.1       tv fi
     61  1.1       tv 
     62  1.1       tv while [ $# -gt 0 ]; do
     63  1.1       tv 	case "$1" in
     64  1.1       tv 	-L)		shift; shift;; # takes an arg, but ignored
     65  1.1       tv 
     66  1.1       tv 	-c|-[lLMOW]*)	shift;; # takes no extra args
     67  1.1       tv 
     68  1.1       tv 	-[IDU]*)	CPPFLAGS="$CPPFLAGS $1"; shift;;
     69  1.1       tv 
     70  1.1       tv 	-[IDU]|-include)
     71  1.1       tv 			CPPFLAGS="$CPPFLAGS $1 $2"; shift; shift;;
     72  1.5  thorpej 
     73  1.5  thorpej 	# This is a Darwin-specific option.
     74  1.5  thorpej 	-no-cpp-precomp)
     75  1.5  thorpej 			CPPFLAGS="$CPPFLAGS $1"; shift;;
     76  1.1       tv 
     77  1.1       tv 	-*)		echo "$0: unknown option: $1"; exit 1;; # all other -options
     78  1.1       tv 
     79  1.1       tv 	*)		SRCS="$SRCS $1"; shift;; # source file
     80  1.1       tv 	esac
     81  1.1       tv done
     82  1.1       tv 
     83  1.1       tv TMP=/tmp/mkdep$$
     84  1.1       tv rm -f $TMP
     85  1.1       tv 
     86  1.1       tv trap 'rm -f $TMP; exit 1' 1 2 3 13 15
     87  1.1       tv 
     88  1.1       tv for f in $SRCS; do
     89  1.1       tv 	@CPP@ $CPPFLAGS $f | @AWK@ '
     90  1.1       tv 		BEGIN {
     91  1.1       tv 			objfile = "'$f'"
     92  1.1       tv 			sub(/^.*\//, "", objfile)
     93  1.1       tv 			sub(/\.(c|cc|m)$/, "'$NEWEXT'", objfile)
     94  1.1       tv 		}
     95  1.1       tv 		/^#/ {
     96  1.1       tv 			# Be as tolerant as possible.
     97  1.2       tv 			sub(/^#(line)? [ 0-9]*\"?/, "")
     98  1.3  thorpej 			sub(/^#(pragma).*/, "")
     99  1.3  thorpej 			sub(/^<.*/, "")
    100  1.1       tv 			sub(/\".*$/, "")
    101  1.1       tv 			sub(/ [ 0-9]*$/, "")
    102  1.1       tv 
    103  1.1       tv 			if ($0 in seenfiles) next
    104  1.1       tv 			if ($0 ~ /y.tab.c/) next
    105  1.1       tv 
    106  1.1       tv 			seenfiles[$0] = 1
    107  1.1       tv 			print objfile ": " $0
    108  1.1       tv 		}
    109  1.1       tv 	' >>$TMP
    110  1.1       tv done
    111  1.1       tv 
    112  1.1       tv if $APPEND; then
    113  1.1       tv 	cat $TMP >>$OUTFILE
    114  1.1       tv else
    115  1.1       tv 	cat $TMP >$OUTFILE
    116  1.1       tv fi
    117  1.1       tv 
    118  1.1       tv rm -f $TMP
    119  1.1       tv exit 0
    120