build-scripts/makedep.sh
author Sam Lantinga <slouken@libsdl.org>
Fri, 14 Apr 2006 03:56:31 +0000
changeset 1634 14f302c5b32c
parent 1521 9b9212e4810c
child 2204 9f64d06fa168
permissions -rwxr-xr-x
Don't hardcode the output directory
     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"$output" = x; then
     7     echo "SOURCES, INCLUDE, 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        else
    26            : >$cache
    27            for path in $base `echo $INCLUDE | sed 's|-I||g'`
    28            do dep="$path/$file"
    29               if test -f "$dep"; then
    30                  echo "	$dep \\" >>$cache
    31                  search_deps $dep >>$cache
    32                  break
    33               fi
    34            done
    35        fi
    36        cat $cache
    37     done
    38 }
    39 
    40 :>${output}.new
    41 for src in $SOURCES
    42 do  echo "Generating dependencies for $src"
    43     ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
    44     obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
    45     echo "\$(objects)/$obj: $src \\" >>${output}.new
    46     search_deps $src | sort | uniq >>${output}.new
    47     case $ext in
    48         c) cat >>${output}.new <<__EOF__
    49 
    50 	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
    51 
    52 __EOF__
    53         ;;
    54         cc) cat >>${output}.new <<__EOF__
    55 
    56 	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
    57 
    58 __EOF__
    59         ;;
    60         m) cat >>${output}.new <<__EOF__
    61 
    62 	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
    63 
    64 __EOF__
    65         ;;
    66         asm) cat >>${output}.new <<__EOF__
    67 
    68 	\$(LIBTOOL) --tag=CC --mode=compile \$(auxdir)/strip_fPIC.sh \$(NASM) $src -o \$@
    69 
    70 __EOF__
    71         ;;
    72         S) cat >>${output}.new <<__EOF__
    73 
    74 	\$(LIBTOOL)  --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
    75 
    76 __EOF__
    77         ;;
    78         *)   echo "Unknown file extension: $ext";;
    79     esac
    80     echo "" >>${output}.new
    81 done
    82 mv ${output}.new ${output}
    83 rm -f ${cache_prefix}*