aboutsummaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..370c378
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+cd ${0%/*} # go to project root
+
+NAME="web-server"
+FLAGS="-std=c99 -Wall -Wextra -g -pedantic -D_POSIX_C_SOURCE=200112L"
+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
+ 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/server.c -o $ODIR/server.o $FLAGS
+gcc -c $SRCD/main.c -o $ODIR/main.o $FLAGS -DFILES=\"$FILES\"
+
+gcc -o $BIN/$NAME $ODIR/main.o $ODIR/server.o $FLAGS
+
+if ! { [[ $RUN -eq 0 ]]; } 2> /dev/null
+then
+ $VALGRND $BIN/$NAME
+fi