-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (62 loc) · 1.94 KB
/
Makefile
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
LEX = flex -d --warn
YACC = bison -d -v --graph
# --graph --
CC = gcc
LD = gcc
CFLAGS = -Wall -Wextra -g -Iinclude/ -Isrc/ -fno-stack-protector
LDFLAGS = -L./lib -I./include -lm
EXEC = bin/main
SRC=$(shell find src/ -type f -name '*.c') src/grammar.l.c src/grammar.y.c
OBJ=$(patsubst src/%.c,obj/%.o,$(SRC))
DIRS=$(patsubst src/%,obj/%,$(shell find src/ -type d)) bin/tests obj/tests
TESTS=$(wildcard tests/*.c)
TEST_BINS=$(patsubst tests/%.c,bin/tests/%,$(TESTS))
DISPLAY_IMAGE=$(shell which viewnior 2>/dev/null || which eog 2>/dev/null || which feh 2>/dev/null || which display 2>/dev/null || which tycat 2> /dev/null)
all: $(DIRS) $(SRC) $(EXEC)
$(EXEC): $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LFLAGS)
obj/%.o: src/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $^ -o $@
src/%.y.c: src/%.y
$(YACC) --defines=$(patsubst %.c,%.h,$@) -o $@ $^
src/%.l.c: src/%.l
$(LEX) -o $@ $^
tests: $(DIRS) $(TEST_BINS)
@for t in $(TEST_BINS) ; do \
if ! $$t ; then \
echo "Failure at test $$t" ; \
fi ; \
done
bin/tests/%: obj/tests/%.o $(filter-out obj/main.o,$(OBJ))
$(CC) -o $@ $^ $(LDFLAGS) $(EXTRA_LFLAGS)
obj/tests/%.o: tests/%.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $^ -o $@
$(DIRS): %:
mkdir -p $@
display_ast: all
dot -Tpng out.dot > /tmp/ast.png
$(DISPLAY_IMAGE) /tmp/ast.png
display_grammar: all
dot -Tpng src/grammar.y.dot > /tmp/grm.png
$(DISPLAY_IMAGE) /tmp/grm.png
graphs:
mkdir -p graphs
scripts/gprof2dot.py:
mkdir -p scripts
wget https://raw.githubusercontent.com/jrfonseca/gprof2dot/master/gprof2dot.py -O $@
chmod u x $@
profile: EXTRA_CFLAGS=-pg
profile: EXTRA_LFLAGS=-pg
profile: scripts/gprof2dot.py graphs clean all
bin/main < fpsrc/func.fp
echo -e "\n\n"
gprof bin/main | scripts/gprof2dot.py | dot -Tpng -o graphs/profile-graph.png
$(DISPLAY_IMAGE) graphs/profile-graph.png
memckeck:
valgrind --leak-check=full bin/main < fpsrc/func.fp
clean:
rm -rf obj/
rm -rf bin/
rm -f src/*.l.c
rm -f src/*.y.*
.PHONY: all tests clean