summary refs log tree commit diff
path: root/GNUmakefile
blob: 39fcc6de59d080b9abae2b54457dbce4352c0ac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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}