3 # @(#)mdepend.sh 1.3 5/11/88 19:44:36
5 # Do the equivalent of the 'makedepend' program, but do it right.
9 # makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
14 # The C compiler used can be overridden with the environment
17 # The "-v" switch of the "makedepend" program is not supported.
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).
29 TMP=${TMPDIR:-/tmp}/mdep$$
35 trap "rm -f ${TMP}*; exit 1" 1 2 15
36 trap "rm -f ${TMP}*; exit 0" 1 2 13
39 if [ `wc -c < $CPPCMD` -eq 1 ]
48 echo $n "exec $CC -E$c" > $CPPCMD
53 magic_string='# DO NOT DELETE'
60 echo $n " '$1'$c" >> $CPPCMD
79 echo "Unknown option '$1' ignored" 1>&2
98 echo 'no makefile or Makefile found' 1>&2
103 makefile=$TMPMAKEFILE
107 echo '' > $DEPENDLINES
111 | sed -n "/^#/s;^;$i ;p"
113 | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' \
114 -e 's|"||g' -e 's| \./| |' \
116 if ($1 != $4 && $2 != "#ident")
118 ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'"
133 else if (length (newrec) > '"$width"')
148 trap "" 1 2 13 15 # Now we are committed
154 cp Makefile Makefile.bak
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.
163 cat >> $makefile <<- END_OF_APPEND
167 ed $silent $makefile <<- END_OF_ED_SCRIPT
168 /^$magic_string/w $MAGICLINE