-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·61 lines (47 loc) · 1.07 KB
/
build.sh
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
#!/bin/sh
echo "Building..."
DIR="$(dirname "$(realpath "$0")")"
exit_on_error () {
echo "An error occured! $1"
exit 1
}
BIN="bin"
RUNNABLE="predictors"
CLEAN=0
RUN=0
# idiomatic parameter and option handling in sh
while test $# -gt 0
do
case "$1" in
"clean") CLEAN=1
;;
"run") RUN=1
;;
esac
shift
done
# Go to script location
cd $DIR || exit_on_error "Failed to enter script location";
# Clean
if [ $CLEAN = 1 ]; then
rm -rf "$BIN" && echo "$BIN folder removed."
fi
# Create bin folder
if [ ! -d "$BIN" ]; then
mkdir -p "$BIN" && echo "$BIN folder created." || exit_on_error "Failed to create $BIN folder!"
fi
cd "$BIN" || exit_on_error "Failed to enter $BIN folder!"
# Stop if error in cmake or make
set -e
if [ ! -f "Makefile" ]; then
cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ ..
fi
make
# Dont stop anymore
set +e
if [ $RUN = 1 ]; then
[ ! -f "$RUNNABLE" ] && exit_on_error "Runnable '$RUNNABLE' not found!"
echo "Executing '$RUNNABLE'..."
#.$RUNABLE
exec "$DIR/$BIN/$RUNNABLE"
fi