aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2024-11-15 13:12:29 +0800
committerMistivia <i@mistivia.com>2024-11-15 13:12:29 +0800
commitbbe08c2ed46a54bf3d16ac2b7f6ead26fc6f3239 (patch)
treefa751afe6a36d30477b2b01b160b3c79300d776b /Makefile
init
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile38
1 files changed, 38 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4095f31
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+target = foo
+cflags = -g
+ldflags = -lm
+cc = gcc
+
+src = $(shell find src/ -name '*.c' -not -name 'main.c')
+obj = $(src:.c=.o)
+tests=$(shell find tests/ -name '*.c')
+tests_bin=$(tests:.c=.bin)
+
+all: $(target)
+
+$(target): $(obj) src/main.o
+ $(cc) $(cflags) $(ldflags) -o $@ $^
+
+test: $(tests_bin)
+ @echo
+ @echo "Run tests:"
+ @scripts/runall.sh $^
+
+$(obj):%.o:%.c
+ $(cc) -c $(cflags) $< -MD -MF $@.d -o $@
+
+src/main.o:src/main.c
+ $(cc) -c $(cflags) $< -MD -MF $@.d -o $@
+
+$(tests_bin):%.bin:%.c $(obj)
+ $(cc) -Isrc/ $(cflags) $(ldflags) $< $(obj) -MD -MF $@.d -o $@
+
+clean:
+ -rm $(shell find tests/ -name '*.bin')
+ -rm $(shell find . -name '*.o' -or -name '*.d')
+ -rm $(target)
+
+DEPS := $(shell find . -name *.d)
+ifneq ($(DEPS),)
+include $(DEPS)
+endif