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