Makefile 15.3 KB
Newer Older
1
.PHONY: help shared static python2 python3 doc install test clean version 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
help:
	@printf "Possible make targets are:\n \
8
9
10
11
12
13
	\t\tversion \t -- Print the version of xerus.\n \
	\t\tshared  \t -- Build xerus as a shared library.\n \
	\t\tstatic  \t -- Build xerus as a static library.\n \
	\t\tpython2 \t -- Build the xerus python2 wrappers.\n \
	\t\tpython3 \t -- Build the xerus python3 wrappers.\n \
	\t\tdoc     \t -- Build the html documentation for the xerus library.\n \
14
	\t\tinstall \t -- Install the shared library and header files (may require root).\n \
15
16
	\t\ttest    \t -- Build and run the xerus unit tests.\n \
	\t\tclean   \t -- Remove all object, library and executable files.\n"
Baum's avatar
Baum committed
17

18

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

# Name of the test executable
TEST_NAME = XerusTest

Benjamin Huber's avatar
Benjamin Huber committed
26

27
# ------------------------------------------------------------------------------------------------------
Sebastian Wolf's avatar
Sebastian Wolf committed
28
#			Extract Xerus version from VERSION file and the git repository
29
30
31
32
33
34
# ------------------------------------------------------------------------------------------------------

VERSION_STRING = $(shell git describe --tags --always 2>/dev/null || cat VERSION)
VERSION = -D XERUS_VERSION="$(VERSION_STRING)"

XERUS_MAJOR_V = $(word 1, $(subst ., ,$(VERSION_STRING)) )
35
36
37
ifneq (,$(findstring v, $(XERUS_MAJOR_V)))
	XERUS_MAJOR_V := $(strip $(subst v, ,$(XERUS_MAJOR_V)) )
endif
38
39
40
41
VERSION += -D XERUS_VERSION_MAJOR=$(XERUS_MAJOR_V)
XERUS_MINOR_V = $(word 2, $(subst ., ,$(VERSION_STRING)) )
VERSION += -D XERUS_VERSION_MINOR=$(XERUS_MINOR_V)
XERUS_REVISION_V = $(word 3, $(subst ., ,$(VERSION_STRING)) )
42
43
44
45
46
47
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
48
49
VERSION += -D XERUS_VERSION_REVISION=$(XERUS_REVISION_V)
VERSION += -D XERUS_VERSION_COMMIT=$(XERUS_COMMIT_V)
50

51

Baum's avatar
Baum committed
52
# ------------------------------------------------------------------------------------------------------
53
#				Register source files for the xerus library
Baum's avatar
Baum committed
54
55
# ------------------------------------------------------------------------------------------------------

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

XERUS_INCLUDES =  $(wildcard include/xerus/*.h)
XERUS_INCLUDES += $(wildcard include/xerus/algorithms/*.h)
XERUS_INCLUDES += $(wildcard include/xerus/applications/*.h)
XERUS_INCLUDES += $(wildcard include/xerus/examples/*.h)
# XERUS_INCLUDES = $(wildcard include/xerus/**/*.h)
68
69
70

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

71
72
MISC_INCLUDES = $(wildcard include/xerus/misc/*.h)

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

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

77
UNIT_TEST_SOURCES = $(wildcard src/unitTests/*.cxx)
78

79
80
TUTORIAL_SOURCES = $(wildcard tutorials/*.cpp)

81
# Create lists of the corresponding objects and dependency files
82
83
84
85
86
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)
87

Sebastian Wolf's avatar
Sebastian Wolf committed
88
89
# PYTHON_OBJECTS = $(PYTHON_SOURCES:%.cpp=build/.pythonObjects/%.o)
# PYTHON_DEPS    = $(PYTHON_SOURCES:%.cpp=build/.pyhtonObjects/%.d)
90
91
92

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

94
95
96
UNIT_TEST_OBJECTS = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.o)
UNIT_TEST_DEPS    = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.d)

97
TUTORIALS	= $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%)
98
99
TUTORIAL_DEPS   = $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%.d)

Baum's avatar
Baum committed
100
101

# ------------------------------------------------------------------------------------------------------
102
#		Load the configurations provided by the user and set up general options
Baum's avatar
Baum committed
103
104
105
# ------------------------------------------------------------------------------------------------------
include config.mk

106
107
108
include makeIncludes/general.mk
include makeIncludes/warnings.mk
include makeIncludes/optimization.mk
Baum's avatar
Baum committed
109

110

Baum's avatar
Baum committed
111
# ------------------------------------------------------------------------------------------------------
112
#					Set additional compiler options
Baum's avatar
Baum committed
113
# ------------------------------------------------------------------------------------------------------
Sebastian Wolf's avatar
Sebastian Wolf committed
114
115
116
ifdef ACTIVATE_CODE_COVERAGE
	DEBUG += -D XERUS_TEST_COVERAGE
endif
117

118
# ------------------------------------------------------------------------------------------------------
119
#					Convinience variables
Baum's avatar
Baum committed
120
# ------------------------------------------------------------------------------------------------------
121

122
123
124
125
126
127
# Small hack to get newlines...
define \n


endef

128
129
FLAGS = $(strip $(COMPATIBILITY) $(WARNINGS) $(OPTIMIZE) $(VERSION) $(LOGGING) $(DEBUG) $(ADDITIONAL_INCLUDE) $(OTHER))
PYTHON_FLAGS = $(strip $(COMPATIBILITY) $(WARNINGS) $(VERSION) $(LOGGING) $(DEBUG) $(ADDITIONAL_INCLUDE) $(OTHER) -fno-var-tracking-assignments)
130
131
132
MINIMAL_DEPS = Makefile config.mk makeIncludes/general.mk makeIncludes/warnings.mk makeIncludes/optimization.mk


133
134
135
# ------------------------------------------------------------------------------------------------------
#					Load dependency files
# ------------------------------------------------------------------------------------------------------
136

137
138
139
140
141
142
-include $(XERUS_DEPS)
-include $(MISC_DEPS)
-include $(TEST_DEPS)
-include $(UNIT_TEST_DEPS)
-include $(TUTORIAL_DEPS)
-include build/.preCompileHeaders/xerus.h.d
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
# ------------------------------------------------------------------------------------------------------
#					Custom functions
# ------------------------------------------------------------------------------------------------------

# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# Params:
#   1. Variable name(s) to test.
#   2. (optional) Error message to print.
check_defined = \
	$(strip $(foreach 1,$1, \
		$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
	$(if $(value $1),, \
		$(error Undefined $1$(if $2, ($2))$(if $(value @), \
				required by target `$@')))

# Check that given variables are declared (they may have empty values),
# die with an error otherwise.
#
# Params:
#   1. Variable name(s) to test.
#   2. (optional) Error message to print.
check_declared = \
	$(strip $(foreach 1,$1, \
		$(call __check_defined,$1,$(strip $(value 2)))))
__check_declared = \
	$(if $(filter undefined,$(origin $1)), \
		$(error Undeclared $1$(if $2, ($2))$(if $(value @), \
175
                required by target '$@' (variable may be empty but must be defined))))
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

# Check that a variable specified through the stem is defined and has
# a non-empty value, die with an error otherwise.
#
#   %: The name of the variable to test.
#
check-defined-%: __check_defined_FORCE
    @:$(call check_defined, $*, target-specific)

# Since pattern rules can't be listed as prerequisites of .PHONY,
# we use the old-school and hackish FORCE workaround.
# You could go without this, but otherwise a check can be missed
# in case a file named like `check-defined-...` exists in the root
# directory, e.g. left by an accidental `make -t` invocation.
.PHONY: __check_defined_FORCE
__check_defined_FORCE:


194
# ------------------------------------------------------------------------------------------------------
195
#					Make Rules
196
197
# ------------------------------------------------------------------------------------------------------

Sebastian Wolf's avatar
Sebastian Wolf committed
198
199
opt:
	$(CXX) $(FLAGS) -Q --help=optimizers
200
201
202
203
204
205


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


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

209
shared: build/libxerus_misc.so build/libxerus.so
210

211
212
213
.PHONY: libxerus_misc_dependencies
libxerus_misc_dependencies:
	@:$(call check_defined, BOOST_LIBS, include and link paths)
214
build/libxerus_misc.so: $(MINIMAL_DEPS) $(MISC_SOURCES) $(MISC_INCLUDES) | libxerus_misc_dependencies
215
	mkdir -p $(dir $@)
216
	$(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
217

218
219
220
.PHONY: libxerus_dependencies
libxerus_dependencies:
	@:$(call check_defined, SUITESPARSE LAPACK_LIBRARIES BLAS_LIBRARIES, include and link paths)
221
build/libxerus.so: $(MINIMAL_DEPS) $(XERUS_SOURCES) $(XERUS_INCLUDES) build/libxerus_misc.so | libxerus_dependencies
222
	mkdir -p $(dir $@)
Michael Goette's avatar
Michael Goette committed
223
	$(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
224

225

Philipp  Trunschke's avatar
Philipp Trunschke committed
226
227
python2: build/python2/xerus.so
python3: build/python3/xerus.so
228

229
build/python2/xerus.so: $(MINIMAL_DEPS) $(PYTHON_SOURCES) src/xerus/python/misc.h build/libxerus.so
230
	@:$(call check_defined, PYTHON2_CONFIG, include and link paths)
231
	mkdir -p $(dir $@)
232
	$(CXX) -shared -fPIC -Wl,-soname,xerus.so $(PYTHON2_CONFIG) $(PYTHON_FLAGS) -I include -I 3rdParty/pybind11/include $(PYTHON_SOURCES) -L ./build/ -Wl,--as-needed -lxerus -o $@
233

234
build/python3/xerus.so: $(MINIMAL_DEPS) $(PYTHON_SOURCES) src/xerus/python/misc.h build/libxerus.so
235
	@:$(call check_defined, PYTHON3_CONFIG, include and link paths)
236
	mkdir -p $(dir $@)
237
	$(CXX) -shared -fPIC -Wl,-soname,xerus.so $(PYTHON3_CONFIG) $(PYTHON_FLAGS) -I include -I 3rdParty/pybind11/include $(PYTHON_SOURCES) -L ./build/ -Wl,--as-needed -lxerus -o $@
238

239

240
static: build/libxerus_misc.a build/libxerus.a
241

242
build/libxerus_misc.a: $(MINIMAL_DEPS) $(MISC_OBJECTS) | libxerus_misc_dependencies
243
	mkdir -p $(dir $@)
244
245
246
247
248
249
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
else
	ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
endif

250
build/libxerus.a: $(MINIMAL_DEPS) $(XERUS_OBJECTS) | libxerus_dependencies
251
	mkdir -p $(dir $@)
252
253
254
255
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
else
	ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
Baum's avatar
Baum committed
256
257
endif

258

259
260
261
262
263
ifdef INSTALL_PYTHON2_PATH
install: build/python2/xerus.so
endif
ifdef INSTALL_PYTHON3_PATH
install: build/python3/xerus.so
264
endif
265
266
ifdef INSTALL_LIB_PATH
ifdef INSTALL_HEADER_PATH
267
install: shared
268
269
	test -d $(strip $(INSTALL_LIB_PATH));
	test -d $(strip $(INSTALL_HEADER_PATH));
270
	@printf "Installing libxerus.so to $(strip $(INSTALL_LIB_PATH)) and storing the header files in $(strip $(INSTALL_HEADER_PATH)).\n"
271
272
273
274
275
276
277
278
ifdef INSTALL_PYTHON2_PATH
	test -d $(strip $(INSTALL_PYTHON2_PATH));
	@printf "Installing python2/xerus.so to $(strip $(INSTALL_PYTHON2_PATH)).\n"
endif
ifdef INSTALL_PYTHON3_PATH
	test -d $(strip $(INSTALL_PYTHON3_PATH));
	@printf "Installing python3/xerus.so to $(strip $(INSTALL_PYTHON3_PATH)).\n"
endif
279
280
	cp include/xerus.h $(INSTALL_HEADER_PATH)
	cp -r include/xerus $(INSTALL_HEADER_PATH)
Ben Huber's avatar
Ben Huber committed
281
282
	cp build/libxerus_misc.so $(INSTALL_LIB_PATH)
	cp build/libxerus.so $(INSTALL_LIB_PATH)
283
284
285
286
287
ifdef INSTALL_PYTHON2_PATH
	cp build/python2/xerus.so $(INSTALL_PYTHON2_PATH)
endif
ifdef INSTALL_PYTHON3_PATH
	cp build/python3/xerus.so $(INSTALL_PYTHON3_PATH)
288
endif
289
else
290
install:
291
	@printf "Cannot install xerus: INSTALL_HEADER_PATH not set. Please set the path in config file.\n"
292
293
294
endif
else
install:
295
	@printf "Cannot install xerus: INSTALL_LIB_PATH not set.  Please set the path in config file.\n"
296
endif
297

298
$(TEST_NAME): $(MINIMAL_DEPS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.a build/libxerus_misc.a | libxerus_misc_dependencies libxerus_dependencies
Sebastian Wolf's avatar
Sebastian Wolf committed
299
	$(CXX) -D XERUS_UNITTEST $(FLAGS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.a build/libxerus_misc.a $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) $(BOOST_LIBS) $(CALLSTACK_LIBS) -o $(TEST_NAME)
Baum's avatar
Baum committed
300

301
302
303
304
305
build/print_boost_version: src/print_boost_version.cpp
	@$(CXX) -o $@ $<

printBoostVersion: build/print_boost_version
	@build/print_boost_version
306

Sebastian Wolf's avatar
Sebastian Wolf committed
307
ifdef ACTIVATE_CODE_COVERAGE
308
ifdef BROCKEN_CI
Sebastian Wolf's avatar
Sebastian Wolf committed
309
310
test:
	mkdir -p build
311
	make $(TEST_NAME)
312
	@cat build/build_output.txt | grep "REQUIRE_TEST @" > build/required_tests.txt
Sebastian Wolf's avatar
Sebastian Wolf committed
313
314
	./$(TEST_NAME) all
else
315
316
317
318

MAKE_PID := $(shell echo $$PPID)
JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))

319
320
test:
	mkdir -p build
321
	make $(TEST_NAME) $(JOB_FLAG) &> build/build_output.txt || cat build/build_output.txt
322
	@cat build/build_output.txt | grep "REQUIRE_TEST @" > build/required_tests.txt
323
324
325
	./$(TEST_NAME) all
endif
else
Baum's avatar
Baum committed
326
327
test:  $(TEST_NAME)
	./$(TEST_NAME) all
Sebastian Wolf's avatar
Sebastian Wolf committed
328
endif
329
330


331
332
.PHONY: test_python2_dependencies
test_python2_dependencies:
333
	@:$(call check_defined, PYTEST2, pytest executable)
334
test_python2: build/libxerus.so build/python2/xerus.so | test_python2_dependencies
Philipp  Trunschke's avatar
Philipp Trunschke committed
335
336
	@PYTHONPATH=build/python2:${PYTHONPATH} LD_LIBRARY_PATH=build:${LD_LIBRARY_PATH} $(PYTEST2) src/pyTests

337
338
.PHONY: test_python3_dependencies
test_python3_dependencies:
339
	@:$(call check_defined, PYTEST3, pytest executable)
340
test_python3: build/libxerus.so build/python3/xerus.so | test_python3_dependencies
Philipp  Trunschke's avatar
Philipp Trunschke committed
341
	@PYTHONPATH=build/python3:${PYTHONPATH} LD_LIBRARY_PATH=build:${LD_LIBRARY_PATH} $(PYTEST3) src/pyTests
342
343


344
fullTest: $(TUTORIALS) $(TEST_NAME)
345
	$(foreach x,$(TUTORIALS),./$(x)$(\n))
346
	./$(TEST_NAME) all
347

348

Philipp  Trunschke's avatar
Philipp Trunschke committed
349
doc:
350
351
352
	make -C doc doc


353
354
355
356
clean:
	rm -fr build
	-rm -f $(TEST_NAME)
	-rm -f include/xerus.h.gch
Ben Huber's avatar
Ben Huber committed
357
	make -C doc clean
358

359
version:
Philipp Trunschke's avatar
Philipp Trunschke committed
360
	@echo $(XERUS_MAJOR_V).$(XERUS_MINOR_V).$(XERUS_REVISION_V)
361

362

Baum's avatar
Baum committed
363

364
365
# Build rule for normal misc objects
build/.miscObjects/%.o: %.cpp $(MINIMAL_DEPS)
366
	mkdir -p $(dir $@)
367
368
369
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@


370
371
# Build rule for normal lib objects
build/.libObjects/%.o: %.cpp $(MINIMAL_DEPS)
372
	mkdir -p $(dir $@)
373
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@
374

375

376
377
378
# Build rule for test lib objects
build/.testObjects/%.o: %.cpp $(MINIMAL_DEPS)
	mkdir -p $(dir $@)
379
	$(CXX) -D XERUS_UNITTEST -I include $< -c $(FLAGS) -MMD -o $@
380

381

382
# Build rule for unit test objects
Benjamin Huber's avatar
Benjamin Huber committed
383
ifdef USE_GCC
384
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS) build/.preCompileHeaders/xerus.h.gch build/.preCompileHeaders/common.hxx.gch
385
	mkdir -p $(dir $@)
386
	$(CXX) -D XERUS_UNITTEST -I build/.preCompileHeaders $< -c $(FLAGS) -MMD -o $@
387
else
388
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS)
389
	mkdir -p $(dir $@)
390
	$(CXX) -D XERUS_UNITTEST -I include -I src/unitTests $< -c $(FLAGS) -MMD -o $@
391
endif
Baum's avatar
Baum committed
392

393

394
# Build and execution rules for tutorials
Ben Huber's avatar
Ben Huber committed
395
build/.tutorialObjects/%: %.cpp $(MINIMAL_DEPS) build/libxerus.a build/libxerus_misc.a
396
	mkdir -p $(dir $@)
Sebastian Wolf's avatar
Sebastian Wolf committed
397
	$(CXX) -I include $< build/libxerus.a build/libxerus_misc.a $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) $(BOOST_LIBS) $(CALLSTACK_LIBS) $(FLAGS) -MMD -o $@
398

399

400
# Build rule for the preCompileHeader
401
build/.preCompileHeaders/xerus.h.gch: include/xerus.h $(MINIMAL_DEPS) .git/ORIG_HEAD
402
	mkdir -p $(dir $@)
403
	$(CXX) -D XERUS_UNITTEST $< -c $(FLAGS) -MMD -o $@
404

405

406
407
408
409
410
411
# 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 $@


412
413
414
415
416
# dummy rule in case files were downloaded without git
.git/ORIG_HEAD:
	mkdir -p .git
	touch .git/ORIG_HEAD