Makefile 15.1 KB
Newer Older
1
.PHONY: help version opt-flags warn-flags 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
help:
	@printf "Possible make targets are:\n \
8
9
10
11
12
13
14
15
16
17
18
	\thelp        --  Print this help message.\n \
	\tversion     --  Print the version of xerus.\n \
	\topt-flags   --  List optimizations used by the compiler.\n \
	\twarn-flags  --  List warnings generated by the compiler.\n \
	\tshared      --  Build xerus as a shared library.\n \
	\tstatic      --  Build xerus as a static library.\n \
	\tpython      --  Build the xerus python3 wrappers.\n \
	\tdoc         --  Build the html documentation for the xerus library.\n \
	\tinstall     --  Install the shared library and header files (may require root).\n \
	\ttest        --  Build and run the xerus unit tests.\n \
	\tclean       --  Remove all object, library and executable files.\n"
Baum's avatar
Baum committed
19

20

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

# Name of the test executable
26
27
TEST_NAME = XerusTest_static
# TEST_NAME = XerusTest_dynamic
Baum's avatar
Baum committed
28

Fuchsi*'s avatar
Fuchsi* committed
29

30
# ------------------------------------------------------------------------------------------------------
31
#			Extract Xerus version from VERSION file
32
33
# ------------------------------------------------------------------------------------------------------

34
VERSION_STRING = $(shell cat VERSION)
35
36
37
VERSION = -D XERUS_VERSION="$(VERSION_STRING)"

XERUS_MAJOR_V = $(word 1, $(subst ., ,$(VERSION_STRING)) )
38
39
40
ifneq (,$(findstring v, $(XERUS_MAJOR_V)))
	XERUS_MAJOR_V := $(strip $(subst v, ,$(XERUS_MAJOR_V)) )
endif
41
VERSION += -D XERUS_VERSION_MAJOR=$(XERUS_MAJOR_V)
42
XERUS_MINOR_V = $(word 2, $(subst ., ,$(VERSION_STRING)))
43
VERSION += -D XERUS_VERSION_MINOR=$(XERUS_MINOR_V)
44
XERUS_REVISION_V = $(word 3, $(subst ., ,$(VERSION_STRING)))
45
ifneq (,$(findstring -, $(XERUS_REVISION_V)))
46
47
	XERUS_COMMIT_V := $(word 2, $(subst -, ,$(XERUS_REVISION_V)))
	XERUS_REVISION_V := $(word 1, $(subst -, ,$(XERUS_REVISION_V)))
48
49
50
else
	XERUS_COMMIT_V = 0
endif
51
52
VERSION += -D XERUS_VERSION_REVISION=$(XERUS_REVISION_V)
VERSION += -D XERUS_VERSION_COMMIT=$(XERUS_COMMIT_V)
53

Philipp  Trunschke's avatar
Philipp Trunschke committed
54
version:
55
	@echo $(XERUS_MAJOR_V).$(XERUS_MINOR_V).$(XERUS_REVISION_V).$(XERUS_COMMIT_V)
56

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

61
62
63
# Register the source files
XERUS_SOURCES = $(wildcard src/xerus/*.cpp)
XERUS_SOURCES += $(wildcard src/xerus/algorithms/*.cpp)
64
XERUS_SOURCES += $(wildcard src/xerus/applications/*.cpp)
65
XERUS_SOURCES += $(wildcard src/xerus/examples/*.cpp)
66
67
68
69
70
71
72
# 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)
73
74
75

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

76
77
MISC_INCLUDES = $(wildcard include/xerus/misc/*.h)

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

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

Fuchsi*'s avatar
Fuchsi* committed
82
UNIT_TEST_SOURCES = $(wildcard src/unitTests/*.cxx)
83

84
85
TUTORIAL_SOURCES = $(wildcard tutorials/*.cpp)

86
# Create lists of the corresponding objects and dependency files
87
88
89
90
91
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)
92

Sebastian Wolf's avatar
Sebastian Wolf committed
93
94
# PYTHON_OBJECTS = $(PYTHON_SOURCES:%.cpp=build/.pythonObjects/%.o)
# PYTHON_DEPS    = $(PYTHON_SOURCES:%.cpp=build/.pyhtonObjects/%.d)
95
96
97

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

99
100
101
UNIT_TEST_OBJECTS = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.o)
UNIT_TEST_DEPS    = $(UNIT_TEST_SOURCES:%.cxx=build/.unitTestObjects/%.d)

102
TUTORIALS	= $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%)
103
104
TUTORIAL_DEPS   = $(TUTORIAL_SOURCES:%.cpp=build/.tutorialObjects/%.d)

Baum's avatar
Baum committed
105
106

# ------------------------------------------------------------------------------------------------------
107
#		Load the configurations provided by the user and set up general options
Baum's avatar
Baum committed
108
109
110
# ------------------------------------------------------------------------------------------------------
include config.mk

111
112
113
include makeIncludes/general.mk
include makeIncludes/warnings.mk
include makeIncludes/optimization.mk
Baum's avatar
Baum committed
114

115

Baum's avatar
Baum committed
116
# ------------------------------------------------------------------------------------------------------
117
#					Set additional compiler options
Baum's avatar
Baum committed
118
# ------------------------------------------------------------------------------------------------------
Sebastian Wolf's avatar
Sebastian Wolf committed
119
120
121
ifdef ACTIVATE_CODE_COVERAGE
	DEBUG += -D XERUS_TEST_COVERAGE
endif
122

123
# ------------------------------------------------------------------------------------------------------
124
#					Convinience variables
Baum's avatar
Baum committed
125
# ------------------------------------------------------------------------------------------------------
126

127
128
129
130
131
132
# Small hack to get newlines...
define \n


endef

133
134
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)
135
136
137
MINIMAL_DEPS = Makefile config.mk makeIncludes/general.mk makeIncludes/warnings.mk makeIncludes/optimization.mk


138
139
140
# ------------------------------------------------------------------------------------------------------
#					Load dependency files
# ------------------------------------------------------------------------------------------------------
141

142
143
144
145
146
147
-include $(XERUS_DEPS)
-include $(MISC_DEPS)
-include $(TEST_DEPS)
-include $(UNIT_TEST_DEPS)
-include $(TUTORIAL_DEPS)
-include build/.preCompileHeaders/xerus.h.d
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
# ------------------------------------------------------------------------------------------------------
#					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 @), \
180
                required by target '$@' (variable may be empty but must be defined))))
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

# 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:


199
# ------------------------------------------------------------------------------------------------------
200
#					Make Rules
201
202
# ------------------------------------------------------------------------------------------------------

203
204
opt-flags:
	@$(CXX) $(FLAGS) -Q --help=optimizers 2>/dev/null
205
206


207
208
warn-flags:
	@$(CXX) $(FLAGS) -Q --help=warnings 2>/dev/null
209
210


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

214
shared: build/libxerus_misc.so build/libxerus.so
215

216
217
218
.PHONY: libxerus_misc_dependencies
libxerus_misc_dependencies:
	@:$(call check_defined, BOOST_LIBS, include and link paths)
219
build/libxerus_misc.so: $(MINIMAL_DEPS) $(MISC_SOURCES) $(MISC_INCLUDES) | libxerus_misc_dependencies
220
	mkdir -p $(dir $@)
221
	$(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
222

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

230

231
python: xerus/xerus.so xerus/libxerus.so xerus/libxerus_misc.so
Philipp  Trunschke's avatar
Philipp Trunschke committed
232
233
234
235
236
237
238

xerus/xerus.so: build/python3/xerus.so
	cp $< $@
xerus/libxerus.so: build/libxerus.so
	cp $< $@
xerus/libxerus_misc.so: build/libxerus_misc.so
	cp $< $@
239

240
build/python3/xerus.so: $(MINIMAL_DEPS) $(PYTHON_SOURCES) src/xerus/python/misc.h build/libxerus.so
241
	@:$(call check_defined, PYTHON3_CONFIG, include and link paths)
242
	mkdir -p $(dir $@)
243
	$(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 $@
244

245

246
static: build/libxerus_misc.a build/libxerus.a
247

248
build/libxerus_misc.a: $(MINIMAL_DEPS) $(MISC_OBJECTS) | libxerus_misc_dependencies
249
	mkdir -p $(dir $@)
250
251
252
253
254
255
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
else
	ar rcs ./build/libxerus_misc.a $(MISC_OBJECTS)
endif

256
build/libxerus.a: $(MINIMAL_DEPS) $(XERUS_OBJECTS) | libxerus_dependencies
257
	mkdir -p $(dir $@)
258
259
260
261
ifdef USE_LTO
	gcc-ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
else
	ar rcs ./build/libxerus.a $(XERUS_OBJECTS)
Baum's avatar
Baum committed
262
263
endif

264

265
266
267
268
269
ifdef INSTALL_PYTHON2_PATH
install: build/python2/xerus.so
endif
ifdef INSTALL_PYTHON3_PATH
install: build/python3/xerus.so
270
endif
271
272
ifdef INSTALL_LIB_PATH
ifdef INSTALL_HEADER_PATH
273
install: shared
274
275
276
277
278
	@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)
Fuchsi*'s avatar
Fuchsi* committed
279
280
	cp build/libxerus_misc.so $(INSTALL_LIB_PATH)
	cp build/libxerus.so $(INSTALL_LIB_PATH)
281
282
ifdef INSTALL_PYTHON3_PATH
	@printf "Installing xerus.so to $(strip $(INSTALL_PYTHON3_PATH)).\n"
283
	mkdir -p $(INSTALL_PYTHON3_PATH)
284
	cp build/python3/xerus.so $(INSTALL_PYTHON3_PATH)
285
endif
286
else
287
install:
288
	@printf "Cannot install xerus: INSTALL_HEADER_PATH not set. Please set the path in config file.\n"
289
290
291
endif
else
install:
292
	@printf "Cannot install xerus: INSTALL_LIB_PATH not set.  Please set the path in config file.\n"
293
endif
294

295
XerusTest_static: $(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
296
	$(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)
297
298
299

XerusTest_dynamic: $(MINIMAL_DEPS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.so build/libxerus_misc.so | libxerus_misc_dependencies libxerus_dependencies
	$(CXX) -D XERUS_UNITTEST $(FLAGS) $(UNIT_TEST_OBJECTS) $(TEST_OBJECTS) build/libxerus.so build/libxerus_misc.so $(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
326
test: $(TEST_NAME)
Baum's avatar
Baum committed
327
	./$(TEST_NAME) all
Sebastian Wolf's avatar
Sebastian Wolf committed
328
endif
329

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


337
fullTest: $(TUTORIALS) $(TEST_NAME)
338
	$(foreach x,$(TUTORIALS),./$(x)$(\n))
339
	./$(TEST_NAME) all
340

341

Philipp  Trunschke's avatar
Philipp Trunschke committed
342
doc:
343
344
345
	make -C doc doc


346
347
348
349
clean:
	rm -fr build
	-rm -f $(TEST_NAME)
	-rm -f include/xerus.h.gch
Fuchsi*'s avatar
Fuchsi* committed
350
	make -C doc clean
351

352

Baum's avatar
Baum committed
353

354
355
# Build rule for normal misc objects
build/.miscObjects/%.o: %.cpp $(MINIMAL_DEPS)
356
	mkdir -p $(dir $@)
357
358
359
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@


360
361
# Build rule for normal lib objects
build/.libObjects/%.o: %.cpp $(MINIMAL_DEPS)
362
	mkdir -p $(dir $@)
363
	$(CXX) -I include $< -c $(FLAGS) -MMD -o $@
364

365

366
367
368
# Build rule for test lib objects
build/.testObjects/%.o: %.cpp $(MINIMAL_DEPS)
	mkdir -p $(dir $@)
369
	$(CXX) -D XERUS_UNITTEST -I include $< -c $(FLAGS) -MMD -o $@
370

371

372
# Build rule for unit test objects
Fuchsi*'s avatar
Fuchsi* committed
373
ifdef USE_GCC
374
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS) build/.preCompileHeaders/xerus.h.gch build/.preCompileHeaders/common.hxx.gch
375
	mkdir -p $(dir $@)
376
	$(CXX) -D XERUS_UNITTEST -I build/.preCompileHeaders $< -c $(FLAGS) -MMD -o $@
377
else
Fuchsi*'s avatar
Fuchsi* committed
378
build/.unitTestObjects/%.o: %.cxx $(MINIMAL_DEPS)
379
	mkdir -p $(dir $@)
380
	$(CXX) -D XERUS_UNITTEST -I include -I src/unitTests $< -c $(FLAGS) -MMD -o $@
381
endif
Baum's avatar
Baum committed
382

383

384
# Build and execution rules for tutorials
Fuchsi*'s avatar
Fuchsi* committed
385
build/.tutorialObjects/%: %.cpp $(MINIMAL_DEPS) build/libxerus.a build/libxerus_misc.a
386
	mkdir -p $(dir $@)
Sebastian Wolf's avatar
Sebastian Wolf committed
387
	$(CXX) -I include $< build/libxerus.a build/libxerus_misc.a $(SUITESPARSE) $(LAPACK_LIBRARIES) $(ARPACK_LIBRARIES) $(BLAS_LIBRARIES) $(BOOST_LIBS) $(CALLSTACK_LIBS) $(FLAGS) -MMD -o $@
388

389

390
# Build rule for the preCompileHeader
391
build/.preCompileHeaders/xerus.h.gch: include/xerus.h $(MINIMAL_DEPS) .git/ORIG_HEAD
392
	mkdir -p $(dir $@)
393
	$(CXX) -D XERUS_UNITTEST $< -c $(FLAGS) -MMD -o $@
394

395

396
397
398
399
400
401
# 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 $@


402
403
404
405
406
# dummy rule in case files were downloaded without git
.git/ORIG_HEAD:
	mkdir -p .git
	touch .git/ORIG_HEAD