wizapp-stdlib/compile

67 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
BUILD_TYPE="debug"
while [[ $# > 0 ]];do
case $1 in
--release)
BUILD_TYPE="release"
shift
;;
*|-*|--*)
echo "Unknown option $1"
exit 1
;;
esac
done
CC=clang
CFLAGS="-Wall -Werror -pedantic "
LIBFLAGS="-fPIC -shared"
INCLUDE="\
$(find src -type d | xargs -I{} echo -n "-I{} ") \
"
TEST_INCLUDE="\
$(find tests -type d | xargs -I{} echo -n "-I{} ") \
"
SRC="\
$(find src -type f -name "*.c" | xargs -I{} echo -n "{} ") \
"
TEST_SRC="\
$(find tests -type f -name "*.c" | xargs -I{} echo -n "{} ") \
"
BUILD_DIR="libwapp-build/posix-$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 -fsanitize=undefined"
fi
OUT="$BUILD_DIR/libwapp.so"
TEST_OUT="$BUILD_DIR/wapptest"
# Compile tests
if [[ $(echo $TEST_SRC | xargs) != "" ]]; then
(set -x ; $CC $CFLAGS $INCLUDE $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 $INCLUDE $SRC -o $OUT)