comparison build-scripts/makedep.sh @ 1361:19418e4422cb

New configure-based build system. Still work in progress, but much improved
author Sam Lantinga <slouken@libsdl.org>
date Thu, 16 Feb 2006 10:11:48 +0000
parents
children 9a9b87172b4b
comparison
equal deleted inserted replaced
1360:70a9cfb4cf1b 1361:19418e4422cb
1 #!/bin/sh
2 #
3 # Generate dependencies from a list of source files
4
5 # Check to make sure our environment variables are set
6 if test x"$INCLUDE" = x -o x"$SOURCES" = x -o x"$objects" = x -o x"$output" = x; then
7 echo "SOURCES, INCLUDE, objects, and output needs to be set"
8 exit 1
9 fi
10 cache_prefix=".#$$"
11
12 generate_var()
13 {
14 echo $1 | sed -e 's|^.*/||' -e 's|\.|_|g'
15 }
16
17 search_deps()
18 {
19 base=`echo $1 | sed 's|/[^/]*$||'`
20 grep '#include "' <$1 | sed -e 's|.*"\([^"]*\)".*|\1|' | \
21 while read file
22 do cache=${cache_prefix}_`generate_var $file`
23 if test -f $cache; then
24 # We already ahve this cached
25 cat $cache
26 continue;
27 fi
28 for path in $base `echo $INCLUDE | sed 's|-I||g'`
29 do dep="$path/$file"
30 if test -f "$dep"; then
31 echo " $dep \\" >$cache
32 echo " $dep \\"
33 generate_dep $dep
34 break
35 fi
36 done
37 done
38 }
39
40 generate_dep()
41 {
42 cat >>${output}.new <<__EOF__
43 $1: \\
44 `search_deps $1`
45
46 __EOF__
47 }
48
49 :>${output}.new
50 for src in $SOURCES
51 do echo "Generating dependencies for $src"
52 generate_dep $src
53 ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
54 obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|$objects/\1.lo|g"`
55 echo "$obj: $src" >>${output}.new
56 case $ext in
57 asm) echo " \$(BUILDASM)" >>${output}.new;;
58 cc) echo " \$(BUILDCC)" >>${output}.new;;
59 c) echo " \$(BUILDC)" >>${output}.new;;
60 m) echo " \$(BUILDM)" >>${output}.new;;
61 *) echo "Unknown file extension: $ext";;
62 esac
63 echo "" >>${output}.new
64 done
65 rm -f ${cache_prefix}*
66 mv ${output}.new ${output}