diff --git a/.gitignore b/.gitignore index 42a2a3f5..bda2ccda 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ tags TAGS +# compile_commands.json +# (https://clang.llvm.org/docs/JSONCompilationDatabase.html) +compile_commands.json + # clangd cache (https://clangd.llvm.org/design/indexing#backgroundindex) .cache/ diff --git a/common.mak b/common.mak index b72eae41..e1b1814d 100644 --- a/common.mak +++ b/common.mak @@ -360,6 +360,7 @@ help: @echo ' all Build all tools (default target)' @echo ' install Install tools' @echo ' clean Delete all generated files' + @echo ' compdb Generate compile_commands.json for clangd' @echo '' @echo 'OPTIONS' @echo ' D=1 Build with debugging option "-Og"' @@ -375,6 +376,27 @@ help: @echo ' # make C=1 CHECK=smatch' .PHONY: help + +# 'compile_commands.json' generation +# +# Create the compilation database 'compile_commands.json'. See +# https://clang.llvm.org/docs/JSONCompilationDatabase.html for details. +# +.PHONY: compdb +compdb: + $(MAKE) clean +ifneq ($(shell command -v compiledb),) + compiledb $(MAKE) +else ifneq ($(shell command -v bear),) + ifeq ($(shell bear --help|grep -- '-- ...'),) + bear $(MAKE) + else + bear -- $(MAKE) + endif +else + $(error Please install either 'compiledb' or 'bear') +endif + # Automatic dependency generation # # Create ".o.d" dependency files with the -MM compile option for all ".c" and