]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
build: add compile-commands target
authorEric Leblond <el@stamus-networks.com>
Sat, 19 Apr 2025 23:49:47 +0000 (01:49 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 9 May 2025 05:50:39 +0000 (07:50 +0200)
It generates a `compile_commands.json` suitable for clangd.
This is almost mandatory to have a command like this one for NixOs
users as tool like bear are not able to intercept correctly the
clang calls due to the usage of a wrapper.

Ticket: #7669

Makefile.am
configure.ac

index ac3addea017425c28e57f4a55e7be9e9596e0607..7e8c37e9fa5fe3482dee9fb73c91ee03a6ed6437 100644 (file)
@@ -18,6 +18,8 @@ DIST_SUBDIRS = $(SUBDIRS) examples/lib/simple examples/lib/custom
 
 CLEANFILES = stamp-h[0-9]*
 
+DISTCLEANFILES = compile_commands.json
+
 install-data-am:
        @echo "Run 'make install-conf' if you want to install initial configuration files. Or 'make install-full' to install configuration and rules";
 
@@ -71,3 +73,16 @@ install-library:
 
 install-headers:
        cd src && $(MAKE) $@
+
+compile-commands:
+if HAVE_CLANG
+       $(MAKE) -C src clean
+       TMP_DIR=$$(mktemp -d --suffix=.suricata-compile-commands) && \
+       $(MAKE) EXTRA_CFLAGS="-MJ $$TMP_DIR/\$$*.json" && \
+       echo '[' > $(top_builddir)/compile_commands.json && \
+       cat $$TMP_DIR/*.json >> $(top_builddir)/compile_commands.json && \
+       echo ']' >> $(top_builddir)/compile_commands.json && \
+       rm -rf $$TMP_DIR
+else
+       @echo "clang compile_commands.json generation not supported with current compiler"
+endif
index fdc23785d0bdb773616e19d76646cbac05cbd4e5..58acbcc12b72e57af447a6c7c06c60d87d2cede7 100644 (file)
@@ -64,6 +64,8 @@
             ;;
     esac
 
+    AM_CONDITIONAL([HAVE_CLANG], [test "x$compiler" == "xclang"])
+
     # Checks for programs.
     AC_PROG_AWK
     AC_PROG_CC