-
Notifications
You must be signed in to change notification settings - Fork 16
/
makefile
208 lines (156 loc) · 6.75 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
#
# src/ root of sources for library
# test/ root of sources for tests
#
# bin/debug build files and binaries for debug builds
# bin/release build files and binaries for release builds
#
# tests are combined in a single binary w/ the types to run selected at
# compile-time, depending on DEBUG #define or overrides. Passing -DDEBUG will
# compile 'functional' tests; not doing so(or passing -DNDEBUG) will compile
# 'performance' tests. To override this behavior use the generic test
# targets(debug-test, release-test) and make w/ one of the following:
# CXXFLAGS=-DRUN_FUNCTIONAL_TESTS
# CXXFLAGS=-DRUN_PERFORMANCE_TESTS
# CXXFLAGS=-DRUN_ALL_TESTS
#
# targets:
# debug: debug build of library -> bin/debug
# release: release build of library -> bin/release
#
# functional-test: specialized debug build of tests -> bin/debug
# performance-test: specialized release build of tests -> bin/release
#
# debug-test: generic debug build of tests -> bin/debug
# release-test: generic release build of tests -> bin/release
#
#
PROJECT_ROOT = $(patsubst %/, %, $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
BUILD_DIR := $(PROJECT_ROOT)/bin
DEBUG_BUILD_DIR := $(BUILD_DIR)/debug
RELEASE_BUILD_DIR := $(BUILD_DIR)/release
# source file dirs for the main lib
SOB_LIB_SUBDIRS = src \
src/orderbook
DEBUG_SOB_LIB_SUBDIRS = $(addprefix $(DEBUG_BUILD_DIR)/, $(SOB_LIB_SUBDIRS))
RELEASE_SOB_LIB_SUBDIRS = $(addprefix $(RELEASE_BUILD_DIR)/, $(SOB_LIB_SUBDIRS))
# obj files for the main lib
SOB_LIB_OBJS = \
$(foreach var, $(SOB_LIB_SUBDIRS), \
$(patsubst %.cpp, %.o, $(wildcard $(var)/*.cpp)) )
DEBUG_SOB_LIB_OBJS = $(addprefix $(DEBUG_BUILD_DIR)/, $(SOB_LIB_OBJS))
RELEASE_SOB_LIB_OBJS = $(addprefix $(RELEASE_BUILD_DIR)/, $(SOB_LIB_OBJS))
# source file dirsfor the performance and functional tests
TEST_SUBDIRS = \
test \
test/performance \
test/performance/tests \
test/functional \
test/functional/tests \
test/functional/tests/advanced_orders
DEBUG_TEST_SUBDIRS = $(addprefix $(DEBUG_BUILD_DIR)/, $(TEST_SUBDIRS))
RELEASE_TEST_SUBDIRS = $(addprefix $(RELEASE_BUILD_DIR)/, $(TEST_SUBDIRS))
# obj files for the performance and functional tests
SOB_TEST_OBJS = \
$(foreach var, $(TEST_SUBDIRS), \
$(patsubst %.cpp, %.o, $(wildcard $(var)/*.cpp)) )
DEBUG_SOB_TEST_OBJS = $(addprefix $(DEBUG_BUILD_DIR)/, $(SOB_TEST_OBJS))
RELEASE_SOB_TEST_OBJS = $(addprefix $(RELEASE_BUILD_DIR)/, $(SOB_TEST_OBJS))
# (internal) compiler options; CXXFLAGS should be set externally
OURFLAGS += -std=c++11 -Wall -fmessage-length=0 -ftemplate-backtrace-limit=0
DEBUG_FLAGS := -DDEBUG -g -O0
debug : OURFLAGS += $(DEBUG_FLAGS)
release : OURFLAGS += -O3
functional-test : OURFLAGS += $(DEBUG_FLAGS)
performance-test : OURFLAGS += -O3
debug-test : OURFLAGS += $(DEBUG_FLAGS)
release-test : OURFLAGS += -O3
LIBS := -lpthread -ldl -lutil
SOB_LIB_NAME := libSimpleOrderbook.a
all: performance-test functional-test
functional-test: $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME) $(DEBUG_BUILD_DIR)/FunctionalTest
performance-test: $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME) $(RELEASE_BUILD_DIR)/PerformanceTest
debug-test: $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME) $(DEBUG_BUILD_DIR)/SimpleOrderbookTest
release-test: $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME) $(RELEASE_BUILD_DIR)/SimpleOrderbookTest
debug: $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME)
release: $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME)
$(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME): $(DEBUG_SOB_LIB_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC Archiver'
ar -r "$@" $(DEBUG_SOB_LIB_OBJS)
@echo 'Finished building target: $@'
@echo ' '
$(DEBUG_BUILD_DIR)/src/%.o : $(PROJECT_ROOT)/src/%.cpp | $(DEBUG_SOB_LIB_SUBDIRS)
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -c -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(DEBUG_SOB_LIB_SUBDIRS):
mkdir -p $@
$(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME): $(RELEASE_SOB_LIB_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC Archiver'
ar -r "$@" $(RELEASE_SOB_LIB_OBJS)
@echo 'Finished building target: $@'
@echo ' '
$(RELEASE_BUILD_DIR)/src/%.o : $(PROJECT_ROOT)/src/%.cpp | $(RELEASE_SOB_LIB_SUBDIRS)
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -c -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(RELEASE_SOB_LIB_SUBDIRS):
mkdir -p $@
$(DEBUG_BUILD_DIR)/FunctionalTest $(DEBUG_BUILD_DIR)/SimpleOrderbookTest : \
$(DEBUG_SOB_TEST_OBJS) $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -o "$@" $(LIBS) $(DEBUG_SOB_TEST_OBJS) $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME)
@echo 'Finished building target: $@'
@echo ' '
$(DEBUG_BUILD_DIR)/test/%.o : $(PROJECT_ROOT)/test/%.cpp | $(DEBUG_TEST_SUBDIRS)
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(DEBUG_TEST_SUBDIRS):
mkdir -p $@
$(RELEASE_BUILD_DIR)/PerformanceTest $(RELEASE_BUILD_DIR)/SimpleOrderbookTest : \
$(RELEASE_SOB_TEST_OBJS) $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -o "$@" $(LIBS) $(RELEASE_SOB_TEST_OBJS) $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME)
@echo 'Finished building target: $@'
@echo ' '
$(RELEASE_BUILD_DIR)/test/%.o : $(PROJECT_ROOT)/test/%.cpp | $(RELEASE_TEST_SUBDIRS)
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CXX) $(CXXFLAGS) $(OURFLAGS) -c -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(RELEASE_TEST_SUBDIRS):
mkdir -p $@
# include .d files for all builds/targets
-include $(patsubst %.o, %.d, $(DEBUG_SOB_LIB_OBJS))
-include $(patsubst %.o, %.d, $(RELEASE_SOB_LIB_OBJS))
-include $(patsubst %.o, %.d, $(DEBUG_SOB_TEST_OBJS))
-include $(patsubst %.o, %.d, $(RELEASE_SOB_TEST_OBJS))
clean:
rm -fr $(DEBUG_BUILD_DIR)/* $(RELEASE_BUILD_DIR)/*
clean-debug:
rm -fr $(DEBUG_BUILD_DIR)/$(SOB_LIB_NAME) $(DEBUG_BUILD_DIR)/src
clean-release:
rm -fr $(RELEASE_BUILD_DIR)/$(SOB_LIB_NAME) $(RELEASE_BUILD_DIR)/src
clean-functional-test:
rm -fr $(DEBUG_BUILD_DIR)/FunctionalTest $(DEBUG_BUILD_DIR)/test
clean-performance-test:
rm -fr $(RELEASE_BUILD_DIR)/PerformanceTest $(RELEASE_BUILD_DIR)/test
clean-debug-test:
rm -fr $(DEBUG_BUILD_DIR)/SimpleOrderbookTest $(DEBUG_BUILD_DIR)/test
clean-release-test:
rm -fr $(RELEASE_BUILD_DIR)/SimpleOrderbookTest $(RELEASE_BUILD_DIR)/test
.PHONY : all performance-test functional-test release debug \
clean clean-debug clean-release clean-functional-test \
clean-performance-test clean-debug-test clean-release-test