3 XCOMM Do the equivalent of the 'makedepend' program, but do it right.
7 XCOMM makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
8 XCOMM [-o object-suffix] [-v] [-a] [-cc compiler] [-d dependencyflag]
12 XCOMM The C compiler used can be overridden with the environment
13 XCOMM variable "CC" or the command line flag -cc.
15 XCOMM The "-v" switch of the "makedepend" program is not supported.
18 XCOMM This script should
19 XCOMM work on both USG and BSD systems. However, when System V.4 comes out,
20 XCOMM USG users will probably have to change "silent" to "-s" instead of
21 XCOMM "-" (at least, that is what the documentation implies).
31 if ! mkdir -p ${TMP}; then
32 echo "$0: cannot create ${TMP}, exit." >&2
41 trap "rm -rf ${TMP}; exit 1" 1 2 15
42 trap "rm -rf ${TMP}; exit 0" 1 2 13
45 if [ `wc -c < $CPPCMD` -eq 1 ]
58 magic_string='# DO NOT DELETE'
64 compilerlistsdepends=n
68 if [ "$endmarker"x != x ] && [ "$endmarker" = "$1" ]; then
73 echo $n " '$1'$c" >> $ARGS
76 -g|-O) # ignore so we can just pass $(CFLAGS) in
80 if [ "$endmarker"x = x ]; then
91 if [ "$1" = "-f-" ]; then
93 elif [ "$1" = "-f" ]; then
97 echo "$1" | sed 's/^\-f//' >${TMP}arg
98 makefile="`cat ${TMP}arg`"
108 echo "$1" | sed 's/^\-\-//' >${TMP}end
109 endmarker="`cat ${TMP}end`"
111 if [ "$endmarker"x = x ]; then
128 # Flag to tell compiler to output dependencies directly
129 # For example, with Sun compilers, -xM or -xM1 or
132 compilerlistsdepends="y"
133 compilerlistdependsflag="$2"
138 echo "Unknown option '$1' ignored" 1>&2
152 if [ "$compilerlistsdepends"x = "y"x ] ; then
153 CC="$CC $compilerlistdependsflag"
156 echo "#!/bin/sh" > $CPPCMD
157 echo "exec $CC `cat $ARGS`" >> $CPPCMD
170 echo 'no makefile or Makefile found' 1>&2
175 makefile=$TMPMAKEFILE
179 if [ "$verbose"x = "y"x ]; then
183 echo '' > $DEPENDLINES
185 if [ "$compilerlistsdepends"x = "y"x ] ; then
188 $CPPCMD $i >> $DEPENDLINES
194 | sed -n "/^#/s;^;$i ;p"
196 | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' \
197 -e 's|"||g' -e 's| \./| |' \
199 if ($1 != $4 && $2 != "#ident" && $2 != "#pragma")
201 numparts = split( $1, ofileparts, "\." )
203 for ( i = 1; i < numparts; i = i+1 )
207 ofile = ofile ofileparts[i]
209 print ofile "'"$objsuffix"'", $4
223 else if (length (newrec) > '"$width"')
236 | egrep -v '^[^:]*:[ ]*$' >> $DEPENDLINES
239 trap "" 1 2 13 15 # Now we are committed
245 cp $makefile $makefile.bak
246 echo "Appending dependencies to $makefile"
251 XCOMM If not -a, append the magic string and a blank line so that
252 XCOMM /^$magic_string/+1,\$d can be used to delete everything from after
253 XCOMM the magic string to the end of the file. Then, append a blank
254 XCOMM line again and then the dependencies.
256 if [ "$append" = "n" ]
258 cat >> $makefile << END_OF_APPEND
263 ed $silent $makefile << END_OF_ED_SCRIPT
264 /^$magic_string/+1,\$d
271 cat $DEPENDLINES >>$makefile