Subversion Repositories Games.Carmageddon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 pmbaty 1
#!/bin/sh
2
 
3
MY_PATH="$(dirname "$0")"
4
 
5
APP_NAME="Carmageddon"
6
ICON_FILE="icon.png"
7
 
8
cd "${MY_PATH}" || exit 1
9
 
10
# cleanup
11
rm -rf .build
12
rm -rf "${APP_NAME}.$(uname)-$(uname -m)"
13
 
14
# compiler and linker flags to use
15
CPPFLAGS="-DDETHRACE_FIX_BUGS=1 -Isrc/harness/include -Isrc/harness -Isrc/smackw32/include -Isrc/BRSRC13/include -Isrc/BRSRC13 -Isrc/S3/include -Isrc/S3 -Isrc/DETHRACE/common -Isrc/DETHRACE/pd -Isrc/DETHRACE -Ilib/glad/include -Ilib/libsmacker -Ilib/miniaudio/include -Ilib/miniaudio/include/miniaudio -Ilib/SDL2 -Ilib"
16
 
17
# read the source files list from the Visual Studio project file if it exists, else list all the .c files from "lib" and "src"
18
if [ -f "${APP_NAME}.vcxproj" ]; then
19
        SRCLIST="$(grep "<ClCompile " ${APP_NAME}.vcxproj|awk -F\" '{print $2}'|tr '\\' '/')"
20
else
21
        SRCLIST="$(find lib -name '*.c') $(find src -name '*.c')"
22
fi
23
 
24
# generate the shader programs
25
echo "Compacting GLSL shaders..."
26
cd src/harness || exit 1
27
for SHADER in resources/*.glsl; do
28
        echo "${SHADER}"
29
        SYMBOL_NAME="$(echo "${SHADER}"|tr '[:lower:]' '[:upper:]'|sed 's/[\.\/]/_/g')"
30
        (
31
                echo "// Auto generated file."
32
                echo "static const char ${SYMBOL_NAME}[] ="
33
                echo "{"
34
                cat "${SHADER}"|hexdump -e '16/1 "%02x" "\n"' -v|sed 's/[0-9a-fA-F][0-9a-fA-F]/0x&, /g' || exit 1
35
                echo "};"
36
        ) > "${SHADER}.h"
37
done
38
cd ../..
39
 
40
# target the current arch only
41
for ARCH in $(uname -m); do
42
        echo "Compiling for ${ARCH}..."
43
        rm -rf ".build/${ARCH}"
44
        mkdir -p ".build/${ARCH}" || exit 1
45
 
46
        # compile source files
47
        for SRCFILE in ${SRCLIST}; do
48
                echo "${SRCFILE}"
49
                cc -o ".build/${ARCH}/$(basename "${SRCFILE}").o" ${CPPFLAGS} -c "${SRCFILE}" || exit 1
50
        done
51
 
52
        # link them together
53
        echo "Linking for ${ARCH}..."
54
        cc -o ".build/${ARCH}/${APP_NAME}" ".build/${ARCH}/"*".o" /usr/local/lib/libSDL2.a /usr/local/lib/libinotify.a -lusbhid -lpthread -lm -lexecinfo || exit 1
55
done
56
 
57
# retrieve the compiled executable
58
cp ".build/${ARCH}/${APP_NAME}" "${APP_NAME}.$(uname)-$(uname -m)"
59
 
60
# finished
61
echo "Carmageddon was built successfully"
62
exit 0