From 96ecf29e8be977f51f351308ef2c7c492bb829aa Mon Sep 17 00:00:00 2001 From: Ethan Werner Date: Tue, 9 Jun 2026 01:17:41 +0400 Subject: refactor --- Makefile | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Makefile (limited to 'Makefile') diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a4ad567 --- /dev/null +++ b/Makefile @@ -0,0 +1,63 @@ +CC = gcc +CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99 -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wformat-security -Wnull-dereference -I include +LDFLAGS = -lm + +CFLAGS_DEBUG = -Wall -Wextra -Werror -pedantic -std=c99 -g -O0 -fstack-protector-strong -Wformat-security -Wnull-dereference -I include +LDFLAGS_DEBUG = $(LDFLAGS) + +EXAMPLES = ann_xor buffer bin direct escape genetic_ann genetic_char \ + genetic_pushdown_btc pool pushdown stack ufo + +TESTS = test_stack test_pool test_buffer test_bin test_pushdown \ + test_escape test_direct test_ann test_genetic test_flat \ + test_uri test_ufo test_interpolate + +EXAMPLE_BINS = $(addprefix bin/, $(EXAMPLES)) +TEST_BINS = $(addprefix tests/, $(TESTS)) + +.PHONY: all clean examples tests run run-tests debug debug-tests valgrind-tests + +all: examples tests + +examples: $(EXAMPLE_BINS) + +tests: $(TEST_BINS) + +$(EXAMPLE_BINS): bin/%: example/%.c + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +$(TEST_BINS): tests/%: tests/%.c + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +debug: + $(MAKE) examples CFLAGS="$(CFLAGS_DEBUG)" LDFLAGS="$(LDFLAGS_DEBUG)" + +debug-tests: + $(MAKE) tests CFLAGS="$(CFLAGS_DEBUG)" LDFLAGS="$(LDFLAGS_DEBUG)" + +valgrind-tests: debug-tests + @fail=0; \ + for t in $(TEST_BINS); do \ + echo ">>> $$t"; valgrind --error-exitcode=1 ./$$t; \ + if [ $$? -ne 0 ]; then fail=1; fi; \ + echo; \ + done; \ + if [ $$fail -ne 0 ]; then echo "SOME TESTS FAILED"; exit 1; \ + else echo "ALL TESTS PASSED"; fi + +clean: + rm -f $(EXAMPLE_BINS) $(TEST_BINS) + +run: examples + @for ex in $(EXAMPLE_BINS); do \ + echo ">>> $$ex"; ./$$ex; echo; done + +run-tests: tests + @fail=0; \ + for t in $(TEST_BINS); do \ + echo ">>> $$t"; ./$$t; \ + if [ $$? -ne 0 ]; then fail=1; fi; \ + echo; \ + done; \ + if [ $$fail -ne 0 ]; then echo "SOME TESTS FAILED"; exit 1; \ + else echo "ALL TESTS PASSED"; fi -- cgit v1.3.1