summary refs log tree commit diff
path: root/GNUmakefile
diff options
context:
space:
mode:
authorzlago2024-09-24 20:54:48 +0200
committerzlago2024-09-24 20:54:48 +0200
commitb23a3ab831f91553d34a48f51370ed9525de07ac (patch)
treebd4adf20ba92d17433f386c0b5347a8d8cc9045f /GNUmakefile
initial commit
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile47
1 files changed, 47 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..39fcc6d
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,47 @@
+#!/usr/bin/env -S gmake -f
+
+export MKDIR ?= mkdir -p
+
+libs := SDL2 z
+
+CFLAGS ?= -Wall -Wpedantic -g -Og
+cflags := -I lib/ -I . ${CFLAGS}
+ldflags := $(addprefix -l,${libs}) ${LDFLAGS}
+
+srcs := $(wildcard src/*.c)
+objs := $(addprefix out/${NS}/,$(notdir ${srcs:.c=.o}))
+deps := $(addprefix out/${NS}/,$(notdir $(patsubst %.c,%.d,$(wildcard src/*.c))))
+
+.PHONY: all run clean lib
+
+all: out/${NS}/a.out
+
+run: out/${NS}/a.out
+	./$<
+
+clean:
+	${RM} -r out/${NS}/
+#	${MAKE} -C lib clean
+
+#lib:
+#	${MAKE} -C $@
+
+out/${NS}/:
+	${MKDIR} $@
+
+out/:
+	${MKDIR} $@
+
+out/${NS}/%.o: src/%.c out/${NS}/%.d | out/${NS}/
+	${CC} -c -o $@ $< ${cflags}
+
+out/${NS}/%.d: src/%.c | out/${NS}/
+	${CC} ${cflags} ${CPPFLAGS} -MM -MG -MF $@ -MT "${@:.d=.o} $@" $<
+
+out/${NS}/a.out: ${objs} | out/${NS}/ #lib
+	${CC} -o $@ $^ $(wildcard lib/out/*.o) ${cflags} ${ldflags}
+
+out/%: utl/%.c | out/${NS}/
+	${CC} -g -Og -o $@ $^ # i have no idea how im supposed to handle CFLAGS
+
+include ${deps}