build-scripts/makedep.sh
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 23:38:50 +0300
branchSDL-1.2
changeset 11977 6cf3a08b42dc
parent 6130 987c365cc7bf
permissions -rwxr-xr-x
backport bug #3332 (win32 deadkeys) patch:

https://bugzilla.libsdl.org/show_bug.cgi?id=3332
Eric Wasylishen <ewasylishen@gmail.com>
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@6130
    44
    obj=`echo $src | sed "s|^.*/\([^ ]*\)\..*|\1.lo|g"`
slouken@6130
    45
    echo "\$(objects)/$obj: $src \\" >>${output}.new
slouken@6130
    46
slouken@6130
    47
    # No search to be done with Windows resource files
slouken@6130
    48
    if test x"$ext" != x"rc"; then
slouken@6130
    49
        search_deps $src | sort | uniq >>${output}.new
slouken@4078
    50
    fi
slouken@1361
    51
    case $ext in
slouken@1416
    52
        c) cat >>${output}.new <<__EOF__
slouken@1416
    53
slouken@1521
    54
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    55
slouken@1416
    56
__EOF__
slouken@1416
    57
        ;;
slouken@1416
    58
        cc) cat >>${output}.new <<__EOF__
slouken@1416
    59
slouken@1521
    60
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    61
slouken@1416
    62
__EOF__
slouken@1416
    63
        ;;
slouken@1416
    64
        m) cat >>${output}.new <<__EOF__
slouken@1416
    65
slouken@1521
    66
	\$(LIBTOOL) --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1416
    67
slouken@1416
    68
__EOF__
slouken@1416
    69
        ;;
slouken@1416
    70
        asm) cat >>${output}.new <<__EOF__
slouken@1416
    71
slouken@4539
    72
	\$(LIBTOOL) --tag=CC --mode=compile \$(auxdir)/strip_fPIC.sh \$(NASM) -I\$(srcdir)/src/hermes/ $src -o \$@
slouken@1416
    73
slouken@1416
    74
__EOF__
slouken@1416
    75
        ;;
slouken@1459
    76
        S) cat >>${output}.new <<__EOF__
slouken@1459
    77
slouken@1521
    78
	\$(LIBTOOL)  --mode=compile \$(CC) \$(CFLAGS) \$(EXTRA_CFLAGS) -c $src  -o \$@
slouken@1459
    79
slouken@1459
    80
__EOF__
slouken@1459
    81
        ;;
slouken@4078
    82
        rc) cat >>${output}.new <<__EOF__
slouken@4078
    83
slouken@6130
    84
	\$(LIBTOOL)  --tag=RC --mode=compile \$(WINDRES) $src -o \$@
slouken@4078
    85
slouken@4078
    86
__EOF__
slouken@4078
    87
        ;;
slouken@1361
    88
        *)   echo "Unknown file extension: $ext";;
slouken@1361
    89
    esac
slouken@1361
    90
    echo "" >>${output}.new
slouken@1361
    91
done
slouken@1361
    92
mv ${output}.new ${output}
slouken@1493
    93
rm -f ${cache_prefix}*