summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: a4ad567d886adbaf795cca7c37e15dc24c316f4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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