aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
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..d20a7d3
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+CC=gcc
+CFLAGS=-std=c17 -Wall -Werror -g
+TESTFW=criterion
+
+# Directories
+BIN=bin
+OBJ=obj
+SRC=src
+TEST=tests
+
+# Files
+OBJS=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(wildcard $(SRC)/*.c))
+TESTBINS=$(patsubst $(TEST)/%.c, $(BIN)/%, $(wildcard $(TEST)/*.c))
+
+all: test
+
+# Target Directories
+$(OBJ):
+ mkdir $@
+
+$(BIN):
+ mkdir $@
+
+# Target Files
+$(OBJ)/%.o: $(SRC)/%.c $(OBJ)
+ $(CC) $(CFLAGS) -o $@ -c $<
+
+$(BIN)/%: $(BIN) $(TEST)/%.c $(OBJS)
+ $(CC) $(CFLAGS) -o $@ -l $(TESTFW) $(filter-out $<,$^)
+
+# Actions
+.PHONY: test
+test: $(TESTBINS)
+ for test in $(TESTBINS); do ./$$test --verbose; done
+
+.PHONY: clean
+clean:
+ rm -r $(BIN) $(OBJ)