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