123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742 |
- #!/bin/sh
- P=`basename $0`; export P
- CPP="cc -E"
- MARKER="# DO NOT DELETE THIS LINE -- makedepend-sh depends on it"
- CKSUM=cksum
- CKSUM_STORE=.dep_cksum
- DEPEND_STORE=.depends
- init_mode() {
- mode="md_args";
- }
- incr_mode() {
- if [ "$mode" = "md_args" ] ; then
- mode="cc_args";
- else
- if [ "$mode" = "cc_args" ] ; then
- mode="fn_args";
- fi
- fi
- }
- append_arg() {
- case "$mode" in
- md_*) arg_md="$arg_md $1" ;;
- cc_*) arg_cc="$arg_cc $1" ;;
- fn_*) arg_fn="$arg_fn $1" ;;
- esac
- }
- append_srcs() {
- append_to="$1"
- srcs_file="$2"
-
-
-
-
-
- cat $srcs_file | \
- awk 'BEGIN { printf("\n#\n# '$mksrcs' generated by makedepend\n#\n'$mksrcs' = ")} \
- {} { for (i = 1; i <= NF; i++) { printf("\\\n %s ", $i) }} \
- END { printf("\n\n") }' >> $append_to
- }
- append_rules() {
- append_to="$1"
- rules_in="$2"
- ( \
- echo; echo '#'; \
- echo '# generated rules for source files that are not local'; \
- echo '# to this directory.'; \
- echo '#'; \
- cat $rules_in; \
- echo; echo; echo) >> $append_to
- }
- generate_awk() {
- cat > $1 <<!
- BEGIN { FS=":" }
- \$1 ~ /^\.[a-zA-Z]+\.[a-zA-Z]+$/ {
-
-
- if (exists[\$1] == 0) {
- exists[\$1] = 1
- names[\$1] = \$1
- cur_suf = \$1
- suff_list=suff_list " " cur_suf
- collect = 1
- } else {
- collect = 0
- }
- next
- }
- /^[\t
- if (collect) {
-
- action[cur_suf]=action[cur_suf] "\t" substr(\$0,2) "\\\n"
- }
- next
- }
- /.*/ {
-
-
- collect = 0
- }
- END {
-
- for (n in names) {
- printf("mkrule_");
- for (j = 1; j <= length(n); j++) {
- c = substr(n,j,1)
- if (c ~ /[a-zA-Z0-9]/) {
- printf("%s", c)
- } else {
-
- printf("_")
- }
- }
- print "='" action[n] "'"
- }
-
-
-
-
-
-
- len = length(suff_list)
- for (j = 1; j <= len; j++) {
-
-
-
-
- c = substr(suff_list,j,1)
- if (c ~ /[ .]/) {
- if (sfx !~ /^$/) {
- sfxs[sfx] = sfx
- sfx = ""
- }
- } else {
- sfx = sfx c
- }
- }
-
- printf("mksuffixes='")
- first = 1
- for (s in sfxs) {
- if (first == 1) { printf("%s", s); first = 0 } else { printf(" %s", s) }
- }
- printf("'\n")
- }
- !
- }
- eval_mrules()
- {
- mrulefile=$1
- eval `mktemp awkscr`
- eval `mktemp mkrule_scr`
- generate_awk $awkscr
- awk -f $awkscr < $mrulefile > $mkrule_scr
- . $mkrule_scr
- if test "$verbose" -gt 1; then
- (echo "make rules are:"; echo "==============="; \
- cat $mkrule_scr; echo "===============") | sed -e "s/^/$P: /"
- fi
- }
- exists_rule()
- {
-
- s_sfx=$1
- p_sfx=$1
-
- rulename=\$mkrule__${s_sfx}_${prod_sfx}
- test -n "`eval echo $rulename`" && return 0
- return 1
- }
- mktemp()
- {
- export tmp_id
- tmp_id=`expr ${tmp_id:-0} + 1`
- name=/tmp/mkdep.$$.${tmp_id}
- echo "$1=$name; tmp_id=$tmp_id"
- }
- explicit_rule()
- {
- src="$1"
- obj="$2"
- srcdir="$3"
- rulefile="$4"
- excludes="$5"
- test "$srcdir" = '.' && return
- src_suffix=`echo $src | sed -n -e 's/.*\.\([^.][^.]*\)$/\1/p'`
- obj_suffix=`echo $obj | sed -n -e 's/.*\.\([^.][^.]*\)$/\1/p'`
-
- rulename=\$mkrule__${src_suffix}_${obj_suffix}
-
-
-
-
- for x in $excludes; do
- test "$x" = "$obj" && {
- test "$verbose" -gt 1 && \
- echo $P: skipping explicit rule for: $obj; \
- return; \
- }
- done
-
-
-
-
- if test -n "`eval echo $rulename`"; then
- echo ${obj}: ${srcdir}/${src} >> $rulefile
-
-
-
-
-
-
-
- eval printf \"$rulename\" | \
- sed -e "s;\$<;$srcdir/$src;g" >> $rulefile
- fi
- }
- in_list_p()
- {
- f="$1"
- ignores="$2"
- for x in $ignores; do
- test "$x" = "$f" && return 0
- done
- return 1
- }
- #
- # see if we already have a file of dependencies and see if it is
- # usable (i.e. the cksum on the cksumfile is still the same)
- #
- have_usable_depends()
- {
- ckmatchfile="$1"
- if test -n "$ckmatchfile" -a -s "$CKSUM_STORE" -a -f "$DEPEND_STORE"; then
- $CKSUM $ckmatchfile > $CKS 2> /dev/null && \
- diff "$CKSUM_STORE" "$CKS" > /dev/null 2>&1 || \
- return 1 # no usable dependencies prestored
- test "$verbose" -gt 0 && echo $P: using dependencies from previous run
- return 0
- fi
- # return FALSE
- return 1
- }
- #
- # maybe_store_depends:
- # we should squirrel away the dependencies that have been generated
- # if the user has specified a -c flag on the command line (i.e. a
- # file to checksum against). If that is the case then store the
- # dependencies in DEPEND_STORE and calculate a new checksum into
- # CKSUM_STORE.
- #
- maybe_store_depends()
- {
- ckmatchfile="$1"
- depsfile="$2"
- if test -n "$ckmatchfile" ; then
- $CKSUM "$ckmatchfile" > $CKS 2> /dev/null && \
- test -s "$CKS" || return 1
- # only store if different
- diff "$CKS" "$CKSUM_STORE" > /dev/null 2>&1 || cdiff=yes
- diff "$depsfile" "$DEPEND_STORE" > /dev/null 2>&1 || ddiff=yes
- if test "$cdiff" = yes -o "$ddiff" = yes; then
- cp "$CKS" "$CKSUM_STORE" && cp "$depsfile" "$DEPEND_STORE" || \
- return 1
- test "$verbose" -gt 0 && echo $P: stored new dependencies for reuse
- fi
- fi
- # success unless we botched things above and returned a 1
- return 0
- }
- #
- # gen_depends():
- # generate the depend information into the file named in TMP.
- #
- gen_depends()
- {
- #
- # go through the source files. Find each in VPATH
- # do the compile there and accumulate the dependencies
- #
- true > $TMP # truncate TMP
-
- for f in $arg_fn; do
-
- # let us assume that all products are '.o' files
- prod_sfx='o'
-
- # figure out the stem: i.e. /a/b/c/foo.o --> foo
- stem=`echo $f | sed -e 's/.o$//'`
-
- # did we actually find a source file
- found_src=no
-
- # if this file is in the ignore list, skip it
- in_list_p "$f" "$ignobjs" && { test "$verbose" -gt 0 && \
- echo $P: ignoring file: $f; continue; }
-
- #
- # go through each possible directory and try each possible
- # source file
- #
- for d in $VPATH; do
-
- #
- # as soon as we find the first src file, we can go onto the
- # next argument (i.e. object file)
- #
- test "$found_src" = yes && break
-
- for src_sfx in $mksuffixes; do
-
- # cannot make a file from itself
- test "$prod_sfx" = "$src_sfx" && continue
-
- #
- # if we were given rules and there is no rule for this
- # transformation then skip this suffix combination
- #
- test -n "$mrules" && exists_rule $src_sfx $prod_sfx || continue
-
- s=${stem}.${src_sfx}
- test "$verbose" -gt 2 && echo "$P: checking for: $d/$s"
-
- if [ -f "$d/$s" ]; then
-
- found_src=yes
-
- test "$verbose" -gt 0 && echo $P: processing $d/$s
-
- case "$src_sfx" in
- c*|C*)
- #
- # This is a file that is a candidate for cpp:
- #
- # process the output of cpp and massage it, then sort
- # it uniquely and as a final step remove the trailing
- # numbers or any other cruft that various compilers
- # might generate. Then remove any lines that
- # make the file depend on itself by removing any
- # dependencies on files not ending in .h or .H
- #
- # also add it to the list of srcs
- #
- test -n "$mksrcs" && echo $d/$s >> $SRCS
- test "$verbose" -lt 2 && errout='2> /dev/null'
-
- eval $CPP $arg_cc $d/$s $errout | \
- sed -n -e "s;^\
- grep -v "//$" | \
- grep -v "$s\$" | \
- sed -e 's;\([^ :]*: [^ ]*\).*;\1;' \
- >> $TMP
- ;;
-
- *)
- test "$verbose" -gt 1 && echo "$P: no preprocessing for $s" ;;
- esac
-
-
-
-
- explicit_rule "$s" "$f" "$d" "$RULES" "$xobjs"
-
- break
- fi
- done
- done
- test "$found_src" = no && echo Did not find the source for: $f
- done
-
-
-
-
-
- if test -n "$sedprog"; then
- sort -u < "$TMP" | sed -f "$sedprog" > "$TMP"_a
- mv "$TMP"_a "$TMP" 2>&1 > /dev/null
- else
- sort -u -o "$TMP" "$TMP"
- fi
-
-
-
-
-
-
-
- test -n "$mksrcs" && test -r "$SRCS" && append_srcs "$TMP" "$SRCS"
-
-
-
-
-
- test -n "$mrules" && test -r "$RULES" && append_rules "$TMP" "$RULES"
- }
- init_mode
- eval `mktemp TMP`
- eval `mktemp RULES`
- eval `mktemp SRCS`
- eval `mktemp CKS`
- VP=.; export VP
- mksrcs=""; export mksrcs
- MF=Makefile; export MF
- append=no; export append
- verbose=0; export verbose
- sedprog=""; export sedprog
- mrules=""; export mrules
- xobjs=""; export xobjs
- ignobjs=""; export ignobjs
- cksumfile=""; export cksumfile
- trap '/bin/rm /tmp/mkdep.$$.* > /dev/null 2>&1' 0 1 2 3 15
- while [ $# -gt 0 ] ; do
- if [ "$mode" = "md_args" ]; then
-
-
-
- case "$1" in
- -V*) shift; VP=$1 ;;
- -s*) shift; mksrcs=$1 ;;
- -f*) shift; MF=$1 ;;
- -p*) shift; CPP="$1" ;;
- -e*) shift; sedprog="$1" ;;
- -c*) shift; cksumfile="$1" ;;
- -m*) shift; mrules="$1" ;;
- -x*) shift; xobjs="$1" ;;
- -i*) shift; ignobjs="$1" ;;
- -a*) append=yes ;;
- -v*) verbose=`expr $verbose + 1` ;;
- --) incr_mode ;;
- *) echo $P: Illegal argument \'"$1"\' >&2; exit 1 ;;
- esac
- shift
- else
- case "$1" in
- --) incr_mode ;;
- *) append_arg "$1" ;;
- esac
- shift;
- fi
- done
- if test -n "$xobjs" -a -z "$mrules"; then
- echo $P: cannot use -x without -m >&2
- exit 1
- fi
- if test "$append" = yes -a -n "$mrules"; then
- echo $P: cannot use append mode if -m is specified >$2
- echo $P: since multiple action definitions are prohibited >&2
- exit 1
- fi
- test -n "$mrules" && eval_mrules $mrules
- VPATH="`echo .:$VP | sed -e 's/:/ /g'`"
- test "$verbose" -gt 1 && echo "$P: CFLAGS are: $arg_cc"
- test "$verbose" -gt 1 && echo "$P: VPATH dirs are: $VPATH"
- mksuffixes=${mksuffixes:-'c'}
- have_usable_depends "$cksumfile" && cp "$DEPEND_STORE" "$TMP" || gen_depends
- if [ "$append" = "yes" ]; then
-
- grep "^$MARKER" $MF > /dev/null 2>&1 || echo "$MARKER" >> $MF
- cat $TMP >> $MF
- else
- if grep "^$MARKER" $MF > /dev/null 2>&1 ; then
-
-
-
-
- tmp_mf="/tmp/mf.$$"
- sed "/^$MARKER/d" $MF > $tmp_mf; mv $tmp_mf $MF
- fi
- echo $MARKER >> $MF
- cat $TMP >> $MF
- fi
- maybe_store_depends "$cksumfile" "$TMP" || \
- echo $P: error storing dependencies for later use
- /bin/rm $TMP > /dev/null 2>&1
|