-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
231 lines (167 loc) · 6.08 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#-------------------------------------------------------------------------
# Copyright 2016, Daan Leijen.
#-------------------------------------------------------------------------
.PHONY : clean dist init tests staticlib main
include out/makefile.config
ifndef $(VARIANT)
VARIANT=debug
endif
CONFIGDIR = out/$(CONFIG)
OUTDIR = $(CONFIGDIR)/$(VARIANT)
INCLUDES = -Iinc -I$(CONFIGDIR)
ifeq ($(VARIANT),release)
CCFLAGS = $(CCFLAGSOPT) -DNDEBUG $(INCLUDES)
CXXFLAGS = $(CXXFLAGSOPT) -DNDEBUG $(INCLUDES)
else ifeq ($(VARIANT),testopt)
CCFLAGS = $(CCFLAGSOPT) $(INCLUDES)
CXXFLAGS = $(CXXFLAGSOPT) $(INCLUDES)
else ifeq ($(VARIANT),debug)
CCFLAGS = $(CCFLAGSDEBUG) $(INCLUDES)
CXXFLAGS = $(CXXFLAGSDEBUG) $(INCLUDES)
else
VARIANTUNKNOWN=1
endif
# Use VALGRIND=1 to memory check under valgrind
ifeq ($(VALGRIND),1)
VALGRINDX=yes
else ifeq ($(VALGRIND),yes)
VALGRINDX=yes
else
VALGRINDX=
endif
ifeq ($(VALGRINDX),yes)
VALGRINDX=valgrind --leak-check=full --show-leak-kinds=all --suppressions=./valgrind.supp
endif
# Uncomment to generate assembly for libhandler
# SHOWASM = -Wa,-aln=$@.s
# -------------------------------------
# Sources
# -------------------------------------
SRCFILES = libhandler.c exception.c
CTESTS = tests.c \
test-exn.c test-state.c test-amb.c test-dynamic.c test-raise.c test-general.c \
test-tailops.c test-state-alloc.c test-yieldn.c test-excn.c
TESTFILES= main-tests.c $(CTESTS)
BENCHFILES=main-perf.c perf.c tests.c test-state.c \
perf-counter.c
SRCS = $(patsubst %,src/%,$(SRCFILES)) $(patsubst %,src/%,$(ASMFILES))
OBJS = $(patsubst %.c,$(OUTDIR)/%$(OBJ), $(SRCFILES)) $(patsubst %$(ASM),$(OUTDIR)/%$(OBJ),$(ASMFILES))
HLIB = $(OUTDIR)/libhandler$(LIB)
TESTSRCS = $(patsubst %,test/%,$(TESTFILES))
TESTMAIN = $(OUTDIR)/libh-tests$(EXE)
BENCHSRCS= $(patsubst %,test/%,$(BENCHFILES))
BENCHMAIN= $(OUTDIR)/libh-bench$(EXE)
TESTFILESXX=main-tests.cpp \
test-destructor.cpp test-try.cpp \
$(CTESTS)
OUTDIRXX = $(OUTDIR)xx
SRCSXX = $(patsubst %,src/%,$(SRCFILES)) $(patsubst %,src/%,$(ASMFILES))
OBJSXX = $(patsubst %.c,$(OUTDIRXX)/%$(OBJ), $(SRCFILES)) $(patsubst %$(ASM),$(OUTDIRXX)/%$(OBJ),$(ASMFILES))
HLIBXX =$(OUTDIRXX)/libhandler++$(LIB)
TESTSRCSXX = $(patsubst %,test/%,$(TESTFILESXX))
TESTMAINXX = $(OUTDIRXX)/libh-tests++$(EXE)
# -------------------------------------
# Main targets
# -------------------------------------
main: init staticlib
tests: init staticlib testmain
@echo ""
@echo "run tests"
$(VALGRINDX) $(TESTMAIN)
bench: init staticlib benchmain
@echo ""
@echo "run benchmark"
$(BENCHMAIN)
mainxx: initxx staticlibxx
testsxx: initxx staticlibxx testmainxx
@echo ""
@echo "run tests++"
$(VALGRINDX) $(TESTMAINXX)
# -------------------------------------
# build tests
# -------------------------------------
testmain: $(TESTMAIN)
$(TESTMAIN): $(TESTSRCS) $(HLIB)
$(CC) $(CCFLAGS) $(LINKFLAGOUT)$@ $(TESTSRCS) $(HLIB)
testmainxx: $(TESTMAINXX)
$(TESTMAINXX): $(TESTSRCSXX) $(HLIBXX)
$(CXX) $(CXXFLAGS) $(LINKFLAGOUT)$@ $(TESTSRCSXX) $(HLIBXX)
# -------------------------------------
# build benchmark
# -------------------------------------
benchmain: $(BENCHMAIN)
$(BENCHMAIN): $(BENCHSRCS) $(HLIB)
$(CC) $(CCFLAGS) $(LINKFLAGOUT)$@ $(BENCHSRCS) $(HLIB) -lm
benchmainxx: $(BENCHMAINXX)
$(BENCHMAINXX): $(BENCHSRCSXX) $(HLIBXX)
$(CXX) $(CXXFLAGS) $(LINKFLAGOUT)$@ $(BENCHSRCSXX) $(HLIBXX)
# -------------------------------------
# build the static library
# -------------------------------------
staticlib: initxx $(HLIB)
$(HLIB): $(OBJS)
$(AR) $(ARFLAGS) $(ARFLAGOUT)$@ $(OBJS)
$(OUTDIR)/%$(OBJ): src/%.c
$(CC) $(CCFLAGS) $(CCFLAG99) $(CCFLAGOUT)$@ -c $< $(SHOWASM)
$(OUTDIR)/%$(OBJ): src/%$(ASM)
$(CC) $(ASMFLAGS) $(ASMFLAGOUT)$@ -c $<
staticlibxx: $(HLIBXX)
$(HLIBXX): $(OBJSXX)
$(AR) $(ARFLAGS) $(ARFLAGOUT)$@ $(OBJSXX)
$(OUTDIRXX)/%$(OBJ): src/%.cpp
$(CXX) $(CXXFLAGS) $(CCFLAGOUT)$@ -c $<
$(OUTDIRXX)/%$(OBJ): src/%.c
$(CXX) $(CXXFLAGS) $(CCFLAGOUT)$@ -c $< $(SHOWASM)
$(OUTDIRXX)/%$(OBJ): src/%$(ASM)
$(CXX) $(ASMFLAGS) $(ASMFLAGOUT)$@ -c $<
# -------------------------------------
# other targets
# -------------------------------------
docs:
clean:
rm -rf $(CONFIGDIR)/*/*
touch $(CONFIGDIR)/makefile.depend
init:
@echo "use 'make help' for help"
@echo "build variant: $(VARIANT), configuration: $(CONFIG)"
@if test "$(VARIANTUNKNOWN)" = "1"; then echo ""; echo "Error: unknown build variant: $(VARIANT)"; echo "Use one of 'debug', 'release', or 'testopt'"; false; fi
@if test -d "$(OUTDIR)/asm"; then :; else $(MKDIR) "$(OUTDIR)/asm"; fi
initxx: init
@if test -d "$(OUTDIRXX)/asm"; then :; else $(MKDIR) "$(OUTDIRXX)/asm"; fi
help:
@echo "Usage: make <target>"
@echo "Or : make VARIANT=<variant> <target>"
@echo "Or : make VALGRIND=1 tests"
@echo ""
@echo "Variants:"
@echo " debug : Build a debug version (default)"
@echo " testopt : Build an optimized version but with assertions"
@echo " release : Build an optimized release version"
@echo ""
@echo "Targets:"
@echo " main : Build a static library (default)"
@echo " tests : Run tests"
@echo " mainxx : Build a static library for C++"
@echo " testsxx : Run tests for C++"
@echo " bench : Run benchmarks, use 'VARIANT=release'"
@echo " clean : Clean output directory"
@echo " depend : Generate dependencies"
@echo ""
@echo "Configuration:"
@echo " output dir : $(OUTDIR)"
@echo " c-compiler : $(CC) $(CCFLAGS)"
@echo ""
# dependencies
# [gcc -MM] generates the dependencies without the full
# directory name, ie.
# evaluator.o: ...
# instead of
# core/evaluator.o: ..
# we therefore use [sed] to append the directory name
depend: init
$(CCDEPEND) $(INCLUDES) src/*.c > $(CONFIGDIR)/temp.depend
sed -e "s|\(.*\.o\)|$(CONFIGDIR)/\$$(VARIANT)/\1|g" $(CONFIGDIR)/temp.depend > $(CONFIGDIR)/makefile.depend
$(CCDEPEND) $(INCLUDES) test/*.c > $(CONFIGDIR)/temp.depend
sed -e "s|\(.*\.o\)|$(CONFIGDIR)/\$$(VARIANT)/\1|g" $(CONFIGDIR)/temp.depend >> $(CONFIGDIR)/makefile.depend
$(RM) $(CONFIGDIR)/temp.depend
include $(CONFIGDIR)/makefile.depend