summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-06-09 01:17:41 +0400
committerEthan Werner <mail@ethanwerner.com>2026-06-09 01:17:41 +0400
commit96ecf29e8be977f51f351308ef2c7c492bb829aa (patch)
treec664aa61262e6f7627a732f0e4fbb84281b99952 /Makefile
parentf6a144987cc403de8ad6bddd055f756120f8d405 (diff)
refactor
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile63
1 files changed, 63 insertions, 0 deletions
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