Debian Codegraph @

bin/mkdep

raw
1 #!/bin/sh -
2 #
3 # Copyright (c) 1987 Regents of the University of California.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms are permitted
7 # provided that the above copyright notice and this paragraph are
8 # duplicated in all such forms and that any documentation,
9 # advertising materials, and other materials related to such
10 # distribution and use acknowledge that the software was developed
11 # by the University of California, Berkeley. The name of the
12 # University may not be used to endorse or promote products derived
13 # from this software without specific prior written permission.
14 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 #
18 # @(#)mkdep.sh 5.12 (Berkeley) 6/30/88
19 #
20
21 MAKE=Makefile # default makefile name is "Makefile"
22 CC=cc # default C compiler is "cc"
23
24 while :
25 do case "$1" in
26 # -c allows you to specify the C compiler
27 -c)
28 CC=$2
29 shift; shift ;;
30
31 # -f allows you to select a makefile name
32 -f)
33 MAKE=$2
34 shift; shift ;;
35
36 # the -p flag produces "program: program.c" style dependencies
37 # so .o's don't get produced
38 -p)
39 SED='s;\.o;;'
40 shift ;;
41 *)
42 break ;;
43 esac
44 done
45
46 if [ $# = 0 ] ; then
47 echo 'usage: mkdep [-p] [-c cc] [-f makefile] [flags] file ...'
48 exit 1
49 fi
50
51 if [ ! -w $MAKE ]; then
52 echo "mkdep: no writeable file \"$MAKE\""
53 exit 1
54 fi
55
56 TMP=/tmp/mkdep$$
57
58 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
59
60 cp $MAKE ${MAKE}.bak
61
62 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
63
64 cat << _EOF_ >> $TMP
65 # DO NOT DELETE THIS LINE -- mkdep uses it.
66 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
67
68 _EOF_
69
70 # If your compiler doesn't have -M, add it. If you can't, the next two
71 # lines will try and replace the "cc -M". The real problem is that this
72 # hack can't deal with anything that requires a search path, and doesn't
73 # even try for anything using bracket (<>) syntax.
74 #
75 # egrep '^#include[ ]*".*"' /dev/null $* |
76 # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
77
78 $CC -MM $* |
79 sed "
80 s; \./; ;g
81 $SED" >> $TMP
82
83 cat << _EOF_ >> $TMP
84
85 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
86 _EOF_
87
88 # copy to preserve permissions
89 cp $TMP $MAKE
90 rm -f ${MAKE}.bak $TMP
91 exit 0