Diff options
Diffstat (limited to '')
-rwxr-xr-xtools/build-development.sh36
1 file changed, 26 insertions, 10 deletions
diff --git a/tools/build-development.sh b/tools/build-development.sh
index 79b9259..00ff569 100755
--- a/tools/build-development.sh
+++ b/tools/build-development.sh
@@ -1,13 +1,10 @@
#!/bin/sh
-# Build cgit for development and debugging. It compiles without optimisation
-# and with full debug information, holds the sources to git's DEVELOPER
-# warnings, and links in AddressSanitizer and UndefinedBehaviorSanitizer, so a
-# memory error or undefined behaviour stops the program where it happens. With
-# clang it also leaves a compilation database in build/compile_commands.json,
-# where a language server looks for one, and with ctags a tags file in
-# build/tags. The sanitizers make cgit slow, so the result is for testing and
-# debugging rather than serving.
+# 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:
@@ -18,14 +15,33 @@
set -eu
-# Every make target below is written relative to the repository root.
cd "$(dirname "$0")/.."
# The build starts from clean so the bundled git objects pick up the same
# flags, and cleanall rather than clean because only cleanall descends into
# vendor/git.
make cleanall
-make "$@" CFLAGS="-O0 -g3" DEVELOPER=1 SANITIZE=address,undefined \
+
+# Named once, so the probe and the build use the same compiler. CC goes on
+# make's command line because git's Makefile sets it, which would override
+# the one from the environment.
+CC=${CC:-cc}
+
+# 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 -fsanitize="$checks" -o "$probe" "$probe.c" >/dev/null 2>&1
+ then
+ sanitize="SANITIZE=$checks"
+ break
+ fi
+done
+make "$@" CC="$CC" CFLAGS="-O0 -g3" DEVELOPER=1 $sanitize \
GENERATE_COMPILATION_DATABASE=yes
# clang writes one entry per object under vendor/git/compile_commands, each