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