Skip to content

Commit 880146a

Browse files
bk2204gitster
authored andcommitted
Makefile: avoid constant rebuilds with compilation database
Many contributors to software use a Language Server Protocol implementation to allow their editor to learn structural information about the code they write and provide additional features, such as jumping to the declaration or definition of a function or type. In C, the usual implementation is clangd, which requires compiling with clang. Because C and C++ projects lack a standard file system layout and build system, unlike languages such as Rust and Go, clangd requires a compilation database to be generated by the clang compiler in order to pass the proper compilation flags and discover all of the files necessary to make the LSP work. This is done by setting GENERATE_COMPILATION_DATABASE to "yes". However, when that's enabled and the user runs "make" a second time, all of the files are re-compiled, which is inconvenient for contributors to Git, since it makes small changes or rebases recompile the entirety of the codebase. This happens because the directory holding the compilation database is updated anytime an object is built, so its modification date will always be newer than the first object built. To solve this, use the same trick we do just above for the .depend directory and filter the compilation database directory out if it already exists, which avoids making it a target to be built. Signed-off-by: brian m. carlson <[email protected]> Helped-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f93ff17 commit 880146a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,7 @@ endif
27572757
compdb_dir = compile_commands
27582758

27592759
ifeq ($(GENERATE_COMPILATION_DATABASE),yes)
2760-
missing_compdb_dir = $(compdb_dir)
2760+
missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))
27612761
$(missing_compdb_dir):
27622762
@mkdir -p $@
27632763

0 commit comments

Comments
 (0)