Home | History | Annotate | Download | only in tcpdump
      1 #!/bin/sh -
      2 #
      3 # Copyright (c) 1994, 1996
      4 #	The Regents of the University of California.  All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms are permitted
      7 # provided that this notice is preserved and that due credit is given
      8 # to the University of California at Berkeley. The name of the University
      9 # may not be used to endorse or promote products derived from this
     10 # software without specific prior written permission. This software
     11 # is provided ``as is'' without express or implied warranty.
     12 #
     13 #	@(#)mkdep.sh	5.11 (Berkeley) 5/5/88
     14 #
     15 
     16 PATH=/bin:/usr/bin:/usr/ucb:/usr/local:/usr/local/bin
     17 export PATH
     18 
     19 MAKE=Makefile			# default makefile name is "Makefile"
     20 CC=cc				# default C compiler is "cc"
     21 DEPENDENCY_CFLAG=-M		# default dependency-generation flag is -M
     22 
     23 while :
     24 	do case "$1" in
     25 		# -c allows you to specify the C compiler
     26 		-c)
     27 			CC=$2
     28 			shift; shift ;;
     29 
     30 		# -f allows you to select a makefile name
     31 		-f)
     32 			MAKE=$2
     33 			shift; shift ;;
     34 
     35 		# -m allows you to specify the dependency-generation flag
     36 		-m)
     37 			DEPENDENCY_CFLAG=$2
     38 			shift; shift ;;
     39 
     40 		# the -p flag produces "program: program.c" style dependencies
     41 		# so .o's don't get produced
     42 		-p)
     43 			SED='s;\.o;;'
     44 			shift ;;
     45 		*)
     46 			break ;;
     47 	esac
     48 done
     49 
     50 if [ $# = 0 ] ; then
     51 	echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [flags] file ...'
     52 	exit 1
     53 fi
     54 
     55 if [ ! -w $MAKE ]; then
     56 	echo "mkdep: no writeable file \"$MAKE\""
     57 	exit 1
     58 fi
     59 
     60 TMP=/tmp/mkdep$$
     61 
     62 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
     63 
     64 cp $MAKE ${MAKE}.bak
     65 
     66 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
     67 
     68 cat << _EOF_ >> $TMP
     69 # DO NOT DELETE THIS LINE -- mkdep uses it.
     70 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
     71 
     72 _EOF_
     73 
     74 # If your compiler doesn't have -M, add it.  If you can't, the next two
     75 # lines will try and replace the "cc -M".  The real problem is that this
     76 # hack can't deal with anything that requires a search path, and doesn't
     77 # even try for anything using bracket (<>) syntax.
     78 #
     79 # egrep '^#include[ 	]*".*"' /dev/null $* |
     80 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
     81 
     82 # XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
     83 $CC $DEPENDENCY_CFLAG $* |
     84 sed "
     85 	s; \./; ;g
     86 	$SED" |
     87 awk '{
     88 	if ($1 != prev) {
     89 		if (rec != "")
     90 			print rec;
     91 		rec = $0;
     92 		prev = $1;
     93 	}
     94 	else {
     95 		if (length(rec $2) > 78) {
     96 			print rec;
     97 			rec = $0;
     98 		}
     99 		else
    100 			rec = rec " " $2
    101 	}
    102 }
    103 END {
    104 	print rec
    105 }' >> $TMP
    106 
    107 cat << _EOF_ >> $TMP
    108 
    109 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
    110 _EOF_
    111 
    112 # copy to preserve permissions
    113 cp $TMP $MAKE
    114 rm -f ${MAKE}.bak $TMP
    115 exit 0
    116