summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile25
1 files changed, 20 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 161b034..e1290d7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,47 @@
CC ?= gcc
SRCDIR ?= src
+INCDIR ?= inc
OBJDIR ?= obj
+TSTDIR ?= test
LIBS = -lm
-INCS = -Ithirdparty/cglm/include
+INCS = -Ithirdparty/cglm/include -Iinc/
CFLAGS ?= -D_FORTIFY_SOURCE=2 -Wall -Werror -Wno-error=unused-variable -g -Og
CFLAGS += -std=gnu11 -fms-extensions -flto
-APP_SOURCES = $(shell find $(SRCDIR) -name "*.c")
+APP_MAIN_SOURCES = $(SRCDIR)/main.c
+APP_MAIN_OBJS = $(APP_MAIN_SOURCES:%.c=$(OBJDIR)/%.o)
+APP_MAIN_DEPS = $(APP_MAIN_OBJS:%.o=%.d)
+
+APP_SOURCES = $(filter-out $(APP_MAIN_SOURCES),$(shell find $(SRCDIR) -name "*.c"))
APP_OBJS = $(APP_SOURCES:%.c=$(OBJDIR)/%.o)
APP_DEPS = $(APP_OBJS:%.o=%.d)
--include $(APP_DEPS)
+TST_SOURCES = $(shell find $(TSTDIR) -name "*.c")
+TST_OBJS = $(TST_SOURCES:%.c=$(OBJDIR)/%.o)
+TST_DEPS = $(TST_OBJS:%.o=%.d)
+TST_APPS = $(TST_SOURCES:%.c=$(OBJDIR)/%)
+
+-include $(APP_DEPS) $(APP_MAIN_DEPS) $(TST_DEPS)
# We don't really need to run the tests for bear to record them
compile_commands.json: clean Makefile $(APP_SOURCES)
@rm -f "$@"
bear -- make main
-main: $(APP_OBJS)
- $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(APP_OBJS) $(LIBS)
+main: $(APP_MAIN_OBJS) $(APP_OBJS)
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(APP_MAIN_OBJS) $(APP_OBJS) $(LIBS)
$(OBJDIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INCS) -MMD -o $@ -c $<
+$(OBJDIR)/test/%: $(OBJDIR)/test/%.o $(APP_OBJS)
+ @mkdir -p $(dir $@)
+ $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(APP_OBJS) $(LIBS)
+
clean:
@rm -rf $(OBJDIR)
@rm -f main