aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: 2295b553b070151d5bee13dc3b6985bb7b5e4b4f (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
#!/bin/sh

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

FLAGS="-std=c99 -Wall -Wextra -g -pedantic"
SRCD="src"
ODIR="obj"
BIN="bin"
FILES="files"
RUN=0

function __run__ {
    RUN=1
}

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

function __clean__ {
    rm -rf $BIN
    rm -rf $ODIR
    rm -rf $FILES
    exit 0
}

function __setup__ {
    ./download-tilesets.sh $FILES
    exit 0
}

function __topng__ {
    ./ppmtopng.sh $FILES
    exit 0
}

set -xe

mkdir -p $BIN
mkdir -p $ODIR
mkdir -p $FILES

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

gcc -c $SRCD/gen_tiles.c -o $ODIR/gen_tiles.o $FLAGS -DPATH=$FILES
gcc -c $SRCD/ppm.c       -o $ODIR/ppm.o       $FLAGS
gcc -c $SRCD/tilemap.c   -o $ODIR/tilemap.o   $FLAGS
gcc -c $SRCD/tiles.c     -o $ODIR/tiles.o     $FLAGS -DPATH=\"$FILES\"
gcc -c $SRCD/wfc.c       -o $ODIR/wfc.o       $FLAGS -DPATH=\"$FILES\"
gcc -c $SRCD/main.c      -o $ODIR/main.o      $FLAGS

gcc -o $BIN/wfc $ODIR/main.o $ODIR/wfc.o $ODIR/tiles.o $ODIR/tilemap.o $ODIR/ppm.o $FLAGS
gcc -o $BIN/gen_tiles $ODIR/gen_tiles.o $FLAGS

if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null
then
    $VALGRND $BIN/gen_tiles
    $VALGRND $BIN/wfc
fi