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

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

FLAGS="-Wall -Wextra -g -pedantic"
FLAGS_RAYLIB="-lraylib -lm -lpthread -lGL -ldl -lrt -lX11"
SRC="src"
BIN="bin"
OBJ="obj"
NAME="kruskal"

RUN=0
VALGRIND=""

WEB=0
RAYLIB_SRC="/usr/local/src/raylib/src" #for web only

function __run__ {
    RUN=1
}

function __valgrind__ {
    VALGRIND=valgrind
    RUN=1
}

function __clean__ {
    rm -rf $BIN
    rm -rf $OBJ
    kill $( ps -q $$ -o pgid= ) # exit
}

function __web__ {
    WEB=1
}

set -xe

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


mkdir -p $BIN
mkdir -p $OBJ

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

    if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null
    then
        $VALGRIND $BIN/$NAME
    fi
else
    source emsdk_env.sh

    emcc -o $BIN/$NAME.html $SRC/main.c $SRC/set.c \
         $FLAGS -DPLATFORM_WEB -DRAYLIB_SRC="\"$RAYLIB_SRC/raylib.h\"" \
         $RAYLIB_SRC/libraylib.a \
         -I$RAYLIB_SRC/raylib.h \
         -s USE_GLFW=3 -s ASYNCIFY \
         --shell-file $SRC/shell.html

    # delete e line that blocks backspace and tab
    sed -i $(($(grep "keyCode === 8" $BIN/$NAME.js -n | cut -d : -f 1)+1))d $BIN/$NAME.js > /dev/null
fi