3 XCOMM $TOG: mdepend.cpp /main/13 1997/06/20 21:12:18 kaleb $
5 XCOMM Do the equivalent of the 'makedepend' program, but do it right.
9 XCOMM makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
10 XCOMM [-o object-suffix]
14 XCOMM The C compiler used can be overridden with the environment
17 XCOMM The "-v" switch of the "makedepend" program is not supported.
20 XCOMM This script should
21 XCOMM work on both USG and BSD systems. However, when System V.4 comes out,
22 XCOMM USG users will probably have to change "silent" to "-s" instead of
23 XCOMM "-" (at least, that is what the documentation implies).
36 trap "rm -f ${TMP}*; exit 1" 1 2 15
37 trap "rm -f ${TMP}*; exit 0" 1 2 13
40 if [ `wc -c < $CPPCMD` -eq 1 ]
53 magic_string='# DO NOT DELETE'
62 if [ "$endmarker"x != x ] && [ "$endmarker" = "$1" ]; then
67 echo $n " '$1'$c" >> $ARGS
70 -g|-O) # ignore so we can just pass $(CFLAGS) in
74 if [ "$endmarker"x = x ]; then
85 if [ "$1" = "-f-" ]; then
98 echo "$1" | sed 's/^\-\-//' >${TMP}end
99 endmarker="`cat ${TMP}end`"
101 if [ "$endmarker"x = x ]; then
119 echo "Unknown option '$1' ignored" 1>&2
133 echo "#!/bin/sh" > $CPPCMD
134 echo "exec $CC `cat $ARGS`" >> $CPPCMD
147 echo 'no makefile or Makefile found' 1>&2
152 makefile=$TMPMAKEFILE
156 if [ "$verbose"x = "y"x ]; then
160 echo '' > $DEPENDLINES
164 | sed -n "/^#/s;^;$i ;p"
166 | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' \
167 -e 's|"||g' -e 's| \./| |' \
169 if ($1 != $4 && $2 != "#ident" && $2 != "#pragma")
171 ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
186 else if (length (newrec) > '"$width"')
199 | egrep -v '^[^:]*:[ ]*$' >> $DEPENDLINES
201 trap "" 1 2 13 15 # Now we are committed
207 cp $makefile $makefile.bak
208 echo "Appending dependencies to $makefile"
213 XCOMM If not -a, append the magic string and a blank line so that
214 XCOMM /^$magic_string/+1,\$d can be used to delete everything from after
215 XCOMM the magic string to the end of the file. Then, append a blank
216 XCOMM line again and then the dependencies.
218 if [ "$append" = "n" ]
220 cat >> $makefile << END_OF_APPEND
225 ed $silent $makefile << END_OF_ED_SCRIPT
226 /^$magic_string/+1,\$d
233 cat $DEPENDLINES >>$makefile