Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Add a development build script
cgit's objects are compiled by its own rule rather than git's, so they took no -MJ flag and a compilation database held only git's sources.
-rw-r--r--source/cgit.mk7
-rwxr-xr-xtools/build-development.sh44
2 files changed, 49 insertions, 2 deletions
diff --git a/source/cgit.mk b/source/cgit.mk
index d0c9e68..876e353 100644
--- a/source/cgit.mk
+++ b/source/cgit.mk
@@ -164,9 +164,12 @@ $(CGIT_BUILD)/CGIT-CFLAGS: FORCE
echo "$$FLAGS" >$(CGIT_BUILD)/CGIT-CFLAGS; \
fi
+# compdb_args and missing_compdb_dir are git's, and stay empty unless
+# GENERATE_COMPILATION_DATABASE asks clang for a -MJ entry per object, which
+# puts cgit's sources in the database beside git's.
$(CGIT_OBJS): $(CGIT_BUILD)/%.o: $(CGIT_SRC)/%.c GIT-CFLAGS $(CGIT_BUILD)/CGIT-CFLAGS \
- $(missing_dep_dirs)
- $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
+ $(missing_dep_dirs) $(missing_compdb_dir)
+ $(QUIET_CC)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $<
$(CGIT_BUILD)/cgit: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)
@echo 1>&2 " * $(LUA_MESSAGE)"
diff --git a/tools/build-development.sh b/tools/build-development.sh
new file mode 100755
index 0000000..79b9259
--- /dev/null
+++ b/tools/build-development.sh
@@ -0,0 +1,44 @@
+#!/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.
+#
+# Any arguments go on to make, the way Lua flags do where pkg-config cannot
+# find Lua:
+#
+# ./tools/build-development.sh LUA_PKGCONFIG=luajit
+#
+# Going back to a normal build takes make cleanall first.
+
+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 \
+ GENERATE_COMPILATION_DATABASE=yes
+
+# clang writes one entry per object under vendor/git/compile_commands, each
+# ending in a comma, so they are joined into one array. cgit's are named after
+# ../../build, which a shell glob would pass over as hidden.
+if test -d vendor/git/compile_commands
+then
+ find vendor/git/compile_commands -name '*.json' -exec cat {} + |
+ sed -e '1s/^/[/' -e '$s/,$/]/' >build/compile_commands.json
+ test -s build/compile_commands.json || rm -f build/compile_commands.json
+fi
+
+if command -v ctags >/dev/null
+then
+ make tags
+fi