summaryrefslogtreecommitdiff
path: root/build_and_test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build_and_test.sh')
-rw-r--r--build_and_test.sh132
1 files changed, 132 insertions, 0 deletions
diff --git a/build_and_test.sh b/build_and_test.sh
new file mode 100644
index 0000000..5a96b0a
--- /dev/null
+++ b/build_and_test.sh
@@ -0,0 +1,132 @@
+if [ ! -d "build" ]; then
+ mkdir build
+fi
+
+OS=Linux
+COMPILE=gcc
+OBJ_POSTFIX=.o
+EXE_POSTFIX=
+FLAGS=
+FLAG_OBJ="-c -o "
+FLAG_EXE="-o "
+LINK_FLAGS=
+
+if [ "$2" = "gcc" ]; then
+ COMPILE=gcc
+elif [ "$2" = "clang" ]; then
+ COMPILE=clang
+elif [ "$2" = "msvc" ]; then
+ COMPILE=cl.exe
+ OBJ_POSTFIX=.obj
+ FLAG_OBJ="-c -Fo"
+ FLAG_EXE="-Fe"
+elif [ "$2" != "" ]; then
+ echo "Unknown C compiler"
+ exit 1
+fi
+
+if [ "$2" != "" ]; then
+ if command -v $COMPILE >/dev/null 2>&1; then
+ echo "C compiler found"
+ else
+ echo "C compiler not found"
+ exit 1
+ fi
+fi
+
+case $(uname | tr '[:upper:]' '[:lower:]') in
+ *darwin*)
+ OS=macOS
+ if [ "$2" = "" ]; then
+ if command -v clang >/dev/null 2>&1; then
+ echo "C compiler found - Clang"
+ COMPILE=clang
+ elif command -v gcc >/dev/null 2>&1; then
+ echo "C compiler found - GCC"
+ else
+ echo "C compiler not found"
+ exit 1
+ fi
+ fi
+ ;;
+ *msys*|*cygwin*|*mingw*|*nt*|*win*)
+ OS=Windows
+ EXE_POSTFIX=.exe
+ if [ "$2" = "" ]; then
+ if command -v cl.exe >/dev/null 2>&1; then
+ echo "C compiler found - MSVC"
+ COMPILE=cl.exe
+ OBJ_POSTFIX=.obj
+ FLAG_OBJ="-c -Fo"
+ FLAG_EXE="-Fe"
+ elif command -v gcc >/dev/null 2>&1; then
+ echo "C compiler found - GCC"
+ elif command -v clang >/dev/null 2>&1; then
+ echo "C compiler found - Clang"
+ COMPILE=clang
+ else
+ echo "C compiler not found"
+ exit 1
+ fi
+ fi
+ if [ "$COMPILE" = "cl.exe" ]; then
+ LINK_FLAGS="Shlwapi.lib Advapi32.lib"
+ else
+ LINK_FLAGS="-lShlwapi -lAdvapi32"
+ fi
+ ;;
+ *)
+ if [ "$2" = "" ]; then
+ if command -v gcc >/dev/null 2>&1; then
+ echo "C compiler found - GCC"
+ elif command -v clang >/dev/null 2>&1; then
+ echo "C compiler found - Clang"
+ COMPILE=clang
+ else
+ echo "C compiler not found"
+ exit 1
+ fi
+ fi
+ ;;
+esac
+
+if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "clang" ]; then
+ if [ "$1" = "release" ]; then
+ FLAGS="-O3"
+ elif [ "$COMPILE" = "gcc" ] && [ "$OS" != "Windows" ]; then
+ FLAGS="-O0 -fsanitize=undefined,address,leak"
+ elif [ "$OS" != "Windows" ]; then
+ FLAGS="-O0 -fsanitize=undefined,address"
+ else
+ FLAGS="-O0"
+ fi
+else
+ if [ "$1" = "release" ]; then
+ FLAGS="-O2"
+ else
+ FLAGS="-Od"
+ fi
+fi
+
+echo ""
+
+echo "Build saw_test_suite"
+$COMPILE ${FLAGS} \
+ ${FLAG_EXE}"build/saw_test_suite${EXE_POSTFIX}" \
+ "source/tests/_static.c" \
+ ${LINK_FLAGS}
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+echo "Run tests"
+echo ""
+
+STATUS=0
+
+./build/saw_test_suite
+if [ $? -ne 0 ]; then
+ STATUS=1
+fi
+
+exit $STATUS