Skip to content

Instantly share code, notes, and snippets.

@JayKickliter
Created February 28, 2018 21:26
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 "[" > $@.tmp
@cat $^ >> $@.tmp
@sed '$$d' < $@.tmp > $@
@echo " }" >> $@
@echo "]" >> $@
@rm $@.tmp
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