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
slouken@1361
     1
#!/bin/sh
slouken@1361
     2
#
slouken@1361
     3
# Generate dependencies from a list of source files
slouken@1361
     4
slouken@1361
     5
# Check to make sure our environment variables are set
slouken@1634
     6
if test x"$INCLUDE" = x -o x"$SOURCES" = x -o x"$output" = x; then
slouken@1634
     7
    echo "SOURCES, INCLUDE, and output needs to be set"
slouken@1361
     8
    exit 1
slouken@1361
     9
fi
slouken@1361
    10
cache_prefix=".#$$"
slouken@1361
    11
slouken@1361
    12
generate_var()
slouken@1361
    13
{
slouken@1361
    14
    echo $1 | sed -e 's|^.*/||' -e 's|\.|_|g'
slouken@1361
    15
}
slouken@1361
    16
slouken@1361
    17
search_deps()
slouken@1361
    18
{
slouken@1361
    19
    base=`echo $1 | sed 's|/[^/]*$||'`
slouken@1361
    20
    grep '#include "' <$1 | sed -e 's|.*"\([^"]*\)".*|\1|' | \
slouken@1361
    21
    while read file
slouken@1361
    22
    do cache=${cache_prefix}_`generate_var $file`
slouken@1361
    23
       if test -f $cache; then
slouken@1391
    24
          : # We already ahve this cached
slouken@1391
    25
       else
slouken@1391
    26
           : >$cache
slouken@1391
    27
           for path in $base `echo $INCLUDE | sed 's|-I||g'`
slouken@1391
    28
           do dep="$path/$file"
slouken@1391
    29
              if test -f "$dep"; then
slouken@1391
    30
                 echo "	$dep \\" >>$cache
slouken@1391
    31
                 search_deps $dep >>$cache
slouken@1391
    32
                 break
slouken@1391
    33
              fi
slouken@1391
    34
           done
slouken@1361
    35
       fi
slouken@1391
    36
       cat $cache
slouken@1361
    37
    done
slouken@1361
    38
}
slouken@1361
    39
slouken@1361
    40
:>${output}.new
slouken@1361
    41
for src in $SOURCES
slouken@1361
    42
do  echo "Generating dependencies for $src"
slouken@1361
    43
    ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
slouken@1634
    44
    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
slouken@1634
    45
    echo "\$(objects)/$obj: $src \\" >>${output}.new
slouken@1388
    46
    search_deps $src | sort | uniq >>${output}.new
slouken@1361
    47
    case $ext in
slouken@1416
    48
        c) cat >>${output}.new <<__EOF__
slouken@1416
    49
slouken@1521
    50
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    51
slouken@1416
    52
__EOF__
slouken@1416
    53
        ;;
slouken@1416
    54
        cc) cat >>${output}.new <<__EOF__
slouken@1416
    55
slouken@1521
    56
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    57
slouken@1416
    58
__EOF__
slouken@1416
    59
        ;;
slouken@1416
    60
        m) cat >>${output}.new <<__EOF__
slouken@1416
    61
slouken@1521
    62
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    63
slouken@1416
    64
__EOF__
slouken@1416
    65
        ;;
slouken@1416
    66
        asm) cat >>${output}.new <<__EOF__
slouken@1416
    67
slouken@1417
    68
	\$(LIBTOOL) --tag=CC --mode=compile \$(auxdir)/strip_fPIC.sh \$(NASM) $src -o \$@
slouken@1416
    69
slouken@1416
    70
__EOF__
slouken@1416
    71
        ;;
slouken@1459
    72
        S) cat >>${output}.new <<__EOF__
slouken@1459
    73
slouken@1521
    74
	\$(LIBTOOL)  --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1459
    75
slouken@1459
    76
__EOF__
slouken@1459
    77
        ;;
slouken@1361
    78
        *)   echo "Unknown file extension: $ext";;
slouken@1361
    79
    esac
slouken@1361
    80
    echo "" >>${output}.new
slouken@1361
    81
done
slouken@1361
    82
mv ${output}.new ${output}
slouken@1493
    83
rm -f ${cache_prefix}*