Skip to content

Instantly share code, notes, and snippets.

@JayKickliter
Created February 28, 2018 21:26
Show Gist options
  • Save JayKickliter/f4e1945abe1d3bbbe3263640a3669e3c to your computer and use it in GitHub Desktop.
Save JayKickliter/f4e1945abe1d3bbbe3263640a3669e3c to your computer and use it in GitHub Desktop.
Generate 'compile_commands.json' in Makefile
%.compdb_entry: %.c
@echo " {" > $@
@echo " \"command\": \"cc $(CFLAGS) $(CPPFLAGS) -c $<\"," >> $@
@echo " \"directory\": \"$(CURDIR)\"," >> $@
@echo " \"file\": \"$<\"" >> $@
@echo " }," >> $@
COMPDB_ENTRIES = $(addsuffix .compdb_entry, $(basename $(SOURCES)))
compile_commands.json: $(COMPDB_ENTRIES)
@echo "[" > [email protected]
@cat $^ >> [email protected]
@sed '$$d' < [email protected] > $@
@echo " }" >> $@
@echo "]" >> $@
@rm [email protected]
clang-tidy: compile_commands.json
run-clang-tidy.py
cppcheck: compile_commands.json
cppcheck --enable=all --inconclusive --std=c99 --project=$(CURDIR)/compile_commands.json --template=gcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment