Commit: cafba69bda40a9a83da5834f8753a7ef45269fd4
Parent: c5faa279e4cf4ae3c73ded7e7f4fa5f0d2e8b8cb
Author: Randy Palamar
Date: Tue, 31 Dec 2024 15:59:49 -0700
tidy up build script
also add some cross compiling tests (easily doable with clang but
not so much with gcc) to make sure neither freestanding target breaks
Diffstat:
M | build.sh | | | 31 | ++++++++++++++++++++++++------- |
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/build.sh b/build.sh
@@ -1,17 +1,28 @@
#!/bin/sh
-cflags="-march=native -O3 -std=c99 -Wall -Wextra -fno-builtin"
+cflags="-march=native -std=c99 -Wall -Wextra -fno-builtin -static"
#cflags="${cflags} -fproc-stat-report"
#cflags="${cflags} -Rpass-missed=.*"
#cflags="${cflags} -fsanitize=address,undefined"
-ldflags="-static"
cc=${CC:-cc}
-debug=${DEBUG}
+build=release
-src=platform_posix.c
+for arg in "$@"; do
+ case "$arg" in
+ clang) cc=clang ;;
+ gcc) cc=gcc ;;
+ debug) build=debug ;;
+ release) build=release ;;
+ *) echo "usage: $0 [debug|release] [gcc|clang]" ;;
+ esac
+done
-[ $debug ] && cflags="$cflags -O0 -ggdb -D_DEBUG"
-[ ! $debug ] && ldflags="-s $ldflags"
+case "${build}" in
+debug) cflags="${cflags} -O0 -ggdb -D_DEBUG" ;;
+release) cflags="${cflags} -O3 -s" ;;
+esac
+
+src=platform_posix.c
case $(uname -sm) in
"Linux aarch64")
@@ -24,4 +35,10 @@ case $(uname -sm) in
;;
esac
-${cc} $cflags $ldflags $src -o jdict
+${cc} ${cflags} ${ldflags} $src -o jdict
+
+# NOTE(rnp): cross compile tests
+clang --target=x86_64-unknown-linux-musl -O3 -nostdlib -ffreestanding -fno-stack-protector \
+ -Wl,--gc-sections platform_linux_amd64.c -o /dev/null
+clang --target=aarch64-unknown-linux-musl -O3 -nostdlib -ffreestanding -fno-stack-protector \
+ -Wl,--gc-sections platform_linux_aarch64.c -o /dev/null