]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tcpdump/mkdep
unbound: Vendor import 1.19.0
[FreeBSD/FreeBSD.git] / contrib / tcpdump / mkdep
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 MAKE=Makefile                   # default makefile name is "Makefile"
17 CC=cc                           # default C compiler is "cc"
18 DEPENDENCY_CFLAG=-M             # default dependency-generation flag is -M
19 SOURCE_DIRECTORY=.              # default source directory is the current directory
20
21 # No command-line flags seen yet.
22 flags=""
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                 # -s allows you to specify the source directory
47                 -s)
48                         SOURCE_DIRECTORY=$2
49                         shift; shift ;;
50
51                 # other command-line flag
52                 -*)
53                         flags="$flags $1"
54                         shift ;;
55
56                 *)
57                         break ;;
58         esac
59 done
60
61 if [ $# = 0 ] ; then
62         echo 'usage: mkdep [-p] [-c cc] [-f makefile] [-m dependency-cflag] [-s source-directory] [flags] file ...'
63         exit 1
64 fi
65
66 if [ ! -w $MAKE ]; then
67         echo "mkdep: no writeable file \"$MAKE\""
68         exit 1
69 fi
70
71 TMP=/tmp/mkdep$$
72
73 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
74
75 cp $MAKE ${MAKE}.bak
76
77 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
78
79 cat << _EOF_ >> $TMP
80 # DO NOT DELETE THIS LINE -- mkdep uses it.
81 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
82
83 _EOF_
84
85 # If your compiler doesn't have -M, add it.  If you can't, the next two
86 # lines will try and replace the "cc -M".  The real problem is that this
87 # hack can't deal with anything that requires a search path, and doesn't
88 # even try for anything using bracket (<>) syntax.
89 #
90 # grep -E '^#include[[:blank:]]*".*"' /dev/null $* |
91 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
92
93 #
94 # Construct a list of source files with paths relative to the source directory.
95 #
96 sources=""
97 for srcfile in $*
98 do
99         sources="$sources $SOURCE_DIRECTORY/$srcfile"
100 done
101
102 # XXX this doesn't work with things like "-DDECLWAITSTATUS=union\ wait"
103 $CC $DEPENDENCY_CFLAG $flags $sources |
104 sed "
105         s; \./; ;g
106         $SED" >> $TMP
107
108 cat << _EOF_ >> $TMP
109
110 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
111 _EOF_
112
113 # copy to preserve permissions
114 cp $TMP $MAKE
115 rm -f ${MAKE}.bak $TMP
116 exit 0