SRC := src CDEBUG := -g -fsanitize=address,undefined CXXFLAGS := -Ilib $(CDEBUG) CPP := c++ LIBS := -lvulkan -lglfw OUT := ./out BIN := $(OUT)/main CXXCMD := $(CPP) $(CXXFLAGS) $(LIBS) define linit $(wordlist 2,$(words $(1)),x $(1)) endef define llast $(lastword $(1)) endef SRCS=$(wildcard $(SRC)/*) all: $(BIN) run: all VK_ADD_LAYER_PATH=/usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json VK_LOADER_LAYERS_ENABLE=*validation ./out/main clean: rm -f out/* cleanlsp: rm -f compile_commands.json cleanall: clean cleanlsp lsp: $(SRCS) rm -f compile_commands.json # TODO figure out how to depend on cleanlsp echo [ >> compile_commands.json for src in $(call linit,$^) ; do \ echo {'"'directory'"': '"'$(PWD)'"', '"'command'"': '"'$(CXXCMD) $^ -o $(BIN)'"', '"'file'"': '"'$$src'"'}, >> compile_commands.json ;\ done echo {'"'directory'"': '"'$(PWD)'"', '"'command'"': '"'$(CXXCMD) $^ -o $(BIN)'"', '"'file'"': '"'$(call llast,$^)'"'} >> compile_commands.json ;\ echo ] >> compile_commands.json $(BIN): $(SRCS) $(CXXCMD) $^ -o $@