diff --git a/Makefile.am b/Makefile.am index ac3addea01..7e8c37e9fa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index fdc23785d0..58acbcc12b 100644 --- a/configure.ac +++ b/configure.ac @@ -64,6 +64,8 @@ ;; esac + AM_CONDITIONAL([HAVE_CLANG], [test "x$compiler" == "xclang"]) + # Checks for programs. AC_PROG_AWK AC_PROG_CC