From 45c1fbf4dfe5c7a7243b625eb8a600bdce6c748f Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Wed, 18 Sep 2024 00:32:53 +0100 Subject: Add makefile & tests --- Makefile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Makefile (limited to 'Makefile') 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) -- cgit