forked from hyrise/hyrise-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.mk
283 lines (229 loc) · 7.18 KB
/
rules.mk
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
ifndef RULES_MK
RULES_MK := defined
RUNDIR := $(shell pwd)
ifndef TOP
TOP := $(shell \
top=$(RUNDIR); \
while [ ! -r "$$top/.top" ] && [ "$$top" != "" ]; do \
top=$${top%/*}; \
done; \
echo $$top)
endif
define uniq_
$(eval seen :=)
$(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))
${seen}
endef
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
uniq = $(strip $(call reverse,$(call uniq_,$(call reverse,$(1)))))
inherit = $(foreach _,$(addsuffix .$(2),$(1)),$(value $(_)))
define inherit_
$(1).$(2) := $$(call uniq, $$($(1).$(2)) $$(call inherit,$$($(1).deps),$(2)))
endef
INHERITABLES := deps LINK_DIRS INCLUDE_DIRS LIBS LDFLAGS CPPFLAGS CFLAGS CXXFLAGS OBJS EXT_LIBS
inherit_all = $(foreach _,$(INHERITABLES),$$(eval $$(call inherit_,$(1),use_$(_))))
ifdef build_debug
echo_cmd =
else
echo_cmd = @echo "$(subst $(PROJECT_ROOT)/,,$(1))";
endif
define library
# user replace-able
ifndef $(1).defined
$(1).deps ?=
$(1).cpps ?= $$(shell find $($(1)) -type f -name "*.cpp")
$(1).objs ?= $$($(1).cpps:%=$(OBJDIR)%.o)
$(1).lib ?= $(RESULT_DIR)/lib$$($(1).libname)_$(BLD).a
$(1).libs ?=
$(1).includes ?=
$(1).defined := is defined
$(1).LDFLAGS ?=
$(1).CPPFLAGS ?=
$(1).CFLAGS ?=
$(1).CXXFLAGS ?=
# rules
$$($(1).lib) : $$($(1).objs)
all += $$($(1).lib)
# inheriting information by first filling in our pieces...
$(1).use_deps := $$($(1).lib)
$(1).use_LIBS := $$($(1).libname)_$(BLD) $$($(1).libs)
$(1).use_EXT_LIBS := $$($(1).libs)
$(1).use_LINK_DIRS := $$(realpath $$(dir $$($(1).lib)))
$(1).use_INCLUDE_DIRS := $$($(1).includes)
$(1).use_LDFLAGS := $$($(1).LDFLAGS)
$(1).use_CPPFLAGS := $$($(1).CPPFLAGS)
$(1).use_CFLAGS := $$($(1).CFLAGS)
$(1).use_CXXFLAGS := $$($(1).CXXFLAGS)
$(1).use_OBJS := $$($(1).objs)
$$(eval $$(call inherit_all,$(1)))
$$($(1).objs) : INCLUDE_DIRS += $$($(1).use_INCLUDE_DIRS)
$$($(1).objs) : CPPFLAGS += $$($(1).use_CPPFLAGS)
$$($(1).objs) : CFLAGS += $$($(1).use_CFLAGS)
$$($(1).objs) : CXXFLAGS += $$($(1).use_CXXFLAGS)
$$($(1).objs) : LIB := $(1)
ifdef build_debug
$$(info loaded $(1) with deps $$($(1).deps))
endif
ifneq "$(MAKECMDGOALS)" "clean"
-include $$($(1).cpps:%=$$(OBJDIR)%.d)
endif
endif
endef
define binary
# user replace-able
ifndef $(1).defined
$(1).deps ?=
$(1).cpps ?= $$(wildcard $($(1))/*.cpp)
$(1).objs ?= $$($(1).cpps:%=$(OBJDIR)%.o)
$(1).binary ?= $(RESULT_DIR)/$($(1).binname)_$(BLD)
$(1).defined := is defined
$(1).libs ?=
# rules
$(1).use_OBJS := $$($(1).objs)
$$(eval $$(call inherit_all,$(1)))
$$($(1).binary) : $$($(1).objs) $$($(1).use_deps)
all: $$($(1).binary)
all += $$($(1).binary)
$$($(1).binary) : LDFLAGS += $$($(1).use_LDFLAGS)
$$($(1).binary) : LINK_DIRS += $$($(1).use_LINK_DIRS)
$$($(1).binary) : LIBS += $$($(1).use_LIBS) $$($(1).libs)
$$($(1).objs) : INCLUDE_DIRS += $$($(1).use_INCLUDE_DIRS)
$$($(1).objs) : CXXFLAGS += $$($(1).use_CXXFLAGS)
$$($(1).objs) : CFLAGS += $$($(1).use_CFLAGS)
$$($(1).objs) : CPPFLAGS += $$($(1).use_CPPFLAGS)
ifdef build_debug
$$(info loaded $(1) with deps $$($(1).deps))
endif
ifneq "$(MAKECMDGOALS)" "clean"
-include $$($(1).cpps:%=$$(OBJDIR)%.d)
endif
endif
endef
define full_link_binary
# user replace-able
ifndef $(1).defined
$(1).deps ?=
$(1).cpps ?= $$(wildcard $($(1))/*.cpp)
$(1).objs ?= $$($(1).cpps:%=$(OBJDIR)%.o)
$(1).binary ?= $(RESULT_DIR)/$($(1).binname)_$(BLD)
$(1).defined := is defined
$(1).libs ?=
# rules
$(1).use_OBJS := $$($(1).objs)
$$(eval $$(call inherit_all,$(1)))
$$($(1).binary) : $$($(1).use_OBJS)
all: $$($(1).binary)
all += $$($(1).binary)
$$($(1).binary) : LDFLAGS += $$($(1).use_LDFLAGS)
$$($(1).binary) : LINK_DIRS += $$($(1).use_LINK_DIRS)
$$($(1).binary) : LIBS += $$($(1).use_EXT_LIBS) $$($(1).libs)
$$($(1).objs) : INCLUDE_DIRS += $$($(1).use_INCLUDE_DIRS)
$$($(1).objs) : CXXFLAGS += $$($(1).use_CXXFLAGS)
$$($(1).objs) : CFLAGS += $$($(1).use_CFLAGS)
$$($(1).objs) : CPPFLAGS += $$($(1).use_CPPFLAGS)
ifdef build_debug
$$(info loaded $(1) with deps $$($(1).deps))
endif
ifneq "$(MAKECMDGOALS)" "clean"
-include $$($(1).cpps:%=$$(OBJDIR)%.d)
endif
endif
endef
define test-binary
$(eval $(call binary,$(1)))
test-tgts += test_$$($(1).binary)
.PHONY: test_$$($(1).binary)
test_$$($(1).binary): $$($(1).binary)
$$(TESTPREFIX) $$($(1).binary) $$(TESTPARAM)
endef
### PROJECT SPECIFIC STUFF ###
PROJECT_ROOT := $(TOP)
OSNAME := $(shell uname -s)
%.mk: makefiles/%.default.mk
@[ -e $@ ] || echo "Grabbing default $@"; cp $< $@
@touch $@
CFLAGS :=
CPPFLAGS :=
CXXFLAGS :=
COMMON_FLAGS :=
LDFLAGS :=
LIBS := log4cxx
LINK_DIRS :=
INCLUDE_DIRS :=
WITH_PAPI := $(shell if [ "`papi_avail 2>&1 | grep Yes | wc -l`" -ne "0" ]; then echo 1; else echo 0; fi)
WITH_MYSQL:= 1
include $(PROJECT_ROOT)/settings.mk
BLD ?= debug
COMPILER ?= g++48
PLUGINS += ccache
ifeq ($(WITH_COVERAGE),1)
PLUGINS += coverage
endif
ifeq ($(WITH_PROFILER),1)
PLUGINS += profiler
endif
ifeq ($(WITH_V8),1)
ifndef V8_BASE_DIRECTORY
$(error V8_BASE_DIRECTORY is not defined)
endif
endif
include $(PROJECT_ROOT)/makefiles/config.$(COMPILER).mk
include $(PLUGINS:%=$(PROJECT_ROOT)/mkplugins/%.mk)
RESULT_DIR := $(PROJECT_ROOT)/build
OBJDIR := $(PROJECT_ROOT)/.build/$(BLD)_$(OSNAME)
CPPFLAGS.debug += -DEXPENSIVE_ASSERTIONS
CPPFLAGS.release += -DEXPENSIVE_TESTS -DPRODUCTION -DNDEBUG
CFLAGS.debug +=
CFLAGS.release +=
LDFLAGS.debug +=
LDFLAGS.release +=
COMMON_FLAGS.debug += -O0
COMMON_FLAGS.release += -O3 -march=native
COMMON_FLAGS += -g -Wall -Wextra -Wno-attributes -Wno-unused-parameter -pthread $(COMMON_FLAGS.$(BLD))
CPPFLAGS += -MMD -pipe $(CPPFLAGS.$(BLD))
CFLAGS += $(COMMON_FLAGS) $(CFLAGS.$(BLD))
CXXFLAGS += -std=c++11 $(COMMON_FLAGS) $(CXXFLAGS.$(BLD))
LINK_DIRS += /usr/local/lib
# This should indeed be done by all the components themselves
INCLUDE_DIRS += $(PROJECT_ROOT)/src/lib
LDFLAGS += $(LDFLAGS.$(BLD))
.PHONY : all clean test ci_test ci_build ci_valgrind_test
.DEFAULT_GOAL := all
TESTPARAM = --minimal
test:
ci_test: TESTPARAM = --gtest_output=xml:$<.xml
ci_test: test
ci_valgrind_test: TESTPARAM =
ci_valgrind_test: TESTPREFIX = valgrind --leak-check=full --xml=yes --xml-file=$<.memcheck
ci_valgrind_test: test
include $(PROJECT_ROOT)/makefiles/ci.mk
ci_build: ci_steps
%/.fake:
@mkdir -p $(@D)
@touch $@
$(RESULT_DIR)/%.a:
$(call echo_cmd,AR $(AR) $@) $(AR) crs $@ $(filter %.o,$?)
$(RESULT_DIR)/%:
$(call echo_cmd,LINK $(CXX) $(BLD) $@) $(CXX) $(CXXFLAGS) -o $@ $(filter %.o,$^) -Wl,-whole-archive $(addprefix -l,$(LIBS)) -Wl,-no-whole-archive $(addprefix -L,$(LINK_DIRS)) $(LDFLAGS)
# Necessary to allow for a second expansion to create dirs
.SECONDEXPANSION:
test: $$(test-tgts)
all: $$(all)
@echo "$@ done for BLD='$(BLD)'"
clean:
rm -rf $(OBJDIR) $(all)
$(OBJDIR)%.cpp.o : %.cpp | $$(@D)/.fake
$(call echo_cmd,CXX $(CXX) $(BLD) $<) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(addprefix -I,$(INCLUDE_DIRS)) -c -o $@ $<
$(OBJDIR)%.c.o : %.c | $$(@D)/.fake
$(call echo_cmd,CC $(CC) $(BLD) $<) $(CC) $(CPPFLAGS) $(CFLAGS) $(addprefix -I,$(INCLUDE_DIRS)) -c -o $@ $<
# Ensure that intermediate files (e.g. the foo.o caused by "foo : foo.c")
# are not auto-deleted --- causing a re-compile every second "make".
.SECONDARY :
.SUFFIXES:
%. :;@echo '$($*)'
ifdef build_debug
$(info TOP is $(TOP))
$(info out of tree build dir $(OBJDIR))
$(info PROJECT_ROOT is $(PROJECT_ROOT))
endif
endif