summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2022-11-02 22:20:04 +0100
committerAlbert Cervin <albert@acervin.com>2022-11-16 23:33:49 +0100
commit2f4cb88d5c60f725323739300bb49dfa8923e7d5 (patch)
tree6ec22c2be92eff05f18e5919e747faab56e555ad /Makefile
downloaddged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.gz
dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.xz
dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.zip
🎉 And so it begins
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile50
1 files changed, 50 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..dfc2a3c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,50 @@
+.PHONY: default clean check run debug debug-tests
+
+default: dged
+
+headers != find src/ -type f -name '*.h'
+srcs != find src/ -type f -name '*.c' ! -name 'main.c'
+
+test_headers != find test/ -type f -name '*.h'
+test_srcs != find test/ -type f -name '*.c'
+
+objs-path = objs
+objs = $(patsubst %.c,$(objs-path)/%.o, $(srcs))
+test_objs = $(patsubst %.c,$(objs-path)/test/%.o, $(test_srcs))
+
+UNAME_S != uname -s
+
+CFLAGS = -Werror -g -std=c99
+
+ifeq ($(UNAME_S),Linux)
+ DEFINES += -DLINUX
+endif
+
+$(objs-path)/test/%.o: %.c $(headers)
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(DEFINES) -I ./src -I ./test -c $< -o $@
+
+$(objs-path)/%.o: %.c $(headers)
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(DEFINES) -I ./src -c $< -o $@
+
+dged: $(objs) $(objs-path)/src/main.o
+ $(CC) $(LDFLAGS) $(objs) $(objs-path)/src/main.o -o dged
+
+run-tests: $(test_objs) $(objs)
+ $(CC) $(LDFLAGS) $(test_objs) $(objs) -o run-tests
+
+check: run-tests
+ ./run-tests
+
+run: dged
+ ./dged
+
+debug: dged
+ gdb ./dged
+
+debug-tests: run-tests
+ gdb ./run-tests
+
+clean:
+ rm -rf $(objs-path) dged run-tests