SDL-mirror/build-scripts/makedep.sh
Sam Lantinga 5b3fcf92ea Fixed build dependencies... ugh
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401392
2006-02-20 11:29:36 +00:00

66 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
#
# Generate dependencies from a list of source files
# Check to make sure our environment variables are set
if test x"$INCLUDE" = x -o x"$SOURCES" = x -o x"$objects" = x -o x"$output" = x; then
echo "SOURCES, INCLUDE, objects, and output needs to be set"
exit 1
fi
cache_prefix=".#$$"
generate_var()
{
echo $1 | sed -e 's|^.*/||' -e 's|\.|_|g'
}
search_deps()
{
base=`echo $1 | sed 's|/[^/]*$||'`
grep '#include "' <$1 | sed -e 's|.*"\([^"]*\)".*|\1|' | \
while read file
do cache=${cache_prefix}_`generate_var $file`
if test -f $cache; then
# We already ahve this cached
if test x$2 = x; then
cat $cache
else
cat $cache >>$2
fi
continue;
fi
for path in $base `echo $INCLUDE | sed 's|-I||g'`
do dep="$path/$file"
if test -f "$dep"; then
echo " $dep \\" >>$cache
if test x$2 = x; then
echo " $dep \\"
else
echo " $dep \\" >>$2
fi
search_deps $dep $cache
break
fi
done
done
}
:>${output}.new
for src in $SOURCES
do echo "Generating dependencies for $src"
ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|$objects/\1.lo|g"`
echo "$obj: $src \\" >>${output}.new
search_deps $src | sort | uniq >>${output}.new
echo "" >>${output}.new
case $ext in
asm) echo " \$(BUILDASM)" >>${output}.new;;
cc) echo " \$(BUILDCC)" >>${output}.new;;
c) echo " \$(BUILDC)" >>${output}.new;;
m) echo " \$(BUILDM)" >>${output}.new;;
*) echo "Unknown file extension: $ext";;
esac
echo "" >>${output}.new
done
rm -f ${cache_prefix}*
mv ${output}.new ${output}