-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.make
196 lines (160 loc) · 6.31 KB
/
common.make
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
# This makefile requires the following variables:
# CXX
# CXXFLAGS
# CXXFLAGS_DEBUG
# NVCC
# CUDAFLAGS
# INCLUDES
# LDFLAGS
# LDLIBS
ifndef SYSTEM
$(error SYSTEM variable is not set)
endif
ifeq ($(wildcard sys/$(SYSTEM)/.),)
$(error $(SYSTEM) is not an available system. Should be one of: $(shell ls sys))
endif
CXXFLAGS+= -Xcompiler -Wall -Xcompiler -Wextra -Xcompiler -Wshadow -Xcompiler -Wpointer-arith -Xcompiler -Wcast-qual -std=c++11 -g -Xcompiler -fopenmp -O3 -Xcompiler
CXXFLAGS_DEBUG+= -Xcompiler -Wall -Xcompiler -Wextra -Xcompiler -Wshadow -Xcompiler -Wpointer-arith -Xcompiler -Wcast-qual -std=c++11 -g -Xcompiler -fopenmp -O0 -DDEBUG -Xcompiler
CUDAFLAGS+=-m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60
INCLUDES+=-I./include -I./ -I./sys/$(SYSTEM)/
LDLIBS+=-lboost_unit_test_framework -lboost_log -lcublas -lcusolver -lcusparse -lcuda -lboost_program_options -lconfig++ -lboost_system
TESTS:=$(wildcard tests/*.cpp)
TESTOBJS:=$(addprefix objects/$(SYSTEM)/,$(TESTS:.cpp=.o))
SYS:=$(wildcard sys/$(SYSTEM)/*.cpp)
SYSNOTDIR:=$(notdir $(SYS))
SYSOBJS:=$(addprefix objects/$(SYSTEM)/sys/,$(SYSNOTDIR:.cpp=.o))
SYSOBJS_DEBUG:=$(addprefix objects/$(SYSTEM)/sys/,$(SYSNOTDIR:.cpp=_debug.o))
SRCS:=$(wildcard src/*.cpp)
OBJS:=$(addprefix objects/$(SYSTEM)/,$(SRCS:.cpp=.o))
OBJS_DEBUG:=$(addprefix objects/$(SYSTEM)/,$(SRCS:.cpp=_debug.o))
DEP:=$(subst .o,.d,$(OBJS)) $(subst .o,.d,$(OBJS_DEBUG)) $(subst .o,.d,$(TESTOBJS)) $(subst .o,.d,$(SYSOBJS)) $(subst .o,.d,$(SYSOBJS_DEBUG))
.PHONY: default
default: $(SYSTEM)
# Compile src files
objects/$(SYSTEM)/src/%.o: src/%.cpp | object-dirs
@echo -n "Compiling $<..."
@$(NVCC) $(INCLUDES) $(CXXFLAGS) -DBOOST_LOG_DYN_LINK -DBOOST_TEST_DYN_LINK $(CUDAFLAGS) -c $< -o $@
@echo " done"
# Compile debug system src files
objects/$(SYSTEM)/sys/%_debug.o: sys/$(SYSTEM)/%.cpp | object-dirs
@echo -n "Compiling $< (debug)..."
@$(NVCC) $(INCLUDES) $(CXXFLAGS_DEBUG) -DBOOST_LOG_DYN_LINK -DBOOST_TEST_DYN_LINK $(CUDAFLAGS) -c $< -o $@
@echo " done"
# Compile src system files
objects/$(SYSTEM)/sys/%.o: sys/$(SYSTEM)/%.cpp | object-dirs
@echo -n "Compiling $<..."
@$(NVCC) $(INCLUDES) $(CXXFLAGS) -DBOOST_LOG_DYN_LINK -DBOOST_TEST_DYN_LINK $(CUDAFLAGS) -c $< -o $@
@echo " done"
# Compile debug src files
objects/$(SYSTEM)/src/%_debug.o: src/%.cpp | object-dirs
@echo -n "Compiling $< (debug)..."
@$(NVCC) $(INCLUDES) $(CXXFLAGS_DEBUG) -DBOOST_LOG_DYN_LINK -DBOOST_TEST_DYN_LINK $(CUDAFLAGS) -c $< -o $@
@echo " done"
# Compile unit tests
objects/$(SYSTEM)/tests/%.o: tests/%.cpp | object-dirs
@echo -n "Compiling $<..."
@$(NVCC) $(INCLUDES) $(CXXFLAGS_DEBUG) -DBOOST_LOG_DYN_LINK -DBOOST_TEST_DYN_LINK $(CUDAFLAGS) -c $< -o $@
@echo " done"
# Link unit tests and run
.PHONY: unit-tests
unit-tests: $(SYSTEM)-unit-tests-run
# Run the unit tests
.PHONY: $(SYSTEM)-unit-tests-run
$(SYSTEM)-unit-tests-run : $(SYSTEM)-unit-tests
@./$(SYSTEM)-unit-tests
# Compile the unit tests
$(SYSTEM)-unit-tests: $(TESTOBJS) $(OBJS_DEBUG) $(SYSOBJS_DEBUG) | object-dirs
@echo -n "Linking $@..."
@$(NVCC) $(CXXFLAGS_DEBUG) $(CUDAFLAGS) $(TESTOBJS) $(SYSOBJS_DEBUG) $(filter-out objects/$(SYSTEM)/src/main_debug.o, $(OBJS_DEBUG)) $(LDFLAGS) $(LDLIBS) -o $@
@echo " done"
# Link program
$(SYSTEM): $(OBJS) $(SYSOBJS) | object-dirs
@echo -n "Linking $@..."
@$(NVCC) $(CXXFLAGS) $(CUDAFLAGS) $(OBJS) $(SYSOBJS) $(LDFLAGS) $(LDLIBS) -o $@
@echo " done"
.PHONY: debug
debug: $(SYSTEM)-debug
# Link program debug
$(SYSTEM)-debug: $(OBJS_DEBUG) $(SYSOBJS_DEBUG) | object-dirs
@echo -n "Linking $@..."
@$(NVCC) $(CXXFLAGS_DEBUG) $(CUDAFLAGS) $(OBJS_DEBUG) $(SYSOBJS_DEBUG) $(LDFLAGS) $(LDLIBS) -o $@
@echo " done"
# Generate dependencies for tests
objects/$(SYSTEM)/tests/%.d: tests/%.cpp | object-dirs
@echo -n 'Generating dependencies for $<...'
@echo -n $(dir $@) > $@
@$(CXX) -MM -MP $(INCLUDES) $< $(ALLINC) >> $@
@echo " done"
# Generate dependencies for src files
objects/$(SYSTEM)/src/%.d: src/%.cpp | object-dirs
@echo -n 'Generating dependencies for $<...'
@echo -n $(dir $@) > $@
@$(CXX) -MM -MP $(INCLUDES) $< $(ALLINC) >> $@
@cp $@ $(subst .d,_debug.d,$@)
@sed -i 's|$(subst .d,.o,$@):\(.*\)|$(subst .d,_debug.o,$@):\1|g' $(subst .d,_debug.d,$@)
@echo " done"
# Generate dependencies for sys src files
objects/$(SYSTEM)/sys/%.d: sys/$(SYSTEM)/%.cpp | object-dirs
@echo -n 'Generating dependencies for $<...'
@echo -n $(dir $@) > $@
@$(CXX) -MM -MP $(INCLUDES) $< $(ALLINC) >> $@
@echo " done"
# Capture current git commit.
# Phony so it's updated every time
.PHONY: githash.h
githash.h:
@echo "Generating GIT hash file..."
@printf '#ifndef GIT_HASH\n#define GIT_HASH "' > $@ && \
git rev-parse HEAD | tr -d "\n" >> $@ && \
printf '"\n#endif' >> $@
# Compile everything
.PHONY: all
all: unit-tests debug default
# Run all tests
.PHONY: test
test: unit-tests regression-tests
# Make and run regression tests
.PHONY: regression-tests
regression-tests: $(SYSTEM)
@echo "Running regression tests..."
@./regression-tests -s $(SYSTEM)
# Create directories
.PHONY: object-dirs
object-dirs:
@mkdir -p objects/$(SYSTEM)/tests
@mkdir -p objects/$(SYSTEM)/src
@mkdir -p objects/$(SYSTEM)/sys
# Include generated dependencies
-include $(DEP)
# Remove object files
.PHONY: clean
clean:
rm -f objects/$(SYSTEM)/tests/*.o
rm -f objects/$(SYSTEM)/src/*.o
rm -f objects/$(SYSTEM)/sys/*.o
# Remove everything that can be regenerated
.PHONY: distclean
distclean: clean
rm -rf objects
rm -f regressionTest.lock
rm -f $(SYSTEM)
rm -f $(SYSTEM)-debug
rm -f $(SYSTEM)-unit-tests
.PHONY: list
list:
@echo "tests: $(TESTS)"
@echo "test objects: $(TESTOBJS)"
@echo "sources: $(SRCS)"
@echo "system: $(SYS)"
@echo "objects: $(OBJS) $(SYSOBJS)"
@echo "dependencies: $(DEP)"
.PHONY: help
help:
@echo "all - Compile everything"
@echo "unit-tests - Compile and run unit tests"
@echo "regression-tests - Compile and run regression tests"
@echo "test - Compile and run all tests"
@echo "default - Compile program"
@echo "debug - Compile program (with O0 and DEBUG defined)"
@echo "clean - Remove object files"
@echo "distclean - Remove all objects and dependencies"