From 20802dfefd399a034900424b3813cf3a0d7718f6 Mon Sep 17 00:00:00 2001 From: kartofen Date: Sat, 25 Nov 2023 17:36:19 +0200 Subject: makefile install cglm --- Makefile | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d67b5ed..c34ba62 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,13 @@ CC := gcc GLSLC := glslc ifeq ($(PROD),1) -CFLAGS := -O2 # production flags +CFLAGS := -std=c99 -O2 # production flags else -CFLAGS := -Wall -Wextra -Wpedantic -g -DDEBUG # debug flags +CFLAGS := -std=c99 -Wall -Wextra -Wpedantic -g -DDEBUG # debug flags endif -CFLAGS += -std=c99 -lm -lvulkan `sdl2-config --cflags --libs` /usr/local/lib/libcglm.a +DEP_CGLM ?= /usr/local/lib/libcglm.a +LDFLAGS += -lm -lvulkan `sdl2-config --cflags --libs` $(DEP_CGLM) SRCD := src OBJD := obj @@ -28,8 +29,8 @@ CDEPS = $(COBJS:%.o=%.d) NAME := test -all: clean $(NAME) -$(NAME): $(BIND)/$(NAME) $(SHOBJ) +all: $(NAME) $(SHOBJ) +$(NAME): $(DEP_CGLM) $(BIND)/$(NAME) clean: rm -rf $(BIND) @@ -45,9 +46,31 @@ $(BIND)/$(SHDR)/%.spv: $(FILD)/$(SHDR)/% $(BIND)/$(NAME): $(COBJS) @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $^ -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ -# Extra Tools +# 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 @@ -74,9 +97,11 @@ analyze: clean sanitize: clean $(MAKE) CC="clang -fsanitize=address" run -run: $(NAME) +run: all $(RUN_CMD) -valgrind: $(BIND)/$(NAME) +valgrind: all cd $(BIND) && \ valgrind -s --leak-check=full --show-leak-kinds=all ./$(NAME) + +.PHONY: all $(NAME) clean cglm_install analyze sanitize run valgrind -- cgit v1.2.3