1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#!/bin/sh
# This script is part of Bakefile (http://www.bakefile.org) autoconf
# script. It is used to track C/C++ files dependencies in portable way.
#
# Permission is given to use this file in any way.
DEPSMODE=gcc
DEPSFLAG="-MMD"
DEPSDIRBASE=.deps
if test $DEPSMODE = gcc ; then
$* ${DEPSFLAG}
status=$?
# determine location of created files:
while test $# -gt 0; do
case "$1" in
-o )
shift
objfile=$1
;;
-* )
;;
* )
srcfile=$1
;;
esac
shift
done
objfilebase=`basename $objfile`
builddir=`dirname $objfile`
depfile=`basename $srcfile | sed -e 's/\..*$/.d/g'`
depobjname=`echo $depfile |sed -e 's/\.d/.o/g'`
depsdir=$builddir/$DEPSDIRBASE
mkdir -p $depsdir
# if the compiler failed, we're done:
if test ${status} != 0 ; then
rm -f $depfile
exit ${status}
fi
# move created file to the location we want it in:
if test -f $depfile ; then
sed -e "s,$depobjname:,$objfile:,g" $depfile >${depsdir}/${objfilebase}.d
rm -f $depfile
else
# "g++ -MMD -o fooobj.o foosrc.cpp" produces fooobj.d
depfile=`echo "$objfile" | sed -e 's/\..*$/.d/g'`
if test ! -f $depfile ; then
# "cxx -MD -o fooobj.o foosrc.cpp" creates fooobj.o.d (Compaq C++)
depfile="$objfile.d"
fi
if test -f $depfile ; then
sed -e "\,^$objfile,!s,$depobjname:,$objfile:,g" $depfile >${depsdir}/${objfilebase}.d
rm -f $depfile
fi
fi
exit 0
elif test $DEPSMODE = mwcc ; then
$* || exit $?
# Run mwcc again with -MM and redirect into the dep file we want
# NOTE: We can't use shift here because we need $* to be valid
prevarg=
for arg in $* ; do
if test "$prevarg" = "-o"; then
objfile=$arg
else
case "$arg" in
-* )
;;
* )
srcfile=$arg
;;
esac
fi
prevarg="$arg"
done
objfilebase=`basename $objfile`
builddir=`dirname $objfile`
depsdir=$builddir/$DEPSDIRBASE
mkdir -p $depsdir
$* $DEPSFLAG >${depsdir}/${objfilebase}.d
exit 0
elif test $DEPSMODE = unixcc; then
$* || exit $?
# Run compiler again with deps flag and redirect into the dep file.
# It doesn't work if the '-o FILE' option is used, but without it the
# dependency file will contain the wrong name for the object. So it is
# removed from the command line, and the dep file is fixed with sed.
cmd=""
while test $# -gt 0; do
case "$1" in
-o )
shift
objfile=$1
;;
* )
eval arg$#=\$1
cmd="$cmd \$arg$#"
;;
esac
shift
done
objfilebase=`basename $objfile`
builddir=`dirname $objfile`
depsdir=$builddir/$DEPSDIRBASE
mkdir -p $depsdir
eval "$cmd $DEPSFLAG" | sed "s|.*:|$objfile:|" >${DEPSDIR}/${objfilebase}.d
exit 0
else
$*
exit $?
fi
|