Added compile_commands.json to Makefile

main
noah metz 2024-01-07 01:24:20 -07:00
parent d4582daae1
commit ffbc2d641e
2 changed files with 36 additions and 3 deletions

3
.gitignore vendored

@ -1,2 +1,5 @@
spacegame
*.o
.compdb
compile_commands.json
.cache

@ -2,10 +2,40 @@ CFLAGS = -I/opt/homebrew/include -O2 -Wall -Wextra
LDFLAGS = -L/opt/homebrew/lib -lglfw -lvulkan -ldl
CC = gcc
SOURCES = $(wildcard $(SRC)/*.c)
SOURCES = $(wildcard src/*.c)
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
spacegame: $(OBJECTS)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
.compdb/%.compdb_entry: %.c
@mkdir -p $(shell dirname $@)
@echo " {" > $@
@echo " \"command\": \"$(CC) $(CFLAGS) -c $<\"," >> $@
@echo " \"directory\": \"$(CURDIR)\"," >> $@
@echo " \"file\": \"$<\"" >> $@
@echo " }," >> $@
COMPDB_ENTRIES = $(addprefix .compdb/, $(addsuffix .compdb_entry, $(basename $(SOURCES))))
compile_commands.json: $(COMPDB_ENTRIES)
@echo "[" > $@.tmp
@cat $^ >> $@.tmp
@sed '$$d' < $@.tmp > $@
@echo " }" >> $@
@echo "]" >> $@
@rm $@.tmp
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
spacegame: src/main.o
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
.PHONY: clean clean_compdb
clean:
rm $(OBJECTS)
rm spacegame
clean_compdb:
rm -rf .compdb
rm compile_commands.json