build-scripts/makedep.sh
author Sam Lantinga <slouken@libsdl.org>
Mon, 20 Feb 2006 11:29:36 +0000
changeset 1388 9a9b87172b4b
parent 1361 19418e4422cb
child 1391 7dc446173e37
permissions -rwxr-xr-x
Fixed build dependencies... ugh
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
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
          # We already ahve this cached
1388
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    25
          if test x$2 = x; then
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    26
              cat $cache
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    27
          else
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    28
              cat $cache >>$2
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    29
          fi
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
          continue;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
       fi
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
       for path in $base `echo $INCLUDE | sed 's|-I||g'`
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
       do dep="$path/$file"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
          if test -f "$dep"; then
1388
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    35
             echo "	$dep \\" >>$cache
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    36
             if test x$2 = x; then
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    37
                  echo "	$dep \\"
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    38
             else
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    39
                  echo "	$dep \\" >>$2
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    40
             fi
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    41
             search_deps $dep $cache
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
             break
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
          fi
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
       done
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
    done
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
}
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
:>${output}.new
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
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
    50
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
    51
    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
    52
    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|$objects/\1.lo|g"`
1388
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    53
    echo "$obj: $src \\" >>${output}.new
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    54
    search_deps $src | sort | uniq >>${output}.new
9a9b87172b4b Fixed build dependencies... ugh
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
    55
    echo "" >>${output}.new
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    case $ext in
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
        asm) echo "	\$(BUILDASM)" >>${output}.new;;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
        cc)  echo "	\$(BUILDCC)" >>${output}.new;;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
        c)   echo "	\$(BUILDC)" >>${output}.new;;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
        m)   echo "	\$(BUILDM)" >>${output}.new;;
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
        *)   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
    62
    esac
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    echo "" >>${output}.new
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
done
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
rm -f ${cache_prefix}*
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
mv ${output}.new ${output}