build-scripts/makedep.sh
author Sam Lantinga <slouken@libsdl.org>
Wed, 22 Feb 2006 04:44:33 +0000
changeset 1416 a4c05c115bb7
parent 1391 7dc446173e37
child 1417 24fbbedd2ad6
permissions -rwxr-xr-x
Fixed script on mingw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
#!/bin/sh
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
#
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
# Generate dependencies from a list of source files
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
# Check to make sure our environment variables are set
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
if test x"$INCLUDE" = x -o x"$SOURCES" = x -o x"$objects" = x -o x"$output" = x; then
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    echo "SOURCES, INCLUDE, objects, and output needs to be set"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    exit 1
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
fi
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
cache_prefix=".#$$"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
generate_var()
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
{
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
    echo $1 | sed -e 's|^.*/||' -e 's|\.|_|g'
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
}
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
search_deps()
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
{
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    base=`echo $1 | sed 's|/[^/]*$||'`
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    grep '#include "' <$1 | sed -e 's|.*"\([^"]*\)".*|\1|' | \
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
    while read file
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
    do cache=${cache_prefix}_`generate_var $file`
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
       if test -f $cache; then
1391
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    24
          : # We already ahve this cached
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    25
       else
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    26
           : >$cache
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    27
           for path in $base `echo $INCLUDE | sed 's|-I||g'`
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    28
           do dep="$path/$file"
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    29
              if test -f "$dep"; then
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    30
                 echo "	$dep \\" >>$cache
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    31
                 search_deps $dep >>$cache
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    32
                 break
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    33
              fi
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    34
           done
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
       fi
1391
7dc446173e37 Blargle-fnargle dependencies and build rules
Sam Lantinga <slouken@libsdl.org>
parents: 1388
diff changeset
    36
       cat $cache
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
    done
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
}
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
:>${output}.new
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
for src in $SOURCES
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
do  echo "Generating dependencies for $src"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
    ext=`echo $src | sed 's|.*\.\(.*\)|\1|'`
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|$objects/\1.lo|g"`
1388
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    45
    echo "$obj: $src \\" >>${output}.new
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    46
    search_deps $src | sort | uniq >>${output}.new
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    case $ext in
1416
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    48
        c) cat >>${output}.new <<__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    49
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    50
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) -c $src  -o \$@
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    51
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    52
__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    53
        ;;
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    54
        cc) cat >>${output}.new <<__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    55
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    56
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) -c $src  -o \$@
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    57
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    58
__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    59
        ;;
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    60
        m) cat >>${output}.new <<__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    61
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    62
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) -c $src  -o \$@
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    63
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    64
__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    65
        ;;
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    66
        asm) cat >>${output}.new <<__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    67
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    68
	\$(LIBTOOL) --tag=CC --mode=compile \$(auxdir)/strip_fPIC.sh \$(NASM) $src -o \$@"
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    69
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    70
__EOF__
a4c05c115bb7 Fixed script on mingw
Sam Lantinga <slouken@libsdl.org>
parents: 1391
diff changeset
    71
        ;;
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
        *)   echo "Unknown file extension: $ext";;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
    esac
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
    echo "" >>${output}.new
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
done
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
mv ${output}.new ${output}