-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
407 lines (342 loc) · 15.2 KB
/
Makefile
File metadata and controls
407 lines (342 loc) · 15.2 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# Copyright 2018 University of Toronto
#
# Permission is hereby granted, to use this software and associated
# documentation files (the "Software") in course work at the University
# of Toronto, or for personal use. Other uses are prohibited, in
# particular the distribution of the Software either publicly or to third
# parties.
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
#
# NOTE: It is always *your* responsibility to ensure your code works
# with the autotester and can be submitted successfully.
#
# We can not grade code that fails to compile/link.
#
# After any changes verify that your code builds and submits successfully!
################################################################################
#If you wish to add custom linking/compile flags add them to the
# CUSTOM_LINK_FLAGS and CUSTOM_COMIPLE_FLAGS. The autotester will
# use these determine how to compile/link your code.
#
# For example, setting:
#
# CUSTOM_COMPILE_FLAGS = -fopenmp
# CUSTOM_LINK_FLAGS = -fopenmp
#
# will enable OpenMP (the fopenmp flag needs to be specified both during
# compilation and linking),
#
# While setting:
#
# CUSTOM_LINK_FLAGS = -lreadline
#
# will cause the autotester to link to the GNU Readline library.
#
# Multiple options can be combined to enable multiple libraries/features
#
# By default the following custom flags are enabled:
# * pkg-config is used to set all compile and linking flags required by EZGL (x11, gtk)
# * -fopenmp (OpenMP for parallel programming)
# * -lreadline (interactive line editing library)
#
CUSTOM_COMPILE_FLAGS = $(shell pkg-config --cflags x11 gtk+-3.0 libcurl) -fopenmp
CUSTOM_LINK_FLAGS = $(shell pkg-config --libs x11 gtk+-3.0 libcurl) -fopenmp -lreadline
################################################################################
# ! WARNING - Here Be Dragons - WARNING !
#
# Editting below this point should not be neccessary,
# and may break the autotester.
#
# Make sure you know what you are doing!
################################################################################
################################################################################
# Utility Functions
################################################################################
#Recursive version of wildcard (i.e. it checks all subdirectories)
# For example:
# $(call rwildcard, /tmp/, *.c *.h)
# will return all files ending in .c or .h in /tmp and any of tmp's sub-directories
#NOTE: the directory (e.g. /tmp/) should end with a slash (i.e. /)
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
#Recursively find directories containing specifc files (useful for finding header include directories)
# For example:
# $(call rfiledirs, /tmp/, *.h *.hpp)
# will return all directories in /tmp which contain .h or .hpp files
#NOTE: the directory (e.g. /tmp/) should end with a slash (i.e. /)
rfiledirs=$(sort $(dir $(call rwildcard, $1, $2)))
################################################################################
# Configuration
################################################################################
#Default build type
CONF=release
$(info Configuration is '$(CONF)')
#
# Tool names
#
#The name of the compiler to use
CXX = g++
#Name of the archiver used to create .a from sets of .o files
AR = ar
#
# Directories
#
#Directory for build temporaries
BUILD_DIR = build
#What directory contains the source files for the main executable?
EXE_SRC_DIR = main/src
#What directory contains the source files for the street map static library?
LIB_STREETMAP_SRC_DIR = libstreetmap/src/
#What directory contains the source files for the street map library tests?
LIB_STREETMAP_TEST_DIR = libstreetmap/tests/
#Global directory to look for custom library builds
ECE297_ROOT ?= /cad2/ece297s/public
ECE297_LIB_DIR ?= $(ECE297_ROOT)/lib
ECE297_INCLUDE_DIR ?= $(ECE297_ROOT)/include
#
#Output files
#
#Name of the primary executable
EXE=mapper
#Name of the test executable
LIB_STREETMAP_TEST=test_libstreetmap
#Name of the street map static library
LIB_STREETMAP=libstreetmap.a
################################################################################
# External Library Configuration
################################################################################
ECE297_MILESTONE_INCLUDE_DIRS ?= $(ECE297_INCLUDE_DIR)/milestones
#Boost serialization
BOOST_SERIALIZATION_RELEASE_LIB := -lboost_serialization
BOOST_SERIALIZATION_DEBUG_CHECK_LIB := $(ECE297_LIB_DIR)/debug_check/libboost_serialization.a
BOOST_SERIALIZATION_LIB := $(BOOST_SERIALIZATION_RELEASE_LIB) #Defines the version actually used, default release
#Streets database
STREETS_DATABASE_RELEASE_LIB := $(ECE297_LIB_DIR)/release/libstreetsdatabase.a
STREETS_DATABASE_DEBUG_CHECK_LIB := $(ECE297_LIB_DIR)/debug_check/libstreetsdatabase.a
STREETS_DATABASE_LIB := $(STREETS_DATABASE_RELEASE_LIB) #Defines the version actually used, default release
STREETS_DATABASE_INCLUDE_DIRS := $(ECE297_INCLUDE_DIR)/streetsdatabase
#Unittest++
UNITTESTPP_RELEASE_LIB := -lunittest++
UNITTESTPP_DEBUG_CHECK_LIB := $(ECE297_LIB_DIR)/debug_check/libunittest++.a
UNITTESTPP_LIB := $(UNITTESTPP_RELEASE_LIB) #Defines the version actually used, default release
#Choose the correct external library builds.
#If we are using a debug build AND we have a separately compiled debug
#build of a library use it instead of the system default
ifeq (debug_check, $(findstring debug_check,$(CONF))) #Doing a debug check build?
#Boost serialization
ifneq (, $(wildcard $(BOOST_SERIALIZATION_DEBUG_CHECK_LIB)))
#Debug lib file exists, use it
BOOST_SERIALIZATION_LIB := $(BOOST_SERIALIZATION_DEBUG_CHECK_LIB)
endif
#Streets database
ifneq (, $(wildcard $(STREETS_DATABASE_DEBUG_CHECK_LIB)))
#Debug lib file exists, use it
STREETS_DATABASE_LIB := $(STREETS_DATABASE_DEBUG_CHECK_LIB)
endif
#Unittest++
ifneq (, $(wildcard $(UNITTESTPP_DEBUG_CHECK_LIB))) #Debug lib file exits
#Debug lib file exists, use it
UNITTESTPP_LIB := $(UNITTESTPP_DEBUG_CHECK_LIB)
endif
endif #debug
################################################################################
# Tool flags
################################################################################
#What warning flags should be passed to the compiler?
WARN_CFLAGS = -Wall \
-Wextra \
-Wpedantic \
-Wcast-qual \
-Wcast-align \
-Wformat=2 \
-Wlogical-op \
-Wmissing-declarations \
-Wmissing-include-dirs \
-Wswitch-default \
-Wundef \
-Wunused-variable \
-Woverloaded-virtual \
-Wctor-dtor-privacy \
-Wnon-virtual-dtor \
-Wredundant-decls \
-Wshadow \
#-Wold-style-cast \
#-Wconversion \
#-Wno-sign-conversion
# Find all the include directoires for each component
LIB_STREETMAP_INCLUDE_FLAGS = $(foreach dir, $(call rfiledirs, $(LIB_STREETMAP_SRC_DIR), *.h *.hpp), -I$(dir) -I$(dir)..)
EXE_INCLUDE_FLAGS = $(foreach dir, $(call rfiledirs, $(EXE_SRC_DIR), *.h *.hpp), -I$(dir))
STREETS_DATABASE_INCLUDE_FLAGS = $(foreach dir, $(STREETS_DATABASE_INCLUDE_DIRS), -I$(dir))
ECE297_MILESTONE_INCLUDE_FLAGS = $(foreach dir, $(ECE297_MILESTONE_INCLUDE_DIRS), -I$(dir))
#What include flags should be passed to the compiler?
INCLUDE_CFLAGS = $(LIB_STREETMAP_INCLUDE_FLAGS) $(ECE297_MILESTONE_INCLUDE_FLAGS) $(STREETS_DATABASE_INCLUDE_FLAGS) $(EXE_INCLUDE_FLAGS)
#What options to generate header dependency files should be passed to the compiler?
DEP_CFLAGS = -MMD -MP
#What extra flags to use in a debug build?
DEBUG_CFLAGS = -g -O0
DEBUG_LFLAGS =
# Defining _GLIBCXX_DEBUG enables extra STL checking (e.g. vector [] bounds checking, iterator validity)
# Specifying -fsanitize enabled run-time sanitizer checking (e.g. bad memory access, leaks, undefined behaviour)
DEBUG_CHECK_CFLAGS = -g -O0 -D_GLIBCXX_DEBUG -fsanitize=address -fsanitize=leak -fsanitize=undefined
DEBUG_CHECK_LFLAGS = -fsanitize=address -fsanitize=leak -fsanitize=undefined
#What extra flags to use in a release build?
RELEASE_CFLAGS = -g -O3
RELEASE_LFLAGS =
#What extra flags to use in release profile build?
# Note: provide -g so symbols are included in profiling info
# We provide the -no-pie link flag to work-around a known bug in gcc6 which causes
# the produce profile to be empty otherwise. See: https://bugs.launchpad.net/bugs/1678510
PROFILE_CFLAGS = -g -O3 -pg -fno-inline
PROFILE_LFLAGS = -no-pie -pg
#Pick either debug/release/profile build flags
ifeq (release, $(CONF))
CONF_CFLAGS := $(RELEASE_CFLAGS)
CONF_LFLAGS := $(RELEASE_LFLAGS)
else ifeq (debug, $(CONF))
CONF_CFLAGS := $(DEBUG_CFLAGS)
CONF_LFLAGS := $(DEBUG_LFLAGS)
else ifeq (debug_check, $(CONF))
CONF_CFLAGS := $(DEBUG_CHECK_CFLAGS)
CONF_LFLAGS := $(DEBUG_CHECK_LFLAGS)
else ifeq (profile, $(CONF))
CONF_CFLAGS := $(PROFILE_CFLAGS)
CONF_LFLAGS := $(PROFILE_LFLAGS)
else
$(error Invalid value for CONF: '$(CONF)', must be 'release', 'debug', 'debug_check', 'profile'. Try 'make help' for usage)
endif
#Collect all the options to give to the compiler
CFLAGS = --std=c++14 $(CONF_CFLAGS) $(DEP_CFLAGS) $(WARN_CFLAGS) $(INCLUDE_CFLAGS) $(CUSTOM_COMPILE_FLAGS)
#Flags for linking
LFLAGS = $(CONF_LFLAGS) -L. $(STREETS_DATABASE_LIB) $(BOOST_SERIALIZATION_LIB) $(GRAPHICS_LFLAGS) $(CUSTOM_LINK_FLAGS)
#
# Archiver flags
#
#Flags for the archiver (used to create static libraries)
ARFLAGS = rvs
################################################################################
# Generate object file names from source file names
################################################################################
#Objects associated with the main executable
EXE_OBJ=$(patsubst %.cpp, $(BUILD_DIR)/$(CONF)/%.o, $(call rwildcard, $(EXE_SRC_DIR), *.cpp))
#Objects associated with the street map library
LIB_STREETMAP_OBJ=$(patsubst %.cpp, $(BUILD_DIR)/$(CONF)/%.o, $(call rwildcard, $(LIB_STREETMAP_SRC_DIR), *.cpp))
#Objects associated with tests for the street map library
# We collect tests both from the local project (under LIB_STREETMAP_TEST_DIR)
LIB_STREETMAP_TEST_OBJ=$(patsubst %.cpp, $(BUILD_DIR)/$(CONF)/%.o, \
$(call rwildcard, $(LIB_STREETMAP_TEST_DIR), *.cpp) \
)
################################################################################
# Dependency files
################################################################################
#To capture dependencies on header files,
# we told the compiler to generate dependency
# files associated with each object file
#
#The ':.o=.d' syntax means replace each filename ending in .o with .d
# For example:
# build/main/main.o would become build/main/main.d
DEP = $(EXE_OBJ:.o=.d) $(LIB_STREETMAP_OBJ:.o=.d) $(LIB_STREETMAP_TEST_OBJ:.o=.d)
################################################################################
# Make targets
################################################################################
#Phony targets are always run (i.e. are always out of date)
# We mark all executables and static libraries as phony so that they will
# always be re-linked. This ensures that all final libraries/executables
# will be of the same build CONF. This is important since using _GLIBCXX_DEBUG
# can cause the debug and release builds to be binary incompatible, causing odd
# errors if both debug and release components are mixed.
.PHONY: clean $(EXE) $(LIB_STREETMAP_TEST) $(LIB_STREETMAP)
#The default target
# This is called when you type 'make' on the command line
all: $(EXE)
#This runs the unit test executable
test: $(LIB_STREETMAP_TEST)
@echo ""
@echo "Running Unit Tests..."
./$(LIB_STREETMAP_TEST)
#Include header file dependencies generated by a
# previous compile
-include $(DEP)
#Link main executable
$(EXE): $(EXE_OBJ) $(LIB_STREETMAP)
$(CXX) $^ $(LFLAGS) -o $@
#Link test executable
$(LIB_STREETMAP_TEST): $(LIB_STREETMAP_TEST_OBJ) $(LIB_STREETMAP)
$(CXX) $^ $(UNITTESTPP_LIB) $(LFLAGS) -o $@
#Street Map static library
$(LIB_STREETMAP): $(LIB_STREETMAP_OBJ)
$(AR) $(ARFLAGS) $@ $^
#Note: % matches recursively between prefix and suffix
# so %.cpp would match both src/a/a.cpp
# and src/b/b.cpp
$(BUILD_DIR)/$(CONF)/%.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(BUILD_DIR)/*
rm -f $(EXE) $(LIB_STREETMAP) $(LIB_STREETMAP_TEST)
custom_flags:
@echo "CUSTOM_COMPILE_FLAGS: $(CUSTOM_COMPILE_FLAGS)"
@echo "CUSTOM_LINK_FLAGS: $(CUSTOM_LINK_FLAGS)"
echo_flags:
@echo "COMPILE_FLAGS: $(CFLAGS)"
@echo "LINK_FLAGS: $(LFLAGS)"
help:
@echo "Makefile for ECE297"
@echo ""
@echo "Usage: "
@echo ' > make'
@echo " Call the default make target (all)."
@echo " This builds the project executable: '$(EXE)'."
@echo " > make clean"
@echo " Removes any generated files including exectuables,"
@echo " static libraries, and object files."
@echo " > make test"
@echo " Runs unit tests."
@echo " Builds and runs any tests found in $(LIB_STREETMAP_TEST_DIR),"
@echo " generating the test executable '$(LIB_STREETMAP_TEST)'."
@echo " > make custom_flags"
@echo " Echos the custom compile and link flags."
@echo " This is used by the autotester to figure out how compile and link your code."
@echo " > make echo_flags"
@echo " Echos the compile and link flags used by the make file."
@echo " > make help"
@echo " Prints this help message."
@echo ""
@echo ""
@echo "Configuration Variables: "
@echo " CONF={release | debug | debug_check | profile}"
@echo " Controls whether the build performs compiler optimizations"
@echo " to improve performance. Currently set to '$(CONF)'."
@echo ""
@echo " With CONF=release compiler optimization is enabled ($(RELEASE_CFLAGS))."
@echo ""
@echo " With CONF=debug compiler optimization is disabled to improve"
@echo " interactive debugging ($(DEBUG_CFLAGS))."
@echo ""
@echo " With CONF=debug_check compiler optimization is disabled, and extra"
@echo " error checking enabled in the standard library, invalid memory access"
@echo " and undefined behaviour ($(DEBUG_CHECK_CFLAGS))."
@echo ""
@echo " With CONF=profile a release-like build with gprof profiling "
@echo " enabled ($(PROFILE_CFLAGS))."
@echo ""
@echo " You can configure specify this option on the command line."
@echo " To perform a release build you can use: "
@echo " > make CONF=release"
@echo " To perform a regular debug build you can use: "
@echo " > make CONF=debug"
@echo " To perform a debug build with extra checking (runs slower) you can use: "
@echo " > make CONF=debug_check"
@echo " To perform a profile build you can use: "
@echo " > make CONF=profile"