aboutsummaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-31 01:25:05 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit1f28c3c733ea3ae4234bff91e1c55e61b1ee3e96 (patch)
tree0ab52e362da03fde741ce8159ef8a4110cd1fb6a /build.sh
parentec1a48e7b86fcd00127dd5a88d56c42083af1d78 (diff)
Starting on asm, implementing extern function call so progress is visible
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh115
1 files changed, 81 insertions, 34 deletions
diff --git a/build.sh b/build.sh
index 214769a..8fd07b8 100755
--- a/build.sh
+++ b/build.sh
@@ -23,41 +23,88 @@ if [ ! -z "$PEDANTIC" ]; then
CFLAGS+="-DAMAL_PEDANTIC -pedantic "
fi
-CFLAGS+="-Wall -Wextra -Werror -g -O0 -DDEBUG -std=c89 -D_GNU_SOURCE"
-LIBS+="-pthread"
-
-BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o "$this_script_dir/libamalgam.so""
-set -x
-time $CC $BUILD_ARGS
-if [ ! -z "$SCAN_BUILD" ]; then
- scan-build $CC $BUILD_ARGS
-fi
-set +x
+build_test() {
+ CFLAGS+="-Wall -Wextra -Werror -Wno-format-security -g -O0 -DDEBUG -std=c89 -D_GNU_SOURCE"
+ LIBS+="-pthread"
-if [ -z "$NO_TEST" ]; then
- source_files_tests=$(readlink -f $(find "$this_script_dir/tests" -name "*.c"))
+ BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o "$this_script_dir/libamalgam.so""
set -x
- time $CC $source_files_tests $CFLAGS $LIBS -o test "$this_script_dir/libamalgam.so"
-fi
+ time $CC $BUILD_ARGS
+ if [ ! -z "$SCAN_BUILD" ]; then
+ scan-build $CC $BUILD_ARGS
+ fi
+ set +x
+
+ if [ -z "$NO_TEST" ]; then
+ source_files_tests=$(readlink -f $(find "$this_script_dir/tests" -name "*.c"))
+ set -x
+ time $CC $source_files_tests $CFLAGS $LIBS -o test "$this_script_dir/libamalgam.so"
+ fi
-set +x
-compile_commands=$(
-first=0
-echo "["
-for source_file in $source_files $source_files_tests; do
- if [ $first == 1 ]; then
- echo ","
+ set +x
+ compile_commands=$(
+ first=0
+ echo "["
+ for source_file in $source_files $source_files_tests; do
+ if [ $first == 1 ]; then
+ echo " ,"
+ fi
+ first=1
+ o_file="${source_file}.o"
+ echo " {"
+ echo " \"file\": \"$source_file\","
+ echo " \"directory\": \"$this_script_dir\","
+ echo " \"command\": \"$CC -o $o_file $CFLAGS $LIBS -c $source_file\""
+ echo " }"
+ done
+ echo "]")
+ echo "$compile_commands" > "$this_script_dir/compile_commands.json"
+}
+
+build_release() {
+ CFLAGS+="-Wall -Wextra -Werror -Wno-format-security -O2 -DNDEBUG -std=c89 -D_GNU_SOURCE -s"
+ LIBS+="-pthread"
+
+ BUILD_ARGS="$source_files $CFLAGS $LIBS -shared -fpic -o "$this_script_dir/libamalgam.so""
+ set -x
+ time $CC $BUILD_ARGS
+ if [ ! -z "$SCAN_BUILD" ]; then
+ scan-build $CC $BUILD_ARGS
fi
- first=1
- o_file="${source_file}.o"
- echo " {"
- echo " \"file\": \"$source_file\","
- echo " \"directory\": \"$this_script_dir\","
- echo " \"command\": \"$CC -o $o_file $CFLAGS $LIBS -c $source_file\","
- echo " \"output\": \"$o_file\""
- echo " }"
-done
-echo "]")
-echo "$compile_commands" > "$this_script_dir/compile_commands.json"
-
-echo "Finished building"
+ set +x
+
+ set +x
+ compile_commands=$(
+ first=0
+ echo "["
+ for source_file in $source_files; do
+ if [ $first == 1 ]; then
+ echo " ,"
+ fi
+ first=1
+ o_file="${source_file}.o"
+ echo " {"
+ echo " \"file\": \"$source_file\","
+ echo " \"directory\": \"$this_script_dir\","
+ echo " \"command\": \"$CC -o $o_file $CFLAGS $LIBS -c $source_file\""
+ echo " }"
+ done
+ echo "]")
+ echo "$compile_commands" > "$this_script_dir/compile_commands.json"
+}
+
+case "$1" in
+ "test")
+ build_test
+ ;;
+ "release")
+ build_release
+ ;;
+ *)
+ echo "usage: build.sh COMMAND"
+ echo "COMMANDS:"
+ echo " test Build tests"
+ echo " release Build as a release package, enabling all optimizations and stripping of binary"
+ exit 1
+ ;;
+esac