From 81723d58c2c4e4e440561afe59a2fc1408191c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Sat, 21 Sep 2019 20:22:28 +0200 Subject: [PATCH 1/2] Add an option to the Makefile for creating compile_command.sjson `compile_command.json` is a compilation database files used by different clangd based IDEs and editors for more accurate code completion. In this patch a make target `compile-commands` is added as a PHONY target which creates such a file. The target is PHONY for easy updating of the database file. The logic used for creating is trivial and will treat all files as C++ (even the `.m`, `.mm` and `.c` files) and won't do escaping of `"` in any path. Information on `compile_commands.json` can be found on https://clang.llvm.org/docs/JSONCompilationDatabase.html --- common.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common.mk b/common.mk index a62e2892e7..e9f1eb9707 100644 --- a/common.mk +++ b/common.mk @@ -5,7 +5,7 @@ DIRS := $(sort $(dir $(OBJS))) # Make build directories DUMMY := $(shell mkdir -p $(DIRS)) -.PHONY: all clean +.PHONY: all clean compile-commands .SUFFIXES: .rc @@ -30,6 +30,13 @@ clean: -include $(DEPS) +compile-commands: + @echo "[" > compile_commands.json + @for file in $(SOURCES); do \ + echo "{ \"directory\": \"$(PROGDIR)\", \"command\": \"$(HOSTCXX) $(CXXFLAGS) -c -MMD $$(pwd)/$$file\", \"file\": \"$$(pwd)/$$file\" }," >> compile_commands.json; \ + done; + @echo "{ \"directory\": \"no\", \"command\": \"trailing\", \"file\": \"comma\"}]" >> compile_commands.json + # Silence stale header dependency errors %.h: @true From 273c4d90f6d813b1f79c96833eb65631e4ce9ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Sat, 21 Sep 2019 20:30:42 +0200 Subject: [PATCH 2/2] Add `.gitignore` rule for `compile_commands.json` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1c0f60b991..790df5e1a6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /Release /build /config.* +/compile_commands.json /makeobj/makeobj /makeobj/makeobj.exe *sim