build: add compile-commands target

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
pull/13201/head
Eric Leblond 6 months ago committed by Victor Julien
parent 20371dbdf6
commit 2a2f38ff88

@ -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

@ -64,6 +64,8 @@
;;
esac
AM_CONDITIONAL([HAVE_CLANG], [test "x$compiler" == "xclang"])
# Checks for programs.
AC_PROG_AWK
AC_PROG_CC

Loading…
Cancel
Save