Commit | Line | Data |
---|---|---|
043ab8c8 | 1 | #!/bin/sh - |
f48536ef | 2 | # |
043ab8c8 KB |
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 | |
dc45ba8c KB |
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. | |
043ab8c8 | 17 | # |
dc45ba8c | 18 | # @(#)mkdep.sh 5.12 (Berkeley) %G% |
f48536ef | 19 | # |
c0644842 KB |
20 | PATH=/bin:/usr/bin:/usr/ucb |
21 | export PATH | |
8c3305b6 | 22 | |
190489bd KB |
23 | MAKE=Makefile # default makefile name is "Makefile" |
24 | ||
25 | while : | |
26 | do case "$1" in | |
27 | # -f allows you to select a makefile name | |
28 | -f) | |
29 | MAKE=$2 | |
30 | shift; shift ;; | |
31 | ||
32 | # the -p flag produces "program: program.c" style dependencies | |
33 | # so .o's don't get produced | |
34 | -p) | |
742d9467 | 35 | SED='s;\.o;;' |
190489bd KB |
36 | shift ;; |
37 | *) | |
38 | break ;; | |
39 | esac | |
40 | done | |
41 | ||
0ee442d6 | 42 | if [ $# = 0 ] ; then |
a41d2463 | 43 | echo 'usage: mkdep [-p] [-f makefile] [flags] file ...' |
0ee442d6 KB |
44 | exit 1 |
45 | fi | |
46 | ||
9f4ff9c5 KB |
47 | if [ ! -w $MAKE ]; then |
48 | echo "mkdep: no writeable file \"$MAKE\"" | |
0ee442d6 KB |
49 | exit 1 |
50 | fi | |
51 | ||
f48536ef KB |
52 | TMP=/tmp/mkdep$$ |
53 | ||
8c3305b6 | 54 | trap 'rm -f $TMP ; exit 1' 1 2 3 13 15 |
f48536ef | 55 | |
8c3305b6 | 56 | cp $MAKE ${MAKE}.bak |
f48536ef | 57 | |
8c3305b6 | 58 | sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP |
f48536ef KB |
59 | |
60 | cat << _EOF_ >> $TMP | |
0ee442d6 KB |
61 | # DO NOT DELETE THIS LINE -- mkdep uses it. |
62 | # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. | |
f48536ef KB |
63 | |
64 | _EOF_ | |
65 | ||
e2b7b485 KB |
66 | # If your compiler doesn't have -M, add it. If you can't, the next two |
67 | # lines will try and replace the "cc -M". The real problem is that this | |
68 | # hack can't deal with anything that requires a search path, and doesn't | |
69 | # even try for anything using bracket (<>) syntax. | |
70 | # | |
71 | # egrep '^#include[ ]*".*"' /dev/null $* | | |
72 | # sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' | | |
73 | ||
742d9467 KB |
74 | cc -M $* | |
75 | sed " | |
76 | s; \./; ;g | |
77 | $SED" | | |
78 | awk '{ | |
79 | if ($1 != prev) { | |
80 | if (rec != "") | |
81 | print rec; | |
82 | rec = $0; | |
83 | prev = $1; | |
84 | } | |
85 | else { | |
86 | if (length(rec $2) > 78) { | |
87 | print rec; | |
88 | rec = $0; | |
89 | } | |
90 | else | |
91 | rec = rec " " $2 | |
92 | } | |
93 | } | |
94 | END { | |
95 | print rec | |
96 | }' >> $TMP | |
f48536ef KB |
97 | |
98 | cat << _EOF_ >> $TMP | |
99 | ||
100 | # IF YOU PUT ANYTHING HERE IT WILL GO AWAY | |
101 | _EOF_ | |
102 | ||
8c3305b6 KB |
103 | # copy to preserve permissions |
104 | cp $TMP $MAKE | |
105 | rm -f ${MAKE}.bak $TMP | |
f48536ef | 106 | exit 0 |