From: brian m. carlson Date: Fri, 9 May 2025 21:12:02 +0000 (+0000) Subject: Makefile: avoid constant rebuilds with compilation database X-Git-Tag: v2.50.0-rc0~32^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=880146aefe0e60e330409a916a0c1b4ac21388c6;p=thirdparty%2Fgit.git 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 Helped-by: Philippe Blain Signed-off-by: Junio C Hamano --- diff --git a/Makefile b/Makefile index 97e8385b66..ee36e700e8 100644 --- a/Makefile +++ b/Makefile @@ -2757,7 +2757,7 @@ endif compdb_dir = compile_commands ifeq ($(GENERATE_COMPILATION_DATABASE),yes) -missing_compdb_dir = $(compdb_dir) +missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir)) $(missing_compdb_dir): @mkdir -p $@