From 7db3e9708553fcb78d1e053d3377dfdfcb863971 Mon Sep 17 00:00:00 2001 From: Quinn Date: Fri, 12 Sep 2025 17:42:46 +0200 Subject: [PATCH] seperate out library compilation from general compilation This can help with a more nuanced compilation. (eg. use system libraries rather than compile our own) Furthermore, it decreases the needed compilation time, since we needn't recompile the whole thing when having cleaned out our local sources. --- .gitignore | 1 + Makefile | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index df6e345..c3e3615 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,6 @@ *.lock /bin/ /obj/ +/lib/obj/ compile_commands.json compile_commands.events.json diff --git a/Makefile b/Makefile index c0a08e9..4c49356 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ CFLAGS += -fsanitize=address -ftrapv -g LDFLAGS += -fsanitize=address -ftrapv endif CPPFLAGS += -Iinclude -Ilib/glad/include -Ilib/glfw/include -Ilib/libarchive/libarchive -LDFLAGS += -Lobj/lib/glfw/src -Lobj/lib/libarchive/libarchive +LDFLAGS += -Llib/obj/glfw/src -Llib/obj/libarchive/libarchive LDLIBS += -lm -lglfw -larchive # detect if we're compiling on Windows, meaning @@ -43,21 +43,25 @@ SRC := $(wildcard src/*.c src/*/*.c src/*/*/*.c src/*/*/*/*.c src/*/*/*/*/* OBJ := $(SRC:%.c=obj/%.o) TEST := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c) -.PHONY: all test clean libs +# TODO: potentially automatically detect whether we should compile libs, or if we can just go ahead. +.PHONY: all libs test clean clean-libs all: bin/$(NAME) -libs: obj/lib/glfw/ obj/lib/libarchive/ +libs: lib/obj/glfw/ lib/obj/libarchive/ test: bin/TEST_$(NAME); bin/TEST_$(NAME) clean: @[ -d bin/ ] && rm -vr bin/ || true @[ -d obj/ ] && rm -vr obj/ || true +clean-libs: + @[ -d lib/obj/ ] && rm -vr lib/obj/ + # compiles the libraries using cmake -obj/lib/%/: lib/%/ +lib/obj/%/: lib/%/ cmake -S $< -B $@ $(MAKE) -C $@ # link together a runtime binary -bin/$(NAME): libs $(OBJ) +bin/$(NAME): $(OBJ) $(info [CC/LD] $@) @mkdir -p $(@D) @$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)