forked from tvanderbruggen/SciCpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
215 lines (160 loc) · 5.81 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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# SPDX-License-Identifier: MIT
# Copyright (c) 2019-2021 Thomas Vanderbruggen <[email protected]>
MAJOR = 0
MINOR = 4
PATCH = 0
SCICPP_SRC=scicpp
TMP=tmp
COMPILER ?= clang
# COMPILER ?= gcc
CROSS_COMPILE =
ARCH_FLAGS = -march=native
OPTIM_FLAGS = -O3 -fno-math-errno # -ffast-math
DEBUG_FLAGS = #-g
INCLUDES = -I. -I$(SCICPP_SRC) -I./deps -I/opt/homebrew/Cellar/boost/1.85.0/include
WARNINGS = -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wpedantic
WARNINGS += -Wcast-align -Wunused -Woverloaded-virtual
WARNINGS += -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2
WARNINGS += -Wfloat-equal -Wsign-promo -Wdisabled-optimization #-Weffc++
ifeq ($(COMPILER),gcc)
CC = $(CROSS_COMPILE)gcc-8
CCXX = $(CROSS_COMPILE)g++-8
WARNINGS += -Wuseless-cast -Wlogical-op -Wduplicated-cond -Wsuggest-attribute=pure -Wsuggest-attribute=const
else
CC = $(CROSS_COMPILE)clang
CCXX = $(CROSS_COMPILE)clang
WARNINGS += -Wpessimizing-move -Wno-zero-length-array -Wextra-semi -Wreserved-id-macro -Wconversion -Wshadow-field
# WARNINGS += -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-documentation-unknown-command -Wno-newline-eof -ferror-limit=200
endif
CFLAGS += $(WARNINGS) $(ARCH_FLAGS) $(OPTIM_FLAGS) $(DEBUG_FLAGS) $(INCLUDES) -MMD -MP
CXXFLAGS = $(CFLAGS) -std=c++17 -pthread
LD_FLAGS = -lm # -lstdc++fs
ifeq ($(COMPILER),clang)
# CXXFLAGS += -stdlib=libc++ # No C++17 deduction guides for now
LD_FLAGS += -lstdc++
endif
all: test
.PHONY: setup_clang
setup_clang:
apt-get install -y clang libc++-dev clang-format
$(TMP)/%.o: %.cpp
@mkdir -p $(dir $@)
$(CCXX) -c $(CXXFLAGS) -o $@ $<
# -------------------------------------------------------------------------------------
# Tests
# -------------------------------------------------------------------------------------
TMP_TEST = $(TMP)/tests
TEST_TARGET = $(TMP_TEST)/test
CATCH_HPP = tests/catch.hpp
TEST_OBJ = $(TMP_TEST)/scicpp_test.o
TEST_MAIN_OBJ = $(TMP_TEST)/tests_main.o
TEST_DEP = $(subst .o,.d,$(TEST_OBJ))
-include $(TEST_DEP)
.PHONY: setup_test
setup_test: $(CATCH_HPP)
$(CATCH_HPP):
curl -L https://github.com/catchorg/Catch2/releases/download/v2.0.1/catch.hpp -o $(CATCH_HPP)
$(TEST_TARGET): $(TEST_OBJ) $(TEST_MAIN_OBJ)
$(CCXX) -o $@ $(TEST_OBJ) $(TEST_MAIN_OBJ) $(CXXFLAGS) $(LD_FLAGS) $(LIBS)
.PHONY: test
test: $(TEST_TARGET)
$< -s -r compact
.PHONY: clean_test
clean_test:
rm -rf $(TMP_TEST)
# -------------------------------------------------------------------------------------
# Benchmarks
# -------------------------------------------------------------------------------------
TMP_BCHMK = $(TMP)/benchmarks
BCHMK_TARGET = $(TMP_BCHMK)/benchmark
BCHMK_OBJ = $(TMP_BCHMK)/scicpp_benchmark.o
BCHMK_DEP = $(subst .o,.d,$(BCHMK_OBJ))
-include $(BCHMK_DEP)
BCHMK_CCXXFLAGS = $(ARCH_FLAGS) $(OPTIM_FLAGS) $(DEBUG_FLAGS) -std=c++17 -pthread -I. -Iscicpp -MMD -MP
# Don't compile Eigen runtime asserts
BCHMK_CCXXFLAGS += -DNDEBUG #-funsafe-loop-optimizations
$(BCHMK_OBJ): benchmarks/scicpp_benchmark.cpp
@mkdir -p $(dir $@)
$(CCXX) -c $(BCHMK_CCXXFLAGS) -o $@ $<
$(BCHMK_TARGET): $(BCHMK_OBJ)
$(CCXX) -o $@ $< $(BCHMK_CCXXFLAGS) $(LD_FLAGS) $(LIBS)
.PHONY: setup_benchmark
setup_benchmark:
apt-get install libboost-all-dev
.PHONY: benchmark
benchmark: $(BCHMK_TARGET)
$< -v -r html -o $(TMP_BCHMK)/results.html
firefox $(TMP_BCHMK)/results.html
.PHONY: clean_benchmark
clean_benchmark:
rm -rf $(TMP_BCHMK)
# -------------------------------------------------------------------------------------
# Release
# -------------------------------------------------------------------------------------
RELEASE_ZIP = $(TMP)/scicpp-$(MAJOR).$(MINOR).$(PATCH).zip
$(RELEASE_ZIP):
zip -r $@ $(SCICPP_SRC) -x *.cpp
.PHONY: release
release: $(RELEASE_ZIP)
.PHONY: clean_release
clean_release:
rm -rf $(RELEASE_ZIP)
# -------------------------------------------------------------------------------------
# Install
# -------------------------------------------------------------------------------------
INSTALL_PATH = /usr/include/
.PHONY: install
install:
rm -rf $(INSTALL_PATH)/scicpp
cp --parents `find -name \*.hpp*` $(INSTALL_PATH)
rm -rf $(INSTALL_PATH)/tests
# -------------------------------------------------------------------------------------
# Examples
# -------------------------------------------------------------------------------------
EXAMPLE := white-noise
EXAMPLE_TARGET = $(TMP)/examples/$(EXAMPLE)
EXAMPLE_OBJ = $(TMP)/examples/$(EXAMPLE).o
EXAMPLE_PY = examples/$(notdir $(basename $(EXAMPLE_OBJ))).py
EXAMPLE_DEP = $(subst .o,.d,$(EXAMPLE_OBJ))
-include $(EXAMPLE_DEP)
$(EXAMPLE_TARGET): $(EXAMPLE_OBJ)
$(CCXX) -o $@ $< $(CXXFLAGS) $(LD_FLAGS) $(LIBS)
# Build and run
.PHONY: example
example: $(EXAMPLE_TARGET)
$<
# Build only
.PHONY: example_build
example_build: $(EXAMPLE_TARGET)
.PHONY: example_py
example_py:
python $(EXAMPLE_PY)
.PHONY: clean_examples
clean_examples:
rm -rf $(TMP)/examples
# -------------------------------------------------------------------------------------
# clean all
# -------------------------------------------------------------------------------------
.PHONY: clean
clean:
rm -rf $(TMP)
# -------------------------------------------------------------------------------------
# Documentation
# -------------------------------------------------------------------------------------
.PHONY: setup_documentation
setup_documentation:
apt-get install -y python-sphinx
apt-get install -y doxygen
pip install sphinx-autobuild exhale breathe
pip install sphinx_bootstrap_theme
# -------------------------------------------------------------------------------------
# Tooling
# -------------------------------------------------------------------------------------
SCRIPT_TIDY_SH = scripts/tidy.sh
SCRIPT_FORMAT_SH = scripts/format.sh
.PHONY: tidy
tidy: $(SCRIPT_TIDY_SH)
bash $<
.PHONY: format
format: $(SCRIPT_FORMAT_SH)
bash $<