{"thread":{"id":"63431","subject":"[PATCH] Makefile: avoid constant rebuilds with compilation database","startedAt":"2025-05-09T21:12:05Z","lastAt":"2025-05-09T21:12:05Z","messageCount":1,"participants":["brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"517714","messageId":"20250509211202.3910761-1-sandals@crustytoothpaste.net","threadId":"63431","inReplyTo":null,"subject":"[PATCH] Makefile: avoid constant rebuilds with compilation database","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-05-09T21:12:02Z","receivedAt":"2025-05-09T21:12:05Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Many contributors to software use a Language Server Protocol\nimplementation to allow their editor to learn structural information\nabout the code they write and provide additional features, such as\njumping to the declaration or definition of a function or type.  In C,\nthe usual implementation is clangd, which requires compiling with clang.\n\nBecause C and C++ projects lack a standard file system layout and build\nsystem, unlike languages such as Rust and Go, clangd requires a\ncompilation database to be generated by the clang compiler in order to\npass the proper compilation flags and discover all of the files\nnecessary to make the LSP work.  This is done by setting\nGENERATE_COMPILATION_DATABASE to \"yes\".\n\nHowever, when that's enabled and the user runs \"make\" a second time,\nall of the files are re-compiled, which is inconvenient for contributors\nto Git, since it makes small changes or rebases recompile the entirety\nof the codebase.  This happens because the directory holding the\ncompilation database is updated anytime an object is built, so its\nmodification date will always be newer than the first object built.\n\nTo solve this, use the same trick we do just above for the .depend\ndirectory and filter the compilation database directory out if it\nalready exists, which avoids making it a target to be built.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\nHelped-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n Makefile | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Makefile b/Makefile\nindex 8a7f1c7654..8f38de8ebf 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2804,7 +2804,7 @@ endif\n compdb_dir = compile_commands\n \n ifeq ($(GENERATE_COMPILATION_DATABASE),yes)\n-missing_compdb_dir = $(compdb_dir)\n+missing_compdb_dir = $(filter-out $(wildcard $(compdb_dir)), $(compdb_dir))\n $(missing_compdb_dir):\n \t@mkdir -p $@\n \n"}]}