spacegame/Makefile

63 lines
1.4 KiB
Makefile

CFLAGS = -I/usr/local/include -O0 -g -Wall -Wextra
LDFLAGS = -L/usr/local/lib -lglfw -lvulkan -ldl -Xlinker -rpath -Xlinker /usr/local/lib
CC = clang
GDB = lldb
SOURCES = $(wildcard src/*.c)
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
VERT_SPV = $(addsuffix .vert.spv, $(basename $(wildcard shader_src/*.vert)))
FRAG_SPV = $(addsuffix .frag.spv, $(basename $(wildcard shader_src/*.frag)))
.PHONY: all
all: spacegame $(VERT_SPV) $(FRAG_SPV)
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)
.PHONY: clean clean_compdb
clean:
rm $(FRAG_SPV)
rm $(VERT_SPV)
rm $(OBJECTS)
rm spacegame
clean_compdb:
rm -rf .compdb
rm compile_commands.json
run: spacegame
./spacegame
debug: spacegame
$(GDB) spacegame
%.vert.spv: %.vert
glslc $< -o $@
%.frag.spv: %.frag
glslc $< -o $@