summaryrefslogtreecommitdiff
path: root/build.sh
blob: 7c140b72516dfc20a981c5259fa7ca637668ea7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh

cd ${0%/*} # go to project root

NAME="main"

DEBUG_FLAGS="-std=c99 -Wall -Wextra -g -pedantic -DDEBUG"
PROD_FLAGS="-std=c99 -O2"
SDL_FLAGS="`sdl2-config --cflags --libs`"
LIB_FLAGS="-lm"

FLAGS="$DEBUG_FLAGS $SDL_FLAGS $LIB_FLAGS"

SRC="src"
OBJ="obj"
BIN="bin"
FILES="files"
RUN=0
WEB=0

function __web__ {
    WEB=1
}

function __run__ {
    RUN=1
}

function __leak__ {
    VALGRND="valgrind --leak-check=full --show-leak-kinds=all -s"
    RUN=1
}

function __prod__ {
    FLAGS="$PROD_FLAGS $SDL_FLAGS $LIB_FLAGS"
}

function __clean__ {
    rm -rf $BIN
    rm -rf $OBJ
    exit 0
}

set -xe

mkdir -p $BIN
mkdir -p $OBJ
mkdir -p $FILES

if ! { [[ $# -eq 0 ]]; } 2> /dev/null
then
    __$1__
fi

if { [[ $WEB -eq 0 ]]; } 2> /dev/null; then
    gcc -o $OBJ/main.o -c $SRC/main.c     $FLAGS
    gcc -o $OBJ/player.o -c $SRC/player.c $FLAGS
    gcc -o $OBJ/sector.o -c $SRC/sector.c $FLAGS

    gcc -o $BIN/$NAME     $OBJ/*.o        $FLAGS

    if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null; then
        $VALGRND $BIN/$NAME
    fi
else
    mkdir -p $BIN/web

    emcc -o $BIN/web/portal-engine.html $SRC/*.c \
         $PROD_FLAGS $LIB_FLAGS \
         -s USE_SDL=2 -s ASYNCIFY \
         --shell-file $SRC/shell.html \
         --preload-file $FILES/map_clear.txt
fi