summaryrefslogtreecommitdiff
path: root/build_and_test.sh
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-01-12 20:21:39 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-01-12 20:21:39 +0100
commited1bceaf27e068c171889a8583b6516e528aa317 (patch)
tree0dd9044cf12d53ce584b564e90483b2e52a06997 /build_and_test.sh
parent59a04dc0300de5dcab4754d7309f9c11c950b55b (diff)
downloadkit-ed1bceaf27e068c171889a8583b6516e528aa317.zip
New build script
Diffstat (limited to 'build_and_test.sh')
-rwxr-xr-x[-rw-r--r--]build_and_test.sh174
1 files changed, 113 insertions, 61 deletions
diff --git a/build_and_test.sh b/build_and_test.sh
index 8da4d96..f7eb5bc 100644..100755
--- a/build_and_test.sh
+++ b/build_and_test.sh
@@ -1,6 +1,58 @@
-#
-# General build instructions
-#
+#!/bin/sh
+
+BUILD_TYPE=
+USE_COMPILER=
+DESTINATION=
+EXTRA_OPTIONS=
+EXTRA_LINK_OPTIONS=
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ -H|--help)
+ echo "Build script for C projects"
+ echo ""
+ echo "Usage: ./build_and_test.sh [OPTIONS]"
+ echo ""
+ echo " -H --help - Print this info"
+ echo " -t --type - Set build type: debug, release"
+ echo " -c --compiler - Set compiler to use: gcc, clang, msvc, emcc"
+ echo " -d --destination - Set destination path"
+ echo " -o --options - Set additional options for the compiler"
+ echo " -l --link - Set additional options for the linker"
+ echo ""
+ exit 0
+ ;;
+ -t|--type)
+ BUILD_TYPE=$2
+ shift
+ shift
+ ;;
+ -c|--compiler)
+ USE_COMPILER="$2"
+ shift
+ shift
+ ;;
+ -d|--destination)
+ DESTINATION="$2"
+ shift
+ shift
+ ;;
+ -o|--options)
+ EXTRA_OPTIONS="$2"
+ shift
+ shift
+ ;;
+ -l|--link)
+ EXTRA_LINK_OPTIONS="$2"
+ shift
+ shift
+ ;;
+ *)
+ echo "Unknown option $1"
+ shift
+ ;;
+ esac
+done
FOLDER=out_gcc
OS=Linux
@@ -13,37 +65,37 @@ FLAG_OBJ="-c -o "
FLAG_EXE="-o "
LINK_FLAGS=
-if [ "$2" = "gcc" ]; then
+if [ "$USE_COMPILER" = "gcc" ]; then
FOLDER=out_gcc
COMPILE=gcc
COMPILEPP=g++
-elif [ "$2" = "clang" ]; then
+elif [ "$USE_COMPILER" = "clang" ]; then
FOLDER=out_clang
COMPILE=clang
COMPILEPP=clang++
-elif [ "$2" = "msvc" ]; then
+elif [ "$USE_COMPILER" = "msvc" ]; then
FOLDER=out_msvc
COMPILE=cl.exe
COMPILEPP=cl.exe
OBJ_POSTFIX=.obj
FLAG_OBJ="-c -Fo"
FLAG_EXE="-Fe"
-elif [ "$2" = "emcc" ]; then
+elif [ "$USE_COMPILER" = "emcc" ]; then
FOLDER=out_emcc
COMPILE=emcc
COMPILEPP=em++
EXE_POSTFIX=.js
LINK_FLAGS="-sFULL_ES3=1"
-elif [ "$2" != "" ]; then
+elif [ "$USE_COMPILER" != "" ]; then
echo "Unknown C compiler"
exit 1
fi
-if [ "$3" != "" ]; then
- FOLDER="$3"
+if [ "$DESTINATION" != "" ]; then
+ FOLDER="$DESTINATION"
fi
-if [ "$2" != "" ]; then
+if [ "$USE_COMPILER" != "" ]; then
if command -v $COMPILE >/dev/null 2>&1; then
echo "C compiler found"
else
@@ -56,7 +108,7 @@ if [ "$COMPILE" != "emcc" ]; then
case $(uname | tr '[:upper:]' '[:lower:]') in
*darwin*)
OS=macOS
- if [ "$2" = "" ]; then
+ if [ "$USE_COMPILER" = "" ]; then
if command -v clang >/dev/null 2>&1; then
echo "C compiler found - Clang"
COMPILE=clang
@@ -72,7 +124,7 @@ if [ "$COMPILE" != "emcc" ]; then
*msys*|*cygwin*|*mingw*|*nt*|*win*)
OS=Windows
EXE_POSTFIX=.exe
- if [ "$2" = "" ]; then
+ if [ "$USE_COMPILER" = "" ]; then
if command -v cl.exe >/dev/null 2>&1; then
echo "C compiler found - MSVC"
COMPILE=cl.exe
@@ -98,7 +150,7 @@ if [ "$COMPILE" != "emcc" ]; then
fi
;;
*)
- if [ "$2" = "" ]; then
+ if [ "$USE_COMPILER" = "" ]; then
if command -v gcc >/dev/null 2>&1; then
echo "C compiler found - GCC"
elif command -v clang >/dev/null 2>&1; then
@@ -115,7 +167,7 @@ if [ "$COMPILE" != "emcc" ]; then
fi
if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "emcc" ]; then
- if [ "$1" = "release" ]; then
+ if [ "$BUILD_TYPE" = "release" ]; then
FLAGS="-O3 -DNDEBUG"
elif [ "$COMPILE" = "gcc" ] && [ "$OS" != "Windows" ]; then
FLAGS="-O0 -fsanitize=undefined,address,leak"
@@ -125,13 +177,13 @@ if [ "$COMPILE" = "gcc" ] || [ "$COMPILE" = "emcc" ]; then
FLAGS="-O0"
fi
elif [ "$COMPILE" = "clang" ]; then
- if [ "$1" = "release" ]; then
+ if [ "$BUILD_TYPE" = "release" ]; then
FLAGS="-O3 -DNDEBUG"
else
FLAGS="-O0"
fi
else
- if [ "$1" = "release" ]; then
+ if [ "$BUILD_TYPE" = "release" ]; then
FLAGS="-O2 -DNDEBUG"
else
FLAGS="-Od"
@@ -139,12 +191,16 @@ else
fi
if [ "$COMPILE" = "clang" ] || [ "$OS" = "macOS" ]; then
- FLAGS="-fblocks ${FLAGS}"
- LINK_FLAGS="-lBlocksRuntime ${LINK_FLAGS}"
+ FLAGS="-fblocks $FLAGS"
+ LINK_FLAGS="-lBlocksRuntime $LINK_FLAGS"
fi
-if [ "$COMPILE" = "clang" ]; then
- COMPILEPP="${COMPILEPP} -stdlib=libc++"
+if [ "$EXTRA_OPTIONS" != "" ]; then
+ FLAGS="$EXTRA_OPTIONS $FLAGS"
+fi
+
+if [ "$EXTRA_LINK_OPTIONS" != "" ]; then
+ LINK_FLAGS="$EXTRA_LINK_OPTIONS $LINK_FLAGS"
fi
if [ ! -d "$FOLDER" ]; then
@@ -152,73 +208,69 @@ if [ ! -d "$FOLDER" ]; then
fi
echo ""
-echo "Compiler options: ${FLAGS}"
-echo "Link options: ${LINK_FLAGS}"
+echo "Compiler options: $FLAGS"
+echo "Link options: $LINK_FLAGS"
echo ""
-#
-# Project-specific instructions
-#
-
echo "Build kit"
-$COMPILE ${FLAGS} \
- ${FLAG_OBJ}"${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILE $FLAGS \
+ ${FLAG_OBJ}"$FOLDER/kit$OBJ_POSTFIX" \
"source/kit/_lib.c"
if [ $? -ne 0 ]; then
exit 1
fi
echo "Build test suite"
-$COMPILE ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_suite${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILE $FLAGS \
+ $FLAG_EXE"$FOLDER/test_suite$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/_exe.c" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
-$COMPILE ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_too_many_assertions${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILE $FLAGS \
+ $FLAG_EXE"$FOLDER/test_too_many_assertions$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/test_too_many_assertions.c" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
-$COMPILE ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_too_many_tests${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILE $FLAGS \
+ $FLAG_EXE"$FOLDER/test_too_many_tests$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/test_too_many_tests.c" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
-$COMPILEPP ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_cpp${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILEPP $FLAGS \
+ $FLAG_EXE"$FOLDER/test_cpp$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/test_cpp.cpp" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
-$COMPILEPP ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_signals${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILEPP $FLAGS \
+ $FLAG_EXE"$FOLDER/test_signals$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/test_signals.cpp" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
-$COMPILE ${FLAGS} \
- ${FLAG_EXE}"${FOLDER}/test_interprocess${EXE_POSTFIX}" \
- "${FOLDER}/kit${OBJ_POSTFIX}" \
+$COMPILE $FLAGS \
+ $FLAG_EXE"$FOLDER/test_interprocess$EXE_POSTFIX" \
+ "$FOLDER/kit$OBJ_POSTFIX" \
"source/tests/test_interprocess.c" \
- ${LINK_FLAGS}
+ $LINK_FLAGS
if [ $? -ne 0 ]; then
exit 1
fi
@@ -228,12 +280,12 @@ echo ""
STATUS=0
-${FOLDER}/test_suite
+$FOLDER/test_suite
if [ $? -ne 0 ]; then
STATUS=1
fi
-${FOLDER}/test_too_many_assertions --quiet
+$FOLDER/test_too_many_assertions --quiet
if [ $? -eq 0 ]; then
echo "too many assertions - OK"
else
@@ -241,7 +293,7 @@ else
STATUS=1
fi
-${FOLDER}/test_too_many_tests --quiet
+$FOLDER/test_too_many_tests --quiet
if [ $? -eq 0 ]; then
echo "too many tests - OK"
else
@@ -249,7 +301,7 @@ else
STATUS=1
fi
-${FOLDER}/test_cpp --quiet
+$FOLDER/test_cpp --quiet
if [ $? -eq 0 ]; then
echo "cpp - OK"
else
@@ -257,7 +309,7 @@ else
STATUS=1
fi
-${FOLDER}/test_signals --quiet
+$FOLDER/test_signals --quiet
if [ $? -eq 0 ]; then
echo "signals - OK"
else
@@ -265,9 +317,9 @@ else
STATUS=1
fi
-${FOLDER}/test_interprocess clean
-${FOLDER}/test_interprocess reader &
-${FOLDER}/test_interprocess writer
+$FOLDER/test_interprocess clean
+$FOLDER/test_interprocess reader &
+$FOLDER/test_interprocess writer
if [ $? -eq 0 ]; then
echo "interprocess - OK"
else