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.
This commit is contained in:
2025-09-12 17:42:46 +02:00
parent 8548c2d037
commit c2e1b67b4c
2 changed files with 10 additions and 5 deletions

1
.gitignore vendored
View File

@@ -18,5 +18,6 @@
*.lock
/bin/
/obj/
/lib/obj/
compile_commands.json
compile_commands.events.json

View File

@@ -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 @@ OBJ := $(SRC:%.c=obj/%.o) $(RES:%=obj/%.o)
TSRC := $(wildcard test/*.c test/*/*.c test/*/*/*.c test/*/*/*/*.c test/*/*/*/*/*.c test/*/*/*/*/*/*.c test/*/*/*/*/*/*/*.c test/*/*/*/*/*/*/*/*.c)
TOBJ := $(TSRC:%.c=obj/%.o)
.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)