Makefile 11.5 KB
Newer Older
Philipp  Trunschke's avatar
Philipp Trunschke committed
1
.PHONY: help version shared static python doc install test clean opt warn printBoostVersion
Philipp  Trunschke's avatar
Philipp Trunschke committed
2

3
# ------------------------------------------------------------------------------------------------------
4
#				Default rule should be the help message
Baum's avatar
Baum committed
5
# ------------------------------------------------------------------------------------------------------
6
7
8
9
help:
	@printf "Possible make targets are:\n \
	\t\tshared \t\t -- Build xerus as a shared library.\n \
	\t\tstatic \t\t -- Build xerus as a static library.\n \
Philipp  Trunschke's avatar
Philipp Trunschke committed
10
11
	\t\tpython2 \t\t -- Build the xerus python2 wrappers.\n \
	\t\tpython3 \t\t -- Build the xerus python3 wrappers.\n \
12
	\t\tdoc \t\t -- Build the html documentation for the xerus library.\n \
13
14
15
	\t\tinstall \t -- Install the shared library and header files (may require root).\n \
	\t\ttest \t\t -- Build and run the xerus unit tests.\n \
	\t\tclean \t\t -- Remove all object, library and executable files.\n"
Baum's avatar
Baum committed
16

17

18
# ------------------------------------------------------------------------------------------------------
19
#				Set the names of the resulting binary codes
20
# ------------------------------------------------------------------------------------------------------
Baum's avatar
Baum committed
21
22
23
24

# Name of the test executable
TEST_NAME = XerusTest

Benjamin Huber's avatar
Benjamin Huber committed
25
# xerus version from VERSION file
Philipp  Trunschke's avatar
Philipp Trunschke committed
26
27
# XERUS_VERSION = $(shell git describe --tags --always 2>/dev/null || cat VERSION)  # git should not be an explicit dependency
XERUS_VERSION = $(shell cat VERSION)
28
DEBUG += -D XERUS_VERSION="$(XERUS_VERSION)"
Benjamin Huber's avatar
Benjamin Huber committed
29

30
31
32
33
XERUS_MAJOR_V = $(word 1, $(subst ., ,$(XERUS_VERSION)) )
ifneq (,$(findstring v, $(XERUS_MAJOR_V)))
	XERUS_MAJOR_V := $(strip $(subst v, ,$(XERUS_MAJOR_V)) )
endif
Philipp  Trunschke's avatar
Philipp Trunschke committed
34
DEBUG += -D XERUS_VERSION_MAJOR="$(XERUS_MAJOR_V)"
35
XERUS_MINOR_V = $(word 2, $(subst ., ,$(XERUS_VERSION)) )
Philipp  Trunschke's avatar
Philipp Trunschke committed
36
DEBUG += -D XERUS_VERSION_MINOR="$(XERUS_MINOR_V)"
37
38
39
40
41
42
43
44
45
46
XERUS_REVISION_V = $(word 3, $(subst ., ,$(XERUS_VERSION)) )
ifneq (,$(findstring -, $(XERUS_REVISION_V)))
	XERUS_COMMIT_V := $(word 2, $(subst -, ,$(XERUS_REVISION_V)) )
	XERUS_REVISION_V := $(word 1, $(subst -, ,$(XERUS_REVISION_V)) )
else
	XERUS_COMMIT_V = 0
endif
DEBUG += -DXERUS_VERSION_REVISION=$(XERUS_REVISION_V)
DEBUG += -DXERUS_VERSION_COMMIT=$(XERUS_COMMIT_V)

Philipp  Trunschke's avatar
Philipp Trunschke committed
47
48
49
50
51
52
53
version:
	@echo $(XERUS_VERSION)
	@echo MAYOR: $(XERUS_MAJOR_V)
	@echo MINOR: $(XERUS_MINOR_V)
	@echo REVISION: $(XERUS_REVISION_V)
	@echo COMMIT: $(XERUS_COMMIT_V)

54

Baum's avatar
Baum committed
55
# ------------------------------------------------------------------------------------------------------
56
#				Register source files for the xerus library
Baum's avatar
Baum committed
57
58
# ------------------------------------------------------------------------------------------------------

59
60
61
# Register the source files
XERUS_SOURCES = $(wildcard src/xerus/*.cpp)
XERUS_SOURCES += $(wildcard src/xerus/algorithms/*.cpp)
62
XERUS_SOURCES += $(wildcard src/xerus/applications/*.cpp)
63
64
65
66
67
68
69
XERUS_SOURCES += $(wildcard src/xerus/examples/*.cpp)

MISC_SOURCES = $(wildcard src/xerus/misc/*.cpp)

PYTHON_SOURCES = $(wildcard src/xerus/python/*.cpp)

TEST_SOURCES = $(wildcard src/xerus/test/*.cpp)
Baum's avatar
Baum committed
70

71
UNIT_TEST_SOURCES = $(wildcard src/unitTests/*.cxx)
72

73
74
TUTORIAL_SOURCES = $(wildcard tutorials/*.cpp)

75
# Create lists of the corresponding objects and dependency files
76
77
78
79
80
XERUS_OBJECTS = $(XERUS_SOURCES:%.cpp=build/.libObjects/%.o)
XERUS_DEPS    = $(XERUS_SOURCES:%.cpp=build/.libObjects/%.d)

MISC_OBJECTS = $(MISC_SOURCES:%.cpp=build/.miscObjects/%.o)
MISC_DEPS    = $(MISC_SOURCES:%.cpp=build/.miscObjects/%.d)
81

Sebastian Wolf's avatar
Sebastian Wolf committed
82
83
# PYTHON_OBJECTS = $(PYTHON_SOURCES:%.cpp=build/.pythonObjects/%.o)
# PYTHON_DEPS    = $(PYTHON_SOURCES:%.cpp=build/.pyhtonObjects/%.d)
84
85
86

TEST_OBJECTS = $(TEST_SOURCES:%.cpp=build/.testObjects/%.o)
TEST_DEPS    = $(TEST_SOURCES:%.cpp=build/.testObjects/%.d)
Baum's avatar
Baum committed
87

88
89
90
UNIT_TEST_OBJECTS = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.o)
UNIT_TEST_DEPS    = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.d)

91
TUTORIALS	= $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%)
92
93
TUTORIAL_DEPS   = $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%.d)

Baum's avatar
Baum committed
94
95

# ------------------------------------------------------------------------------------------------------
96
#		Load the configurations provided by the user and set up general options
Baum's avatar
Baum committed
97
98
99
# ------------------------------------------------------------------------------------------------------
include config.mk

100
101
102
include makeIncludes/general.mk
include makeIncludes/warnings.mk
include makeIncludes/optimization.mk
Baum's avatar
Baum committed
103

104

Baum's avatar
Baum committed
105
# ------------------------------------------------------------------------------------------------------
106
#					Set additional compiler options
Baum's avatar
Baum committed
107
108
# ------------------------------------------------------------------------------------------------------

109

Baum's avatar
Baum committed
110

111

112
# ------------------------------------------------------------------------------------------------------
113
#					Convinience variables
Baum's avatar
Baum committed
114
# ------------------------------------------------------------------------------------------------------
115

116
117
118
119
120
121
# Small hack to get newlines...
define \n


endef

122
123
FLAGS = $(strip $(COMPATIBILITY) $(WARNINGS) $(OPTIMIZE) $(LOGGING) $(DEBUG) $(ADDITIONAL_INCLUDE) $(OTHER))
PYTHON_FLAGS = $(strip $(COMPATIBILITY) $(WARNINGS) $(LOGGING) $(DEBUG) $(ADDITIONAL_INCLUDE) $(OTHER) -fno-var-tracking-assignments)
124
125
126
MINIMAL_DEPS = Makefile config.mk makeIncludes/general.mk makeIncludes/warnings.mk makeIncludes/optimization.mk


127
128
129
# ------------------------------------------------------------------------------------------------------
#					Load dependency files
# ------------------------------------------------------------------------------------------------------
130

131
132
133
134
135
136
-include $(XERUS_DEPS)
-include $(MISC_DEPS)
-include $(TEST_DEPS)
-include $(UNIT_TEST_DEPS)
-include $(TUTORIAL_DEPS)
-include build/.preCompileHeaders/xerus.h.d
137

138

139
# ------------------------------------------------------------------------------------------------------
140
#					Make Rules
141
142
# ------------------------------------------------------------------------------------------------------

Sebastian Wolf's avatar
Sebastian Wolf committed
143
144
opt:
	$(CXX) $(FLAGS) -Q --help=optimizers
145
146
147
148
149
150


warn:
	$(CXX) $(FLAGS) -Q --help=warnings


Sebastian Wolf's avatar
Sebastian Wolf committed
151
# Fake rule to create arbitary headers, to prevent errors if files are moved/renamed
152
%.h:
153

154
shared: build/libxerus_misc.so build/libxerus.so
155
156
157

build/libxerus_misc.so: $(MINIMAL_DEPS) $(MISC_SOURCES)
	mkdir -p $(dir $@)
158
	$(CXX) -shared -fPIC -Wl,-soname,libxerus_misc.so $(FLAGS) -I include $(MISC_SOURCES) -Wl,--as-needed $(CALLSTACK_LIBS) $(BOOST_LIBS) -o build/libxerus_misc.so
Sebastian Wolf's avatar
Sebastian Wolf committed
159

Ben Huber's avatar
Ben Huber committed
160
build/libxerus.so: $(MINIMAL_DEPS) $(XERUS_SOURCES) build/libxerus_misc.so
161
	mkdir -p $(dir $@)
Michael Goette's avatar
Michael Goette committed
162
	$(CXX) -shared -fPIC -Wl,-soname,libxerus.so $(FLAGS) -I include $(XERUS_SOURCES) -L ./build/ -Wl,--as-needed -lxerus_misc $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) -o build/libxerus.so
163

164

Philipp  Trunschke's avatar
Philipp Trunschke committed
165
166
python2: build/python2/xerus.so
python3: build/python3/xerus.so
167
168
169

build/python2/xerus.so: $(MINIMAL_DEPS) $(PYTHON_SOURCES) build/libxerus.so
	mkdir -p $(dir $@)
170
	$(CXX) -shared -fPIC -Wl,-soname,xerus.so $(PYTHON2_CONFIG) $(PYTHON_FLAGS) -I include $(PYTHON_SOURCES) -L ./build/ -Wl,--as-needed -lxerus $(BOOST_PYTHON2) -o $@
171

172
build/python3/xerus.so: $(MINIMAL_DEPS) $(PYTHON_SOURCES) build/libxerus.so
173
	mkdir -p $(dir $@)
174
	@# -fpermissive is needed because of a bug in the definition of BOOST_PYTHON_MODULE_INIT in <boost/python/module_init.h>
175
	$(CXX) -shared -fPIC -Wl,-soname,xerus.so $(PYTHON3_CONFIG) $(PYTHON_FLAGS) -fpermissive -I include $(PYTHON_SOURCES) -L ./build/ -Wl,--as-needed -lxerus $(BOOST_PYTHON3) -o $@
176

177

178
static: build/libxerus_misc.a build/libxerus.a
179

180
build/libxerus_misc.a: $(MINIMAL_DEPS) $(MISC_OBJECTS)
181
	mkdir -p $(dir $@)
182
183
184
185
186
187
188
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
else
	ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
endif

build/libxerus.a: $(MINIMAL_DEPS) $(XERUS_OBJECTS)
189
	mkdir -p $(dir $@)
190
191
192
193
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
else
	ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
Baum's avatar
Baum committed
194
195
endif

196

197
198
199
200
201
ifdef INSTALL_PYTHON2_PATH
install: build/python2/xerus.so
endif
ifdef INSTALL_PYTHON3_PATH
install: build/python3/xerus.so
202
endif
203
204
ifdef INSTALL_LIB_PATH
ifdef INSTALL_HEADER_PATH
205
install: shared
206
207
208
209
210
	@printf "Installing libxerus.so to $(strip $(INSTALL_LIB_PATH)) and storing the header files in $(strip $(INSTALL_HEADER_PATH)).\n"
	mkdir -p $(INSTALL_LIB_PATH)
	mkdir -p $(INSTALL_HEADER_PATH)
	cp include/xerus.h $(INSTALL_HEADER_PATH)
	cp -r include/xerus $(INSTALL_HEADER_PATH)
Ben Huber's avatar
Ben Huber committed
211
212
	cp build/libxerus_misc.so $(INSTALL_LIB_PATH)
	cp build/libxerus.so $(INSTALL_LIB_PATH)
213
214
215
216
217
218
219
ifdef INSTALL_PYTHON2_PATH
	@printf "Installing xerus.so to $(strip $(INSTALL_PYTHON2_PATH)).\n"
	cp build/python2/xerus.so $(INSTALL_PYTHON2_PATH)
endif
ifdef INSTALL_PYTHON3_PATH
	@printf "Installing xerus.so to $(strip $(INSTALL_PYTHON3_PATH)).\n"
	cp build/python3/xerus.so $(INSTALL_PYTHON3_PATH)
220
endif
221
else
222
install:
223
	@printf "Cannot install xerus: INSTALL_HEADER_PATH not set. Please set the path in config file.\n"
224
225
226
endif
else
install:
227
	@printf "Cannot install xerus: INSTALL_LIB_PATH not set.  Please set the path in config file.\n"
228
endif
229

230

231
$(TEST_NAME): $(MINIMAL_DEPS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.a build/libxerus_misc.a
Michael Goette's avatar
Michael Goette committed
232
	$(CXX) -D XERUS_UNITTEST $(FLAGS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.a build/libxerus_misc.a $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) $(CALLSTACK_LIBS) -o $(TEST_NAME)
Baum's avatar
Baum committed
233

234
235
236
237
238
build/print_boost_version: src/print_boost_version.cpp
	@$(CXX) -o $@ $<

printBoostVersion: build/print_boost_version
	@build/print_boost_version
239

Philipp  Trunschke's avatar
Philipp Trunschke committed
240
test: $(TEST_NAME)
Baum's avatar
Baum committed
241
	./$(TEST_NAME) all
242
243


244
test_python2: build/libxerus.so build/python2/xerus.so
Philipp  Trunschke's avatar
Philipp Trunschke committed
245
246
	@PYTHONPATH=build/python2:${PYTHONPATH} LD_LIBRARY_PATH=build:${LD_LIBRARY_PATH} $(PYTEST2) src/pyTests

247
test_python3: build/libxerus.so build/python3/xerus.so
Philipp  Trunschke's avatar
Philipp Trunschke committed
248
	@PYTHONPATH=build/python3:${PYTHONPATH} LD_LIBRARY_PATH=build:${LD_LIBRARY_PATH} $(PYTEST3) src/pyTests
249
250


251
fullTest: $(TUTORIALS) $(TEST_NAME)
252
	$(foreach x,$(TUTORIALS),./$(x)$(\n))
253
	./$(TEST_NAME) all
254

255

Philipp  Trunschke's avatar
Philipp Trunschke committed
256
doc:
257
258
259
	make -C doc doc


260
261
262
263
clean:
	rm -fr build
	-rm -f $(TEST_NAME)
	-rm -f include/xerus.h.gch
Ben Huber's avatar
Ben Huber committed
264
	make -C doc clean
265

266

Baum's avatar
Baum committed
267

268
269
# Build rule for normal misc objects
build/.miscObjects/%.o: %.cpp $(MINIMAL_DEPS)
270
	mkdir -p $(dir $@)
271
272
273
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@


274
275
# Build rule for normal lib objects
build/.libObjects/%.o: %.cpp $(MINIMAL_DEPS)
276
	mkdir -p $(dir $@)
277
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@
278

279

280
281
282
# Build rule for test lib objects
build/.testObjects/%.o: %.cpp $(MINIMAL_DEPS)
	mkdir -p $(dir $@)
283
	$(CXX) -D XERUS_UNITTEST -I include $< -c $(FLAGS) -MMD -o $@
284

285

286
# Build rule for unit test objects
Benjamin Huber's avatar
Benjamin Huber committed
287
ifdef USE_GCC
288
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS) build/.preCompileHeaders/xerus.h.gch build/.preCompileHeaders/common.hxx.gch
289
	mkdir -p $(dir $@)
290
	$(CXX) -D XERUS_UNITTEST -I build/.preCompileHeaders $< -c $(FLAGS) -MMD -o $@
291
else
292
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS)
293
	mkdir -p $(dir $@)
294
	$(CXX) -D XERUS_UNITTEST -I include -I src/unitTests $< -c $(FLAGS) -MMD -o $@
295
endif
Baum's avatar
Baum committed
296

297

298
# Build and execution rules for tutorials
Ben Huber's avatar
Ben Huber committed
299
build/.tutorialObjects/%: %.cpp $(MINIMAL_DEPS) build/libxerus.a build/libxerus_misc.a
300
	mkdir -p $(dir $@)
Michael Goette's avatar
Michael Goette committed
301
	$(CXX) -I include $< build/libxerus.a build/libxerus_misc.a $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) $(CALLSTACK_LIBS) $(FLAGS) -MMD -o $@
302

303

304
# Build rule for the preCompileHeader
305
build/.preCompileHeaders/xerus.h.gch: include/xerus.h $(MINIMAL_DEPS) .git/ORIG_HEAD
306
	mkdir -p $(dir $@)
307
	$(CXX) -D XERUS_UNITTEST $< -c $(FLAGS) -MMD -o $@
308

309

310
311
312
313
314
315
# Build rule for the other preCompileHeader
build/.preCompileHeaders/common.hxx.gch: src/unitTests/common.hxx $(MINIMAL_DEPS) .git/ORIG_HEAD
	mkdir -p $(dir $@)
	$(CXX) -D XERUS_UNITTEST $< -c $(FLAGS) -MMD -o $@


316
317
318
319
320
# dummy rule in case files were downloaded without git
.git/ORIG_HEAD:
	mkdir -p .git
	touch .git/ORIG_HEAD