]> andersk Git - moira.git/blame - util/makedepend/mdepend.sh
RSAREF (for new reg_svr)
[moira.git] / util / makedepend / mdepend.sh
CommitLineData
d1b2a10e 1#!/bin/sh
2#
3# @(#)mdepend.sh 1.3 5/11/88 19:44:36
4#
5# Do the equivalent of the 'makedepend' program, but do it right.
6#
7# Usage:
8#
9# makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
10# [-o object-suffix]
11#
12# Notes:
13#
14# The C compiler used can be overridden with the environment
15# variable "CC".
16#
17# The "-v" switch of the "makedepend" program is not supported.
18#
19#
20# This script should
21# work on both USG and BSD systems. However, when System V.4 comes out,
22# USG users will probably have to change "silent" to "-s" instead of
23# "-" (at least, that's what the documentation implies).
24#
25CC=${CC:-cc}
26
27silent='-'
28
29TMP=${TMPDIR:-/tmp}/mdep$$
30CPPCMD=${TMP}a
31DEPENDLINES=${TMP}b
32TMPMAKEFILE=${TMP}c
33MAGICLINE=${TMP}d
34
35trap "rm -f ${TMP}*; exit 1" 1 2 15
36trap "rm -f ${TMP}*; exit 0" 1 2 13
37
38echo " \c" > $CPPCMD
39if [ `wc -c < $CPPCMD` -eq 1 ]
40then
41 c="\c"
42 n=
43else
44 c=
45 n="-n"
46fi
47
48echo $n "exec $CC -E$c" > $CPPCMD
49chmod +x $CPPCMD
50
51files=
52makefile=
53magic_string='# DO NOT DELETE'
54objsuffix='.o'
55width=78
56while [ $# != 0 ]
57do
58 case "$1" in
59 -D*|-I*)
60 echo $n " '$1'$c" >> $CPPCMD
61 ;;
62 -w)
63 width="$2"
64 shift
65 ;;
66 -s)
67 magic_string="$2"
68 shift
69 ;;
70 -f)
71 makefile="$2"
72 shift
73 ;;
74 -o)
75 objsuffix="$2"
76 shift
77 ;;
78 -*)
79 echo "Unknown option '$1' ignored" 1>&2
80 ;;
81 *)
82 files="$files $1"
83 ;;
84 esac
85 shift
86done
87echo ' $*' >> $CPPCMD
88
89case "$makefile" in
90 '')
91 if [ -r makefile ]
92 then
93 makefile=makefile
94 elif [ -r Makefile ]
95 then
96 makefile=Makefile
97 else
98 echo 'no makefile or Makefile found' 1>&2
99 exit 1
100 fi
101 ;;
102 -)
103 makefile=$TMPMAKEFILE
104 ;;
105esac
106
107echo '' > $DEPENDLINES
108for i in $files
109do
110 $CPPCMD $i \
111 | sed -n "/^#/s;^;$i ;p"
112done \
113 | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' \
114 -e 's|"||g' -e 's| \./| |' \
115 | awk '{
116 if ($1 != $4 && $2 != "#ident")
117 {
118 ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
119 print ofile, $4
120 }
121 }' \
122 | sort -u \
123 | awk '
124 {
125 newrec = rec " " $2
126 if ($1 != old1)
127 {
128 old1 = $1
129 if (rec != "")
130 print rec
131 rec = $1 ": " $2
132 }
133 else if (length (newrec) > '"$width"')
134 {
135 print rec
136 rec = $1 ": " $2
137 }
138 else
139 rec = newrec
140 }
141 END \
142 {
143 if (rec != "")
144 print rec
145 }' \
146 >> $DEPENDLINES
147
148trap "" 1 2 13 15 # Now we are committed
149case "$makefile" in
150 $TMPMAKEFILE)
151 ;;
152 *)
153 rm -f Makefile.bak
154 cp Makefile Makefile.bak
155 ;;
156esac
157
158#
159# Before we go edit the Makefile, we must make sure that magic_string
160# exists, and that it's not the last line. Otherwise, dear old ed
161# will exit prematurely. What a pain.
162#
163cat >> $makefile <<- END_OF_APPEND
164 $magic_string
165
166END_OF_APPEND
167ed $silent $makefile <<- END_OF_ED_SCRIPT
168 /^$magic_string/w $MAGICLINE
169 /^$magic_string/,\$d
170 \$r $MAGICLINE
171 \$r $DEPENDLINES
172 w
173 q
174END_OF_ED_SCRIPT
175
176case "$makefile" in
177 $TMPMAKEFILE)
178 cat $TMPMAKEFILE
179 ;;
180esac
181
182rm -f ${TMP}*
This page took 0.078044 seconds and 5 git commands to generate.