CC := gcc GLSLC := glslc ifeq ($(PROD),1) CFLAGS := -std=c99 -O2 # production flags else CFLAGS := -std=c99 -Wall -Wextra -Wpedantic -g -DDEBUG # debug flags endif DEP_CGLM ?= /usr/local/lib/libcglm.a LDFLAGS += -lm -lvulkan `sdl2-config --cflags --libs` $(DEP_CGLM) SRCD := src OBJD := obj BIND := bin FILD := files SHDR := shaders SFILE = $(shell find $(SRCD)/ -type f 2> /dev/null) CSRCS = $(filter %.c, $(SFILE)) COBJS = $(CSRCS:$(SRCD)/%.c=$(OBJD)/%.o) FILES = $(shell find $(FILD) -type f 2> /dev/null) SHDRS = $(filter %.vert %.frag, $(FILES)) SHOBJ = $(SHDRS:$(FILD)/$(SHDR)/%=$(BIND)/$(SHDR)/%.spv) CDEPS = $(COBJS:%.o=%.d) -include $(CDEPS) NAME := test all: $(NAME) $(SHOBJ) $(NAME): $(DEP_CGLM) $(BIND)/$(NAME) clean: rm -rf $(BIND) rm -rf $(OBJD) $(OBJD)/%.o: $(SRCD)/%.c @mkdir -p $(dir $@) $(CC) $(CFLAGS) -MMD -MF $(@:%.o=%.d) -c $< -o $@ $(BIND)/$(SHDR)/%.spv: $(FILD)/$(SHDR)/% @mkdir -p $(dir $@) $(GLSLC) $< -o $@ $(BIND)/$(NAME): $(COBJS) @mkdir -p $(dir $@) $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ # Dependency Tools DEP_CGLM_DIR ?= /usr/local/src $(DEP_CGLM): @echo "-- DEPENDENCY NOT INSTALLED --" @echo "DEP_CGLM=$(DEP_CGLM) does not exist" @echo "use '[sudo] make cglm_install' to install it quickly" @echo "DEP_CGLM_DIR is the dir where the source code will be cloned" @echo " (default is $(DEP_CGLM_DIR))" @exit 1 cglm_install: @echo "cloning cglm at $(DEP_CGLM_DIR)" cd $(DEP_CGLM_DIR); \ git clone "https://github.com/recp/cglm"; \ cd cglm && mkdir build && cd build; \ cmake .. -DCGLM_STATIC=ON; \ make; \ mkdir -p $(dir $(DEP_CGLM)); \ mv libcglm.a $(DEP_CGLM); \ # Debug Tools RUN_CMD := cd $(BIND) && ./$(NAME) UNITY := unity $(BIND)/$(UNITY): $(CSRCS) @mkdir -p $(dir $@) for src in $^; do \ cat $${src} >> $(SRCD)/$(UNITY).c; \ done $(CC) $(CFLAGS) $(SRCD)/$(UNITY).c -o $@ @rm $(SRCD)/$(UNITY).c analyze: clean scan-build \ -enable-checker alpha \ -enable-checker core \ -enable-checker deadcode \ -enable-checker security \ -enable-checker unix \ make $(BIND)/$(UNITY) sanitize: clean $(MAKE) CC="clang -fsanitize=address" run run: all $(RUN_CMD) valgrind: all cd $(BIND) && \ valgrind -s --leak-check=full --show-leak-kinds=all ./$(NAME) .PHONY: all $(NAME) clean cglm_install analyze sanitize run valgrind