Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Use the sanitizers the compiler offers
Diffstat (limited to '')
-rwxr-xr-xtools/build-development.sh26
1 file changed, 21 insertions, 5 deletions
diff --git a/tools/build-development.sh b/tools/build-development.sh
index aaa9e71..d340057 100755
--- a/tools/build-development.sh
+++ b/tools/build-development.sh
@@ -1,9 +1,10 @@
#!/bin/sh
-# Build cgit for development and debugging. The sanitizers stop the program at
-# a memory error or undefined behaviour, which makes it slow, so the result is
-# for testing rather than serving. With clang it also leaves a compilation
-# database in build/ for a language server, and with ctags a tags file there.
+# Build cgit for development and debugging. The sanitizers the compiler offers
+# stop the program at a memory error or undefined behaviour, which makes it
+# slow, so the result is for testing rather than serving. With clang it also
+# leaves a compilation database in build/ for a language server, and with
+# ctags a tags file there.
#
# Any arguments go on to make, the way Lua flags do where pkg-config cannot
# find Lua:
@@ -20,7 +21,22 @@ cd "$(dirname "$0")/.."
# flags, and cleanall rather than clean because only cleanall descends into
# vendor/git.
make cleanall
-make "$@" CFLAGS="-O0 -g3" DEVELOPER=1 SANITIZE=address,undefined \
+
+# OpenBSD's compiler has no AddressSanitizer, so the build falls back to the
+# undefined behaviour checks alone, and to no sanitizer where neither links.
+probe=$(mktemp "${TMPDIR:-/tmp}/cgit-probe.XXXXXX")
+trap 'rm -f "$probe" "$probe.c"' EXIT
+printf 'int main(void){return 0;}\n' >"$probe.c"
+sanitize=""
+for checks in address,undefined undefined
+do
+ if ${CC:-cc} -fsanitize="$checks" -o "$probe" "$probe.c" >/dev/null 2>&1
+ then
+ sanitize="SANITIZE=$checks"
+ break
+ fi
+done
+make "$@" CFLAGS="-O0 -g3" DEVELOPER=1 $sanitize \
GENERATE_COMPILATION_DATABASE=yes
# clang writes one entry per object under vendor/git/compile_commands, each