#!/bin/sh # # dependgen -root rootdir -Ioptions src ... # # Script to generate dependencies. This runs makedepend, adding the following: # o Place objects in objs/${ARCH}/${OPT}/ (with make variable refs) # o Removes absolute file dependences and those under $ROOT/tools # o Discards warnings # o Output file is .depend # o adds dependencies for .cc source files # flags='' root='' while [ $# -gt 0 ] ; do case $1 in -root) shift root="$1" shift;; --) shift break;; -*) flags="${flags} $1" shift;; *) break;; esac done srcs="$*" if [ "x$root" = "x" ] ; then echo "Error: must specify -root" >&2 exit 1 fi tmp1dep=depend1.tmp tmp2dep=depend2.tmp tmpout=depend.out.tmp rmtmp="rm -f $tmp1dep $tmp1dep.bak $tmp2dep $tmpout" # make sure there are no stale tmp files $rmtmp # Generate dependencies on .h file. # Use a small width (-w) to ensure there is only one dependency per line. # Don't output stderr unless command fails. touch $tmp1dep makedepend $flags -p'objs/${ARCH}/${OPT}/' -w5 -f$tmp1dep -- $srcs >$tmpout 2>&1 if [ $? != 0 ] ; then cat $tmpout $rmtmp exit 1 fi # Remove absolute file names and those under to $root/tools awk -v "root=$root" ' BEGIN { toolsDir=root "/tools" toolsLen=length(toolsDir) } ((match($2, "^/") == 0) && (substr($2, 1, toolsLen) != toolsDir)) { # not absolute or under tools print $0 }' $tmp1dep >$tmp2dep # Append .o: .cc dependencies. echo $srcs | awk ' BEGIN { # break into records on whitespace to process files separately RS="[ \n\t]+" } /\w+/{ # generate name of .o from .c or .cc # CHANGED 22 June 2005 Kevin Karplus # to require \w+ match and eliminate erroneous empty test obj=$0; sub("[.][^.]+$", ".o", obj); print "objs/${ARCH}/${OPT}/" obj ": " $0 }' >>$tmp2dep mv -f $tmp2dep .depend $rmtmp