-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
124 lines (111 loc) · 4.72 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
#This variable stores the name/path of the directory with all the object files will be (relative to the make file)
OBJ_DIR=build
SRC_DIR=DgsSort
CMAKE_CMD=cmake
MAKE_CMD=make
ifneq ($(SANI),)
CMAKE_ADD_SANI="-DSANITIZER=$(SANI)"
DIR_APPEND="-$(SANI)"
else
CMAKE_ADD_SANI=
DIR_APPEND=
endif
CMAKE_GEN_CMD=-DCMAKE_INSTALL_PREFIX=$(shell pwd) $(CMAKE_ADD_SANI)
SYSNAME=$(shell hostname)
#this builds the project with no flags but those absolutely necessary
.PHONY: plain
plain: BUILD_DIR=$(OBJ_DIR)/plain$(DIR_APPEND)
plain: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE="" $(CMAKE_GEN_CMD)
plain: primary_build_rule
#this builds the project with debug flags making it easier to attach a debugger and see what is happening
.PHONY: debug
debug: BUILD_DIR=$(OBJ_DIR)/Debug$(DIR_APPEND)
debug: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=Debug $(CMAKE_GEN_CMD)
debug: primary_build_rule
#this builds the project with debug flags and with optimization flags allowing you to attach a debugger
#to see if the optimization is screwing something up
.PHONY: opt_debug
opt_debug: BUILD_DIR=$(OBJ_DIR)/RelWithDebInfo$(DIR_APPEND)
opt_debug: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=RelWithDebInfo $(CMAKE_GEN_CMD)
opt_debug: primary_build_rule
#this builds the project with no debug flags and with optimization flags making it run faster
.PHONY: release
release: BUILD_DIR=$(OBJ_DIR)/Release$(DIR_APPEND)
release: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=Release $(CMAKE_GEN_CMD)
release: primary_build_rule
#this builds the project with the generic warning flags enabled to see where you might want to make changed
.PHONY: warn
warn: BUILD_DIR=$(OBJ_DIR)/Warn$(DIR_APPEND)
warn: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=Warn $(CMAKE_GEN_CMD)
warn: primary_build_rule
#this builds the project with the generic warning flags enabled to see where you might want to make changed
.PHONY: warn_opt
warn_opt: BUILD_DIR=$(OBJ_DIR)/WarnWithOpt$(DIR_APPEND)
warn_opt: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=WarnWithOpt $(CMAKE_GEN_CMD)
warn_opt: primary_build_rule
#this runs the clang-tidy rule on the project, but does not build anything
.PHONY: tidy
tidy: BUILD_DIR=$(OBJ_DIR)/tidy
tidy: CMAKE_FLAGS=-DCMAKE_BUILD_TYPE="" $(CMAKE_GEN_CMD)
tidy:
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR); $(CMAKE_CMD) $(CMAKE_FLAGS) ../../$(SRC_DIR)
@echo "Hitting clang tidy checks"
@$(MAKE) -C $(BUILD_DIR) tidy
# this does the build actions for everything
.PHONY: primary_build_rule
primary_build_rule:
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR); $(CMAKE_CMD) $(CMAKE_FLAGS) ../../$(SRC_DIR)
@$(MAKE) -C $(BUILD_DIR)
@$(MAKE) -C $(BUILD_DIR) install
ifneq ($(SANI),)
# needed on apple... but not linux?? so make it error ignoring
-dsymutil $(EXE_FILE)
endif
ifeq ($(SYSNAME),champ)
@mkdir -p logs
@find logs -type d -print0 | xargs -0 chmod g+w
@find build -type d -print0 | xargs -0 chmod g+w
endif
.PHONY: help
help:
@echo ''
@echo 'Build Types:'
@echo ' `plain` - Build with no flags but those strictly necessary'
@echo ' `debug` - Build with debug flag'
@echo ' `opt_debug` - Build with debug and optimization flags'
@echo ' `release` - Build with optimization flags'
@echo ' `warn` - Build with all the warning flags we can find'
@echo ' `warn_opt` - Build with all the warning flags and release flags (enables a few more warnings)'
@echo ''
@echo 'Sanitizers:'
@echo ' To use a clang sanitizer, add `SANI=$$(Option)` to your command line'
@echo ' The sanitizer options are:'
@echo ' `Address` - Finds out of bounds accesses (to heap, stack and globals), use-after-free, and double-free ~2x slowdown'
@echo ' `Thread` - Detects data races (with limitations) 5-15x slow down, 5-10x memory overhead'
@echo ' `Memory` - Finds uninitialized reads ~3x slowdown'
@echo ' `UndefinedBehavior` - Finds undifined behavior almost no slowdown (has further options, see doc)'
@echo ' `Leak` - Finds memory leaks, almost no slowdown until the end of the process'
@echo ' More about sanitizers at: https://releases.llvm.org/6.0.0/tools/clang/docs/'
@echo ''
@echo 'Miscellaneous Options:'
@echo ' To build multiple files in parallel use'
@echo ' `-j$$(NUM_BUILD)`'
@echo ' To see the commands issued during the buld process add the following to the command line'
@echo ' `VERBOSE=1`'
@echo ''
@echo 'Example:'
@echo ' To show the commands run, run 8 build commands simultaneously,'
@echo ' use the address sanitizer, and have optimization and debug symbols you would run'
@echo ' `make -j 8 VERBOSE=1 SANI=Address opt_debug`'
@echo ''
#cleaning targets to remove various things generated by this make file
#this removes the contents of the build directories
.PHONY: clean
clean:
-rm -rf $(OBJ_DIR)
#this runs clean and then removes the executable
.PHONY: cleanall
cleanall: clean
-rm -f dgSort