-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
147 lines (119 loc) · 5.19 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
########################################################################
### S E T U P
########################################################################
UNAME := $(shell uname)
DEPS_DEBUG = libprofiler
CFLAGS = -O2
CFLAGS_DEBUG = -DDEBUG -DPROG='"volta (debugmode)"' -ggdb -ansi -Wall
LIBS = -lcdb
OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
.PHONY : parsegraph profile clean clobber release
########################################################################
### P L A T F O R M T A R G E T S
########################################################################
# I hate this. Tools like pkg-config are supposed to make finding
# libraries easy across platforms. They only work when everyone names
# the libraries the same thing, unfortunately. (Why name the libs with
# the version number, when pkg-config supports built in versioning??)
# And no, I'm not going to use autoconf, which just takes your build
# problems and makes a whole bunch of new baby problems for you to
# deal with. Gaaarrgghghh.
#
# If you have problems building volta, manually pass the correct CFLAGS
# and LIBS to the 'make' command line for your platform.
#
# The following works for OSX with macports or homebrew (10.6/10.7),
# FreeBSD 8.x through 10.x, and Ubuntu 11.10 through 14.04.
# Ubuntu
# - perftools doesn't currently register a .pc file at all
# - lua is called 'lua5.2'
ifeq ($(UNAME), Linux)
volta: CFLAGS += -L/usr/lib -I/usr/include
volta: CFLAGS += $(shell pkg-config --cflags-only-I --libs-only-L lua5.2)
volta: LIBS += $(shell pkg-config --libs-only-l lua5.2)
debug: CFLAGS += $(CFLAGS_DEBUG)\
$(shell pkg-config --cflags-only-I --libs-only-L lua5.2)
debug: LIBS += $(shell pkg-config --libs-only-l lua5.2) -lprofiler
# FreeBSD
# - lua is called 'lua-5.2'
else ifeq ($(UNAME), FreeBSD)
volta: CFLAGS += -L/usr/local/lib -I/usr/local/include
volta: CFLAGS += $(shell pkg-config --cflags-only-I --libs-only-L lua-5.2)
volta: LIBS += $(shell pkg-config --libs-only-l lua-5.2)
debug: CFLAGS += $(CFLAGS_DEBUG)\
$(shell pkg-config --cflags-only-I --libs-only-L lua-5.2 $(DEPS_DEBUG))
debug: LIBS += $(shell pkg-config --libs-only-l lua-5.2 $(DEPS_DEBUG))
# Darwin, everyone else (best guess?)
# - lua is called 'lua', hopefully!
else
volta: CFLAGS += $(shell pkg-config --cflags-only-I --libs-only-L lua)
volta: LIBS += $(shell pkg-config --libs-only-l lua)
debug: CFLAGS += $(CFLAGS_DEBUG)\
$(shell pkg-config --cflags-only-I --libs-only-L lua $(DEPS_DEBUG))
debug: LIBS += $(shell pkg-config --libs-only-l lua $(DEPS_DEBUG))
endif
# Fix parser line number display in debug mode
ifeq (,$(findstring debug,$(MAKECMDGOALS)))
RAGEL_FLAGS = -LCe -G2
else
RAGEL_FLAGS = -Ces -G2
endif
# Ensure the parser is included in the objs list
# (patsubst wouldn't have found it if parser.c wasn't pre-generated.)
ifneq (parser.o,$(findstring parser.o,$(OBJS)))
OBJS += parser.o
endif
########################################################################
### B U I L D
########################################################################
volta: $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
strip $@
$(OBJS): volta.h
db.o: db.h
# don't actually depend on parser.rl, so distributions don't require ragel
parser.c:
ragel $(RAGEL_FLAGS) parser.rl -o $@
debug: $(OBJS)
$(CC) $(CFLAGS) -o volta $(OBJS) $(LIBS)
########################################################################
### U T I L
########################################################################
parsegraph: \
request_graph.xml request_graph.pdf request_graph.dot \
rule_graph.xml rule_graph.pdf rule_graph.dot \
dbinput_graph.xml dbinput_graph.pdf dbinput_graph.dot \
tld_graph.xml tld_graph.pdf tld_graph.dot
request_graph.xml request_graph.pdf request_graph.dot \
rule_graph.xml rule_graph.pdf rule_graph.dot \
dbinput_graph.xml dbinput_graph.pdf dbinput_graph.dot \
tld_graph.xml tld_graph.pdf tld_graph.dot: parser.rl
ragel -Vp -S request_parser parser.rl > request_graph.dot
ragel -Vp -S rule_parser parser.rl > rule_graph.dot
ragel -Vp -S dbinput_parser parser.rl > dbinput_graph.dot
ragel -Vp -S tld_parser parser.rl > tld_graph.dot
ragel $(RAGEL_FLAGS) -S request_parser -x parser.rl -o request_graph.xml
ragel $(RAGEL_FLAGS) -S rule_parser -x parser.rl -o rule_graph.xml
ragel $(RAGEL_FLAGS) -S dbinput_parser -x parser.rl -o dbinput_graph.xml
ragel $(RAGEL_FLAGS) -S tld_parser -x parser.rl -o tld_graph.xml
dot -Tpdf request_graph.dot > request_graph.pdf
dot -Tpdf rule_graph.dot > rule_graph.pdf
dot -Tpdf dbinput_graph.dot > dbinput_graph.pdf
dot -Tpdf tld_graph.dot > tld_graph.pdf
# export CPUPROFILE="cpu.prof" before running volta for cpu profiling
# export CPUPROFILE_FREQUENCY=100 (default)
profile:
pprof --dot ./volta $(CPUPROFILE) | dot -Tpng > $(CPUPROFILE).png
pprof --text ./volta $(CPUPROFILE)
tags:
ctags *.h *.c
clobber: clean
rm -f parser.c volta.db ChangeLog tags
clean:
-rm -f volta *_graph.* *.o *.prof*
# requires BSD tar
release: VERSION = $(shell hg id -t | awk '{ print $$1 }')
release: clobber parser.c
hg log --style changelog > ChangeLog
tar -C .. --exclude misc --exclude .\* --exclude \*.rl -s '/^volta/volta-$(VERSION)/' -czvf /tmp/volta-$(VERSION).tgz volta
mv /tmp/volta-$(VERSION).tgz .