From a10d2bf57ba42a8fe5d67d7ba4fc2ddc2d759c8e Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Mon, 25 Mar 2024 09:50:59 -0500 Subject: [PATCH] Makefile: Generate compile_commands.json Introduce a make target for generating compile_commands.json to feed clangd and the Language Server Protocol, to gain better editor integration. Add the relevant files to .gitignore. Signed-off-by: Bjorn Andersson --- .gitignore | 2 ++ Makefile | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index f12beef..0faf217 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.o qdl ks +compile_commands.json +.cache diff --git a/Makefile b/Makefile index e0dec0d..6b035ad 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,13 @@ $(OUT): $(OBJS) $(KS_OUT): $(KS_OBJS) $(CC) -o $@ $^ $(LDFLAGS) +compile_commands.json: $(SRCS) $(KS_SRCS) + @echo -n $^ | jq -snR "[inputs|split(\" \")[]|{directory:\"$(PWD)\", command: \"$(CC) $(CFLAGS) -c \(.)\", file:.}]" > $@ + clean: rm -f $(OUT) $(OBJS) rm -f $(KS_OUT) $(KS_OBJS) + rm -f compile_commands.json install: $(OUT) $(KS_OUT) install -d $(DESTDIR)$(prefix)/bin