xenocara/util/gccmakedep/gccmakedep.in

131 lines
2.1 KiB
Plaintext
Raw Normal View History

2015-01-03 08:32:08 -07:00
#!/bin/sh
2006-11-25 09:15:45 -07:00
2015-01-03 08:32:08 -07:00
#
# makedepend which uses 'gcc -M'
#
# $XFree86: xc/config/util/gccmdep.cpp,v 3.10tsi Exp $
#
# Based on mdepend.cpp and code supplied by Hongjiu Lu <hjl@nynexst.com>
#
2006-11-25 09:15:45 -07:00
TMP=mdep$$.tmp
2015-01-03 08:32:08 -07:00
CC="@CC@"
RM="rm -f"
LN="ln"
MV="mv"
2006-11-25 09:15:45 -07:00
${RM} ${TMP}
trap "${RM} ${TMP}*; exit 1" 1 2 15
trap "${RM} ${TMP}*; exit 0" 1 2 13
files=
makefile=
endmarker=
magic_string='# DO NOT DELETE'
append=n
args=
while [ $# != 0 ]; do
if [ "$endmarker"x != x -a "$endmarker" = "$1" ]; then
endmarker=
else
case "$1" in
-D*|-I*|-U*)
2015-01-03 08:32:08 -07:00
# arg may contain single quotes
qarg=`echo "$1" | sed "s/'/'\\\\\\\\''/g"`
args="$args '$qarg'"
2006-11-25 09:15:45 -07:00
;;
-g*|-O*)
;;
*)
if [ "$endmarker"x = x ]; then
case $1 in
2015-01-03 08:32:08 -07:00
# ignore these flags
2006-11-25 09:15:45 -07:00
-w|-o|-cc)
shift
;;
-v)
;;
-s)
magic_string="$2"
shift
;;
-f*)
if [ "$1" = "-f-" ]; then
makefile="-"
elif [ "$1" = "-f" ]; then
makefile="$2"
shift
else
echo "$1" | sed 's/^\-f//' >${TMP}arg
makefile="`cat ${TMP}arg`"
rm -f ${TMP}arg
fi
;;
--*)
endmarker=`echo $1 | sed 's/^\-\-//'`
if [ "$endmarker"x = x ]; then
endmarker="--"
fi
;;
-a)
append=y
;;
-*)
echo "Unknown option '$1' ignored" 1>&2
;;
*)
2015-01-03 08:32:08 -07:00
# filename may contain blanks
files="$files '$1'"
2006-11-25 09:15:45 -07:00
;;
esac
fi
;;
esac
fi
shift
done
if [ x"$files" = x ]; then
2015-01-03 08:32:08 -07:00
# Nothing to do
2006-11-25 09:15:45 -07:00
exit 0
fi
case "$makefile" in
'')
if [ -r makefile ]; then
makefile=makefile
elif [ -r Makefile ]; then
makefile=Makefile
else
echo 'no makefile or Makefile found' 1>&2
exit 1
fi
;;
esac
if [ X"$makefile" != X- ]; then
if [ x"$append" = xn ]; then
sed -e "/^$magic_string/,\$d" < $makefile > $TMP
echo "$magic_string" >> $TMP
else
cp $makefile $TMP
fi
fi
CMD="$CC -M $args $files"
if [ X"$makefile" != X- ]; then
CMD="$CMD >> $TMP"
fi
2015-01-03 08:32:08 -07:00
# Do not wildcard expand '*' in args
eval "$CMD"
2006-11-25 09:15:45 -07:00
if [ X"$makefile" != X- ]; then
$RM ${makefile}.bak
$MV $makefile ${makefile}.bak
$MV $TMP $makefile
fi
$RM ${TMP}*
exit 0