1 #!/bin/sh -
2 #
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
7 # provided that this notice is preserved and that due credit is given
8 # to the University of California at Berkeley. The name of the University
9 # may not be used to endorse or promote products derived from this
10 # software without specific prior written permission. This software
11 # is provided ``as is'' without express or implied warranty.
12 #
13 # @(#)mkdep.sh 5.11 (Berkeley) 5/5/88
14 #
15
16 #PATH=/bin:/usr/bin:/usr/ucb
17 #export PATH
18
19 MAKE=Makefile # default makefile name is "Makefile"
20 CC=g++ # default makefile name is "Makefile"
21
22 while :
23 do case "$1" in
24 # -f allows you to select a makefile name
25 -f)
26 MAKE=$2
27 shift; shift ;;
28
29 # the -p flag produces "program: program.c" style dependencies
30 # so .o's don't get produced
31 -p)
32 SED='s;\.o;;'
33 shift ;;
34 -c)
35 CC=$2
36 shift; shift ;;
37 *)
38 break ;;
39 esac
40 done
41
42 if [ $# = 0 ] ; then
43 echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
44 exit 1
45 fi
46
47 if [ ! -w $MAKE ]; then
48 echo "mkdep: no writeable file \"$MAKE\""
49 exit 1
50 fi
51
52 TMP=/tmp/mkdep$$
53
54 trap 'rm -f $TMP ; exit 1' 1 2 3 13 15
55
56 cp $MAKE ${MAKE}.bak
57
58 sed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
59
60 cat << _EOF_ >> $TMP
61 # DO NOT DELETE THIS LINE -- mkdep uses it.
62 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
63
64 _EOF_
65
66 awk=awk
67 if [ -x /bin/nawk ] ; then
68 awk=/bin/nawk
69 fi
70
71 # If your compiler doesn't have -M, add it. If you can't, the next two
72 # lines will try and replace the "cc -M". The real problem is that this
73 # hack can't deal with anything that requires a search path, and doesn't
74 # even try for anything using bracket (<>) syntax.
75 #
76 #egrep '^#include[ ]*".*"' /dev/null $* |
77 #sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.cc/.o/' |
78 $CC -M $* |
79 sed "
80 s; \./; ;g
81 $SED" |
82 $awk '
83 END {
84 if (rec != "")
85 print rec;
86 }
87 {
88 if ($1 != prev) {
89 if (rec != "")
90 print rec;
91 rec = $0;
92 prev = $1;
93 }
94 else {
95 if (length(rec $2) > 78) {
96 print rec;
97 rec = $0;
98 }
99 else
100 rec = rec " " $2
101 }
102 }' |
103 $awk '{
104 # GNU cpp outputs assumes objects land in current directory
105 # but we put them in subdirectories, so fix up the rules accordingly
106 # i.e., make "foo.o: dir/foo.cc blah" turn into "dir/foo.o: dir/..."
107 if ($1 ~ /.*:/ && $2 ~ "/") {
108 k = 1
109 while (1) {
110 s = substr($2, k);
111 i = index(s,"/");
112 if (i == 0)
113 break;
114 k += i
115 }
116 path = substr($2, 1, k - 1);
117 line = "";
118 for (i = 2; i <= NF; ++i)
119 line = line " " $i;
120
121 print path $1 " " line;
122 } else
123 print $0
124 }' >> $TMP
125
126 cat << _EOF_ >> $TMP
127
128 # IF YOU PUT ANYTHING HERE IT WILL GO AWAY
129 _EOF_
130
131 # copy to preserve permissions
132 cp $TMP $MAKE
133 rm -f ${MAKE}.bak $TMP
134 exit 0
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.