-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
269 lines (219 loc) · 7.01 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
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
#
# Top-level makefile for specpaxos
#
CC = gcc
CXX = g++
LD = g++
EXPAND = lib/tmpl/expand
CFLAGS := -g -Wall -pthread -iquote.obj/gen -Wno-uninitialized -O3
CXXFLAGS := -std=c++0x -O3
LDFLAGS := -levent_pthreads -ldl
LIBPATH := -I./
CFLAGS += $(LIBPATH)
## Debian package: check
# CHECK_CFLAGS := $(shell pkg-config --cflags check)
# CHECK_LDFLAGS := $(shell pkg-config --cflags --libs check)
# Debian package: libprotobuf-dev
PROTOBUF_CFLAGS := $(shell pkg-config --cflags protobuf)
PROTOBUF_LDFLAGS := $(shell pkg-config --cflags --libs protobuf)
CFLAGS += $(PROTOBUF_CFLAGS)
LDFLAGS += $(PROTOBUF_LDFLAGS)
PROTOC := protoc
# Debian package: libevent-dev
LIBEVENT_CFLAGS := $(shell pkg-config --cflags libevent)
LIBEVENT_LDFLAGS := $(shell pkg-config --libs libevent)
CFLAGS += $(LIBEVENT_CFLAGS)
LDFLAGS += $(LIBEVENT_LDFLAGS)
# Debian packages: libssl-dev libcrypto-dev
LIBSSL_CFLAGS := $(shell pkg-config --cflags libssl) $(shell pkg-config --cflags libcrypto)
LIBSSL_LDFLAGS := $(shell pkg-config --libs libssl) $(shell pkg-config --libs libcrypto)
CFLAGS += $(LIBSSL_CFLAGS)
LDFLAGS += $(LIBSSL_LDFLAGS)
# Debian package: libunwind-dev
# XXX Some versions of Ubuntu don't seem to have pkg-config files
# installed for libunwind, so specify manually.
LIBUNWIND_CFLAGS :=
LIBUNWIND_LDFLAGS := -lunwind
#LIBUNWIND_CFLAGS := $(shell pkg-config --cflags libunwind)
#LIBUNWIND_LDFLAGS := $(shell pkg-config --libs libunwind)
CFLAGS += $(LIBUNWIND_CFLAGS)
LDFLAGS += $(LIBUNWIND_LDFLAGS)
# Google test framework. This doesn't use pkgconfig
GTEST_DIR := /usr/src/gtest
# Additional flags
PARANOID = 0
ifneq ($(PARANOID),0)
override CFLAGS += -DPARANOID=1
$(info WARNING: Paranoid mode enabled)
endif
PERFTOOLS = 0
ifneq ($(PERFTOOLS),0)
override CFLAGS += -DPPROF=1
override LDFLAGS += -lprofiler
endif
# Make sure all is the default
.DEFAULT_GOAL := all
# Eliminate default suffix rules
.SUFFIXES:
# Delete target files if there is an error (or make is interrupted)
.DELETE_ON_ERROR:
# make it so that no intermediate .o files are ever deleted
.PRECIOUS: %.o
##################################################################
# Tracing
#
ifeq ($(V),1)
trace = $(3)
Q =
else
trace = @printf "+ %-6s " $(1) ; echo $(2) ; $(3)
Q = @
endif
GTEST := .obj/gtest/gtest.a
GTEST_MAIN := .obj/gtest/gtest_main.a
##################################################################
# Sub-directories
#
# The directory of the current make fragment. Each file should
# redefine this at the very top with
# d := $(dir $(lastword $(MAKEFILE_LIST)))
d :=
# The object directory corresponding to the $(d)
o = .obj/$(d)
# SRCS is the list of all non-test-related source files.
SRCS :=
# TEST_SRCS is just like SRCS, but these source files will be compiled
# with testing related flags.
TEST_SRCS :=
# GTEST_SRCS is tests that use Google's testing framework
GTEST_SRCS :=
# PROTOS is the list of protobuf *.proto files
PROTOS :=
# BINS is a list of target names for non-test binaries. These targets
# should depend on the appropriate object files, but should not
# contain any commands.
BINS :=
# TEST_BINS is like BINS, but for test binaries. They will be linked
# using the appropriate flags. This is also used as the list of tests
# to run for the `test' target.
TEST_BINS :=
# add-CFLAGS is a utility macro that takes a space-separated list of
# sources and a set of CFLAGS. It sets the CFLAGS for each provided
# source. This should be used like
#
# $(call add-CFLAGS,$(d)a.c $(d)b.c,$(PG_CFLAGS))
define add-CFLAGS
$(foreach src,$(1),$(eval CFLAGS-$(src) += $(2)))
endef
# Like add-CFLAGS, but for LDFLAGS. This should be given a list of
# binaries.
define add-LDFLAGS
$(foreach bin,$(1),$(eval LDFLAGS-$(bin) += $(2)))
endef
include lib/Rules.mk
include common/Rules.mk
include unreplicated/Rules.mk
include vr/Rules.mk
include fastpaxos/Rules.mk
include nopaxos/Rules.mk
include bench/Rules.mk
include store/Rules.mk
include sequencer/Rules.mk
##################################################################
# General rules
#
#
# Protocols
#
PROTOOBJS := $(PROTOS:%.proto=.obj/%.o)
PROTOSRCS := $(PROTOS:%.proto=.obj/gen/%.pb.cc)
PROTOHEADERS := $(PROTOS:%.proto=%.pb.h)
$(PROTOSRCS) : .obj/gen/%.pb.cc: %.proto
@mkdir -p .obj/gen
$(call trace,PROTOC,$^,$(PROTOC) --cpp_out=.obj/gen $^)
#
# Compilation
#
# -MD Enable dependency generation and compilation and output to the
# .obj directory. -MP Add phony targets so make doesn't complain if
# a header file is removed. -MT Explicitly set the target in the
# generated rule to the object file we're generating.
DEPFLAGS = -M -MF ${@:.o=.d} -MP -MT $@ -MG
# $(call add-CFLAGS,$(TEST_SRCS),$(CHECK_CFLAGS))
OBJS := $(SRCS:%.cc=.obj/%.o) $(TEST_SRCS:%.cc=.obj/%.o) $(GTEST_SRCS:%.cc=.obj/%.o)
define compile
@mkdir -p $(dir $@)
$(call trace,$(1),$<,\
$(CC) -iquote. $(CFLAGS) $(CFLAGS-$<) $(2) $(DEPFLAGS) -E $<)
$(Q)$(CC) -iquote. $(CFLAGS) $(CFLAGS-$<) $(2) -E -o .obj/$*.t $<
$(Q)$(EXPAND) $(EXPANDARGS) -o .obj/$*.i .obj/$*.t
$(Q)$(CC) $(CFLAGS) $(CFLAGS-$<) $(2) -c -o $@ .obj/$*.i
endef
define compilecxx
@mkdir -p $(dir $@)
$(call trace,$(1),$<,\
$(CXX) -iquote. $(CFLAGS) $(CXXFLAGS) $(CFLAGS-$<) $(2) $(DEPFLAGS) -E $<)
$(Q)$(CXX) -iquote. $(CFLAGS) $(CXXFLAGS) $(CFLAGS-$<) $(2) -c -o $@ $<
endef
# All object files come in two flavors: regular and
# position-independent. PIC objects end in -pic.o instead of just .o.
# Link targets that build shared objects must depend on the -pic.o
# versions.
$(OBJS): .obj/%.o: %.cc $(PROTOSRCS)
$(call compilecxx,CC,)
$(OBJS:%.o=%-pic.o): .obj/%-pic.o: %.cc $(PROTOSRCS)
$(call compilecxx,CCPIC,-fPIC)
$(PROTOOBJS): .obj/%.o: .obj/gen/%.pb.cc
$(call compilecxx,CC,)
$(PROTOOBJS:%.o=%-pic.o): .obj/%-pic.o: .obj/gen/%.pb.cc $(PROTOSRCS)
$(call compilecxx,CCPIC,-fPIC)
#
# Linking
#
$(call add-LDFLAGS,$(TEST_BINS),$(CHECK_LDFLAGS))
$(BINS) $(TEST_BINS): %:
$(call trace,LD,$@,$(LD) -o $@ $^ $(LDFLAGS) $(LDFLAGS-$@))
#
# Automatic dependencies
#
DEPS := $(OBJS:.o=.d) $(OBJS:.o=-pic.d)
-include $(DEPS)
#
# Testing
#
GTEST_INTERNAL_SRCS := $(wildcard $(GTEST_DIR)/src/*.cc)
GTEST_OBJS := $(patsubst %.cc,.obj/gtest/%.o,$(notdir $(GTEST_INTERNAL_SRCS)))
$(GTEST_OBJS): .obj/gtest/%.o: $(GTEST_DIR)/src/%.cc
$(call compilecxx,CC,-I$(GTEST_DIR) -Wno-missing-field-initializers)
$(GTEST) : .obj/gtest/gtest-all.o
$(call trace,AR,$@,$(AR) $(ARFLAGS) $@ $^)
$(GTEST_MAIN) : .obj/gtest/gtest-all.o .obj/gtest/gtest_main.o
$(call trace,AR,$@,$(AR) $(ARFLAGS) $@ $^)
#
# Cleaning
#
.PHONY: clean
clean:
$(call trace,RM,binaries,rm -f $(BINS) $(TEST_BINS))
$(call trace,RM,objects,rm -rf .obj)
##################################################################
# Targets
#
.PHONY: all
all: $(BINS)
$(TEST_BINS:%=run-%): run-%: %
$(call trace,RUN,$<,$<)
$(TEST_BINS:%=gdb-%): gdb-%: %
$(call trace,GDB,$<,CK_FORK=no gdb $<)
.PHONY: test
test: $(TEST_BINS:%=run-%)
.PHONY: check
check: test
.PHONY: TAGS
TAGS:
$(Q)rm -f $@
$(call trace,ETAGS,sources,\
etags $(SRCS) $(TEST_SRCS))
$(call trace,ETAGS,headers,\
etags -a $(foreach dir,$(sort $(dir $(SRCS) $(TEST_SRCS))),\
$(wildcard $(dir)*.h)))