-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
321 lines (262 loc) · 9.92 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
###############################################################################
# Makefile options: Edit here or specify on command-line (e.g. make STATIC=yes)
# Installation destinations
PREFIX := /usr/local
## Optional features; comment out or set to value other than 'yes' to disable
# Generate statically linked binary
STATIC := no
# Use libdeflate for block compression
LIBDEFLATE := yes
# Show individual commands during build; otherwise shows summaries instead.
VERBOSE := no
# Use of colored output during build (yes/no/auto)
COLOR := auto
# Debug build; adds warnings and debugging symbols
DEBUG := no
# Include coverage instrumentation in build
COVERAGE := no
# Enable address and undefined behavior sanitation
SANITIZE := no
###############################################################################
# Makefile internals. Normally you do not need to touch these.
EXEC_MAIN := adapterremoval3
EXEC_TEST := unit_tests
BUILD_DIR := build
OBJS_DIR := $(BUILD_DIR)/objects
COV_DIR := $(BUILD_DIR)/coverage
DOCS_DIR := $(BUILD_DIR)/docs
MAN_PAGE := $(DOCS_DIR)/man/$(EXEC_MAIN).1
REGRESSION_TESTS := tests/regression
REGRESSION_DIR := $(BUILD_DIR)/regression
INSTALLEXE = install -m 0755
INSTALLDAT = install -m 0644
INSTALLDOC = install -m 0644
MKDIR = install -d # act as mkdir -p
# Default compilation flags
CXXFLAGS := ${CXXFLAGS} -std=c++14 -O3
LDLIBS := -pthread -lisal -ldeflate ${LDLIBS}
LDFLAGS := ${LDFLAGS}
ifeq ($(strip ${VERBOSE}),no)
QUIET := @
endif
ifeq ($(strip ${COLOR}),auto)
ifeq (${NO_COLOR},)
ifneq ($(strip $(MAKE_TERMOUT)),)
COLOR := yes
endif
endif
endif
ifeq ($(strip ${COLOR}),yes)
COLOR_YELLOW := "\033[0;33m"
COLOR_GREEN := "\033[0;32m"
COLOR_CYAN := "\033[0;36m"
COLOR_END := "\033[0m"
else
COLOR := no
endif
BUILD_NAME := release
BUILD_NAME_PREFIX :=
BUILD_NAME_POSTFIX :=
ifeq ($(strip ${STATIC}),yes)
$(info Building static AdapterRemoval binary: yes)
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58909
LDFLAGS := $(LDFLAGS) -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -static
OBJS_DIR := $(BUILD_DIR)/static
EXECUTABLE := $(BUILD_DIR)/$(EXEC_MAIN).static
BUILD_NAME_PREFIX := static-
else
$(info Building static AdapterRemoval binary: no)
endif
ifeq ($(strip ${COVERAGE}), yes)
$(info Building AdapterRemoval with coverage instrumentation: yes)
CXXFLAGS := ${CXXFLAGS} --coverage
DEBUG := yes
BUILD_NAME := coverage
else
$(info Building AdapterRemoval with coverage instrumentation: no)
endif
ifeq ($(strip ${DEBUG}), yes)
$(info Building AdapterRemoval with debug information: yes)
CXXFLAGS := ${CXXFLAGS} -g -DDEBUG \
-pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy \
-Wdisabled-optimization -Wformat=2 -Winit-self -Wold-style-cast \
-Woverloaded-virtual -Wredundant-decls -Wsign-promo -Wstrict-overflow=2 \
-Wswitch-default -Wundef -Weffc++ -Wdeprecated
ifneq ($(strip ${COVERAGE}), yes)
BUILD_NAME := debug
endif
else
$(info Building AdapterRemoval with debug information: no)
endif
ifeq ($(strip ${SANITIZE}), yes)
$(info Building AdapterRemoval with sanitizers: yes)
CXXFLAGS := ${CXXFLAGS} -fno-sanitize-recover=all -fsanitize=undefined,address
ifeq ($(findstring clang,${CXX}),)
LDLIBS := $(LDLIBS) -lasan
endif
BUILD_NAME_POSTFIX := ${BUILD_NAME_POSTFIX}-sanitize
else
$(info Building AdapterRemoval with sanitizers: no)
endif
# Use a different folder for each build configuration
BUILD_NAME := $(BUILD_NAME_PREFIX)$(BUILD_NAME)$(BUILD_NAME_POSTFIX)
EXECUTABLE := $(BUILD_DIR)/$(BUILD_NAME)/$(EXEC_MAIN)
TEST_RUNNER := $(BUILD_DIR)/$(BUILD_NAME)/$(EXEC_TEST)
OBJS_DIR := $(BUILD_DIR)/$(BUILD_NAME)
$(info Build configuration: $(BUILD_NAME))
################################################################################
# Build objects shared between unit tests and executable
CORE_OBJS := \
$(OBJS_DIR)/alignment_tables.o \
$(OBJS_DIR)/alignment.o \
$(OBJS_DIR)/argparse.o \
$(OBJS_DIR)/barcode_table.o \
$(OBJS_DIR)/debug.o \
$(OBJS_DIR)/fastq_enc.o \
$(OBJS_DIR)/fastq.o \
$(OBJS_DIR)/json.o \
$(OBJS_DIR)/linereader.o \
$(OBJS_DIR)/logging.o \
$(OBJS_DIR)/managed_writer.o \
$(OBJS_DIR)/mathutils.o \
$(OBJS_DIR)/simd_avx2.o \
$(OBJS_DIR)/simd_avx512bw.o \
$(OBJS_DIR)/simd_sse2.o \
$(OBJS_DIR)/simd_std.o \
$(OBJS_DIR)/simd.o \
$(OBJS_DIR)/strutils.o \
$(OBJS_DIR)/utilities.o
# Build objects used only by the executable
EXEC_OBJS := \
$(OBJS_DIR)/adapter_id.o \
$(OBJS_DIR)/adapterset.o \
$(OBJS_DIR)/benchmarking.o \
$(OBJS_DIR)/demultiplexing.o \
$(OBJS_DIR)/fastq_io.o \
$(OBJS_DIR)/linereader_joined.o \
$(OBJS_DIR)/main_adapter_id.o \
$(OBJS_DIR)/main_adapter_rm.o \
$(OBJS_DIR)/main_benchmark.o \
$(OBJS_DIR)/main_demultiplex.o \
$(OBJS_DIR)/main.o \
$(OBJS_DIR)/reports_html.o \
$(OBJS_DIR)/reports_json.o \
$(OBJS_DIR)/reports_terminal.o \
$(OBJS_DIR)/reports_template_html.o \
$(OBJS_DIR)/scheduler.o \
$(OBJS_DIR)/statistics.o \
$(OBJS_DIR)/threads.o \
$(OBJS_DIR)/timer.o \
$(OBJS_DIR)/progress.o \
$(OBJS_DIR)/trimming.o \
$(OBJS_DIR)/userconfig.o
# Build objects used only by the test runner
TEST_OBJS := \
$(OBJS_DIR)/alignment_test.o \
$(OBJS_DIR)/argparse_test.o \
$(OBJS_DIR)/barcodes_test.o \
$(OBJS_DIR)/buffer_test.o \
$(OBJS_DIR)/counts_test.o \
$(OBJS_DIR)/debug_test.o \
$(OBJS_DIR)/fastq_test.o \
$(OBJS_DIR)/json_test.o \
$(OBJS_DIR)/linereader_test.o \
$(OBJS_DIR)/logging_test.o \
$(OBJS_DIR)/main_test.o \
$(OBJS_DIR)/mathutils_test.o \
$(OBJS_DIR)/strutils_test.o \
$(OBJS_DIR)/utilities_test.o
################################################################################
.PHONY: all clean docs man everything examples install regression test
all: $(EXECUTABLE)
clean:
@echo $(COLOR_GREEN)"Cleaning"$(COLOR_END)
$(QUIET) rm -rf $(BUILD_DIR)
$(QUIET) make -C examples clean
everything: all test regression docs examples
examples: $(EXECUTABLE)
@echo $(COLOR_GREEN)"Running examples"$(COLOR_END)
$(QUIET) make -C examples EXE=$(CURDIR)/$(EXECUTABLE)
install: $(EXECUTABLE) $(MAN_PAGE)
@echo $(COLOR_GREEN)"Installing AdapterRemoval .."$(COLOR_END)
@echo $(COLOR_GREEN)" .. binary into ${DESTDIR}${PREFIX}/bin/"$(COLOR_END)
$(QUIET) $(MKDIR) ${DESTDIR}${PREFIX}/bin/
$(QUIET) $(INSTALLEXE) $(EXECUTABLE) ${DESTDIR}${PREFIX}/bin/
@echo $(COLOR_GREEN)" .. man-page into ${DESTDIR}${PREFIX}/share/man/man1/"$(COLOR_END)
$(QUIET) $(MKDIR) ${DESTDIR}${PREFIX}/share/man/man1/
$(QUIET) $(INSTALLDOC) "$(MAN_PAGE)" ${DESTDIR}${PREFIX}/share/man/man1/
@echo $(COLOR_GREEN)" .. README into ${DESTDIR}${PREFIX}/share/adapterremoval3/"$(COLOR_END)
$(QUIET) $(MKDIR) ${DESTDIR}${PREFIX}/share/adapterremoval3/
$(QUIET) $(INSTALLDOC) README.md ${DESTDIR}${PREFIX}/share/adapterremoval3/
@echo $(COLOR_GREEN)" .. examples into ${DESTDIR}${PREFIX}/share/adapterremoval3/examples/"$(COLOR_END)
$(QUIET) $(MKDIR) ${DESTDIR}${PREFIX}/share/adapterremoval3/examples/
$(QUIET) $(INSTALLDAT) examples/Makefile examples/*.* ${DESTDIR}${PREFIX}/share/adapterremoval3/examples/
# HTML report templates
.INTERMEDIATE: src/reports_template.intermediate
src/reports_template_html.hpp src/reports_template_html.cpp: src/reports_template.intermediate ;
src/reports_template.intermediate: src/reports_template.html scripts/html_template_to_cpp.py
@echo $(COLOR_CYAN)"Building HTML templates from $<"$(COLOR_END)
$(QUIET) python3 scripts/html_template_to_cpp.py $< src/reports_template_html
regression: $(EXECUTABLE)
@echo $(COLOR_GREEN)"Running regression tests"$(COLOR_END)
$(QUIET) $(MKDIR) $(REGRESSION_DIR)
$(QUIET) python3 scripts/regression_test_runner.py $(REGRESSION_DIR) $(REGRESSION_TESTS) \
--json-schema "schema.json" \
--executable $(EXECUTABLE)
test: $(TEST_RUNNER)
@echo $(COLOR_GREEN)"Running unit tests"$(COLOR_END)
$(QUIET) $(TEST_RUNNER) --invisibles --use-colour $(COLOR)
ifeq ($(strip ${COVERAGE}), yes)
ifneq ($(shell which gcovr), )
@echo $(COLOR_GREEN)"Running coverage analysis"$(COLOR_END)
$(QUIET) mkdir -p "$(COV_DIR)"
$(QUIET) gcovr \
--txt $(COV_DIR)/index.txt \
--xml $(COV_DIR)/coverage.xml \
--exclude-throw-branches \
--exclude-lines-by-pattern ".*\\sREQUIRE[_A-Z]*\\(.*" \
--sort-percentage \
--exclude tests/unit/catch.hpp \
--html-details $(COV_DIR)/index.html \
--delete
$(QUIET) cat "$(COV_DIR)/index.txt"
else
@echo $(COLOR_YELLOW)"Cannot analyse coverage: gcovr not found"$(COLOR_END)
endif
endif
$(EXECUTABLE): $(CORE_OBJS) $(EXEC_OBJS)
@echo $(COLOR_GREEN)"Linking executable $@"$(COLOR_END)
$(QUIET) $(CXX) $(CXXFLAGS) ${LDFLAGS} $^ ${LDLIBS} -o $@
$(TEST_RUNNER): $(CORE_OBJS) $(TEST_OBJS)
@echo $(COLOR_GREEN)"Linking executable $@"$(COLOR_END)
$(QUIET) $(CXX) $(CXXFLAGS) ${LDFLAGS} $^ ${LDLIBS} -o $@
# Main object files
$(OBJS_DIR)/%.o: src/%.cpp
@echo $(COLOR_CYAN)"Building $@ from $<"$(COLOR_END)
$(QUIET) $(MKDIR) $(OBJS_DIR)
$(QUIET) $(CXX) $(CXXFLAGS) -pthread -c -MMD -MQ $@ -MF $(@:.o=.d) -o $@ $<
# Objects built with support for specific CPU instructions
$(OBJS_DIR)/simd_avx2.o $(OBJS_DIR)/simd_avx512bw.o $(OBJS_DIR)/simd_sse2.o : $(OBJS_DIR)/simd_%.o: src/simd_%.cpp
@echo $(COLOR_CYAN)"Building $@ from $< (-m$*)"$(COLOR_END)
$(QUIET) $(MKDIR) $(OBJS_DIR)
$(QUIET) $(CXX) $(CXXFLAGS) -pthread -c -MMD -MQ $@ -MF $(@:.o=.d) -o $@ $< -m$*
# Unit test object files
$(OBJS_DIR)/%.o: tests/unit/%.cpp
@echo $(COLOR_CYAN)"Building $@ from $<"$(COLOR_END)
$(QUIET) $(MKDIR) $(OBJS_DIR)
$(QUIET) $(CXX) $(CXXFLAGS) -pthread -c -MMD -MQ $@ -MF $(@:.o=.d) -o $@ $< -Isrc
###############################################################################
# Documentation
SPHINXOPTS = -n -q
SPHINXBUILD = sphinx-build
docs: man
@echo $(COLOR_CYAN)"Building manual"$(COLOR_END)
$(QUIET) @$(SPHINXBUILD) -M html docs $(BUILD_DIR)/docs $(SPHINXOPTS)
man $(MAN_PAGE):
@echo $(COLOR_CYAN)"Building man-page"$(COLOR_END)
$(QUIET) @$(SPHINXBUILD) -M man docs $(BUILD_DIR)/docs $(SPHINXOPTS)
###############################################################################
# Automatic tracking of include-file dependencies
-include $(CORE_OBJS:.o=.d)
-include $(EXEC_OBJS:.o=.d)
-include $(TEST_OBJS:.o=.d)