101 lines
2.0 KiB
Bash
Executable File
101 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
BUILD_TYPE="debug"
|
|
COMPONENTS="all"
|
|
|
|
function join_array {
|
|
DELIM="$1"
|
|
shift
|
|
local IFS="$DELIM"
|
|
echo "$*"
|
|
}
|
|
|
|
SUPPORTED_COMPONENTS=("all" "testing" "core")
|
|
COMPONENTS_STRING="$(join_array "|" ${SUPPORTED_COMPONENTS[@]})"
|
|
|
|
while [[ $# > 0 ]];do
|
|
case $1 in
|
|
--release)
|
|
BUILD_TYPE="release"
|
|
shift
|
|
;;
|
|
--components)
|
|
COMPONENTS="$2"
|
|
shift
|
|
shift
|
|
;;
|
|
*|-*|--*)
|
|
echo "Unknown option $1"
|
|
echo "Usage: $0 [--release] [--components $COMPONENTS_STRING (Default: all)]"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
CC=clang
|
|
CFLAGS="-Wall -Wextra -Werror -pedantic"
|
|
LIBFLAGS="-fPIC -shared"
|
|
KERNEL="$(uname -s)"
|
|
MACHINE="$(uname -m)"
|
|
PLATFORM="${KERNEL}_${MACHINE}"
|
|
|
|
if [[ $CC == "gcc" ]]; then
|
|
# Used to disable the "ASan runtime does not come first in initial library list" error when compiling with gcc
|
|
export ASAN_OPTIONS=verify_asan_link_order=0
|
|
fi
|
|
|
|
case $COMPONENTS in
|
|
all)
|
|
SRC="src/wapp.c"
|
|
;;
|
|
testing)
|
|
SRC="src/testing/wapp_testing.c"
|
|
;;
|
|
core)
|
|
SRC="src/core/wapp_core.c"
|
|
;;
|
|
*)
|
|
echo "Unrecognised option for components: $COMPONENTS"
|
|
echo "Accepted options: $COMPONENTS_STRING"
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
TEST_INCLUDE="$(find src -type d | xargs -I{} echo -n "-I{} ") $(find tests -type d | xargs -I{} echo -n "-I{} ")"
|
|
TEST_SRC="$(find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")"
|
|
|
|
BUILD_DIR="libwapp-build/$PLATFORM-$BUILD_TYPE"
|
|
if [[ -d $BUILD_DIR ]]; then
|
|
rm -rf $BUILD_DIR
|
|
fi
|
|
mkdir -p $BUILD_DIR
|
|
|
|
if [[ $BUILD_TYPE == "release" ]]; then
|
|
CFLAGS+=" -O3"
|
|
else
|
|
CFLAGS+=" -g -fsanitize=address,undefined"
|
|
fi
|
|
|
|
OUT="$BUILD_DIR/libwapp.so"
|
|
TEST_OUT="$BUILD_DIR/wapptest"
|
|
|
|
# Compile tests
|
|
if [[ $(echo $TEST_SRC | xargs) != "" ]]; then
|
|
(set -x ; $CC $CFLAGS $TEST_INCLUDE $SRC $TEST_SRC -o $TEST_OUT)
|
|
fi
|
|
|
|
# Run tests and exit on failure
|
|
if [[ -f $TEST_OUT ]]; then
|
|
$TEST_OUT
|
|
STATUS="$?"
|
|
|
|
rm $TEST_OUT
|
|
|
|
if [[ $STATUS != "0" ]]; then
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Compile library
|
|
(set -x ; $CC $CFLAGS $LIBFLAGS $SRC -o $OUT)
|