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 | # |
f83849d8 | 18 | # @(#)mkdep.sh 5.18 (Berkeley) %G% |
f48536ef | 19 | # |
c0644842 KB |
20 | PATH=/bin:/usr/bin:/usr/ucb |
21 | export PATH | |
8c3305b6 | 22 | |
82629d33 | 23 | D=.depend # default dependency file is .depend |
4db60ccd | 24 | append=0 |
190489bd KB |
25 | |
26 | while : | |
27 | do case "$1" in | |
4db60ccd KB |
28 | # -a appends to the depend file |
29 | -a) | |
30 | append=1 | |
31 | shift ;; | |
32 | ||
190489bd KB |
33 | # -f allows you to select a makefile name |
34 | -f) | |
82629d33 | 35 | D=$2 |
190489bd KB |
36 | shift; shift ;; |
37 | ||
38 | # the -p flag produces "program: program.c" style dependencies | |
39 | # so .o's don't get produced | |
40 | -p) | |
742d9467 | 41 | SED='s;\.o;;' |
190489bd KB |
42 | shift ;; |
43 | *) | |
44 | break ;; | |
45 | esac | |
46 | done | |
47 | ||
0ee442d6 | 48 | if [ $# = 0 ] ; then |
82629d33 | 49 | echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...' |
0ee442d6 KB |
50 | exit 1 |
51 | fi | |
52 | ||
f48536ef KB |
53 | TMP=/tmp/mkdep$$ |
54 | ||
8c3305b6 | 55 | trap 'rm -f $TMP ; exit 1' 1 2 3 13 15 |
f48536ef | 56 | |
742d9467 KB |
57 | cc -M $* | |
58 | sed " | |
59 | s; \./; ;g | |
2bfaf234 | 60 | /\.c:$/d |
742d9467 KB |
61 | $SED" | |
62 | awk '{ | |
63 | if ($1 != prev) { | |
64 | if (rec != "") | |
65 | print rec; | |
66 | rec = $0; | |
67 | prev = $1; | |
68 | } | |
69 | else { | |
70 | if (length(rec $2) > 78) { | |
71 | print rec; | |
72 | rec = $0; | |
73 | } | |
74 | else | |
75 | rec = rec " " $2 | |
76 | } | |
77 | } | |
78 | END { | |
79 | print rec | |
82629d33 | 80 | }' > $TMP |
f48536ef | 81 | |
f83849d8 KB |
82 | if [ $? != 0 ]; then |
83 | echo 'mkdep: compile failed.' | |
84 | rm -f $TMP | |
85 | exit 1 | |
86 | fi | |
87 | ||
4db60ccd KB |
88 | if [ $append = 1 ]; then |
89 | cat $TMP >> $D | |
90 | rm -f $TMP | |
91 | else | |
92 | mv $TMP $D | |
93 | fi | |
f48536ef | 94 | exit 0 |