-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
331 lines (223 loc) · 8.19 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
322
323
324
325
326
327
328
329
330
331
###################################################################################################
# ngsAMOVA Makefile
####################################################################################################
default: all
PROGRAM = ngsAMOVA
# Compiler specs
CXX ?= g++
# No-compile targets
NO_COMPILE = help clean test test-%
VAL_ADD_CRYPTOLIB = -lcrypto
VAL_NOTADD_CRYPTOLIB =
####################################################################################################
# [BLOCK START]
# ony run if make will try compiling, i.e. not NO_COMPILE
ifeq (,$(filter $(NO_COMPILE),$(MAKECMDGOALS))) #1
$(info ________________________________________________________________________________)
$(info )
$(info [INFO] Checking for library availability)
$(info )
## -> [cryptolib availability check]
CRYPTO_TRY = $(shell echo 'int main(){}'|$(CXX) -x c++ - -lcrypto 2>/dev/null -o /dev/null; echo $$?)
ifeq "$(CRYPTO_TRY)" "0" #1_1
$(info [INFO] -> Crypto library is available to link)
THIS_CRYPTOLIB = $(VAL_ADD_CRYPTOLIB)
else #1_1
# CRYPTO_TRY != 0
THIS_CRYPTOLIB = $(VAL_NOTADD_CRYPTOLIB)
$(info [INFO] -> Crypto library is not available to link)
endif #1_1
## -> [htslib source check]
#if htslib source is defined
ifdef HTSSRC #1_2
#if hts source is set to systemwide
ifeq ($(HTSSRC),systemwide) #1_2_1
$(info [INFO] -> HTSSRC set to systemwide; assuming systemwide installation)
THIS_LIBHTS := -lhts
else #1_2_1
#if hts source path is given
# Adjust $(HTSSRC) to point to your top-level htslib directory
$(info [INFO] -> HTSSRC is defined as $(HTSSRC))
CPPFLAGS := -I$(realpath $(HTSSRC))
THIS_LIBHTS := $(realpath $(HTSSRC))/libhts.a
endif #1_2_1
#if htssrc not defined
else #1_2
$(info [INFO] -> HTSSRC is not defined; using htslib submodule)
HTSSRC := $(realpath $(CURDIR)/htslib)
CPPFLAGS := -I$(HTSSRC)
THIS_LIBHTS := $(HTSSRC)/libhts.a
all: .activate_module
endif #1_2
DEV_FLAGS = -g -Wall
OPTIM_OFF = -O0
OPTIM_ON = -O3
PREV_BUILD_MODE := $(shell grep -oP 'define DEV \K\d' dev.h)
ifeq (dev,$(filter dev,$(MAKECMDGOALS))) #1_3
THIS_BUILD_MODE := 1
ifeq (1,$(PREV_BUILD_MODE)) #1_3_1
# PREV_BUILD_MODE is 1
BUILD_MODE_CHANGED := 0
else #1_3_1
# PREV_BUILD_MODE is 0
BUILD_MODE_CHANGED := 1
endif #1_3_1
else #1_3
THIS_BUILD_MODE := 0
ifeq (1,$(PREV_BUILD_MODE)) #1_3_2
# PREV_BUILD_MODE is 1
BUILD_MODE_CHANGED := 1
else #1_3_2
# PREV_BUILD_MODE is 0
BUILD_MODE_CHANGED := 0
endif #1_3_2
endif #1_3
ifeq (1,$(BUILD_MODE_CHANGED)) #1_4
$(info [INFO] -> Build mode has been changed)
$(info [INFO] -> Updating dev.h)
$(shell sed -i 's/define DEV $(PREV_BUILD_MODE)/define DEV $(THIS_BUILD_MODE)/' dev.h)
endif #1_4
ifeq (dev,$(filter dev,$(MAKECMDGOALS))) #1_5
$(info )
$(info ________________________________________________________________________________)
$(info )
$(info [INFO] Compiling in developer mode)
$(info )
OPTIM_FLAGS := $(OPTIM_OFF)
THIS_MODE_FLAGS := $(DEV_FLAGS) $(OPTIM_FLAGS)
else #1_5
$(info )
$(info ________________________________________________________________________________)
$(info )
$(info [INFO] Compiling in release mode)
$(info )
OPTIM_FLAGS := $(OPTIM_ON)
THIS_MODE_FLAGS := $(OPTIM_FLAGS)
endif #1_5
$(info [INFO] -> CXXFLAGS was "$(CXXFLAGS)")
CXXFLAGS += $(THIS_MODE_FLAGS)
$(info [INFO] -> Updated CXXFLAGS to "$(CXXFLAGS)")
$(info [INFO] -> LIBS was "$(LIBS)")
LIBS := $(THIS_LIBHTS) $(THIS_CRYPTOLIB) -lz -lm -lbz2 -llzma -lcurl -lpthread
$(info [INFO] -> Updated LIBS to "$(LIBS)")
$(info )
$(info ________________________________________________________________________________)
$(info )
endif #1
# [BLOCK END]
####################################################################################################
####################################################################################################
dev: all
all: $(PROGRAM)
CXXSRC := $(wildcard *.cpp)
# Preprocessed C++ files
PREP := $(CXXSRC:.cpp=.ii)
# Assembly source files
ASM := $(CXXSRC:.cpp=.s)
# Object files
OBJ := $(CXXSRC:.cpp=.o)
# Dependency files
DEP := $(OBJ:.o=.d)
-include $(DEP)
FLAGS := $(CPPFLAGS) $(CXXFLAGS)
VERSION = v0.5
ifneq ($(wildcard .git),)
VERSION := $(VERSION)-$(shell git describe --always)
endif
VERSIONH = version.h
$(VERSIONH):
$(if $(wildcards version.h),$(if $(findstring "$(VERSION)",$(shell cat version.h)),,$(shell echo '#define NGSAMOVA_VERSION "$(VERSION)"' > version.h)), $(shell echo '#define NGSAMOVA_VERSION "$(VERSION)"' > version.h))
# Build info
BUILDH = build.h
$(BUILDH):
$(info [INFO] Writing build info to build.h)
$(shell echo '#define NGSAMOVA_MAKE_CXX ("$(CXX)")' > build.h)
$(shell echo '#define NGSAMOVA_MAKE_LIBS ("$(LIBS)")' >> build.h)
$(shell echo '#define NGSAMOVA_MAKE_FLAGS ("$(FLAGS)")' >> build.h)
$(shell echo '#define NGSAMOVA_MAKE_HTSSRC ("$(HTSSRC)")' >> build.h)
$(shell echo '#define NGSAMOVA_MAKE_CXXFLAGS ("$(CXXFLAGS)")' >> build.h)
$(shell echo '#define NGSAMOVA_MAKE_CPPFLAGS ("$(CPPFLAGS)")' >> build.h)
$(PROGRAM): $(OBJ)
@echo "________________________________________________________________________________"
@echo ""
@echo "[INFO] -> Finishing up"
$(CXX) -o $@ $^ $(LIBS)
@echo "________________________________________________________________________________"
@echo ""
@echo "[FINISHED] $(PROGRAM) is now ready to use!"
@echo " Full path to the program: $(CURDIR)/$(PROGRAM)"
@echo ""
@echo " To get started, run:"
@echo " $(CURDIR)/$(PROGRAM) -h"
@echo " or:"
@echo " ./$(PROGRAM) -h"
@echo ""
%.o: %.cpp $(VERSIONH) $(BUILDH)
@echo ""
@echo "________________________________________________________________________________"
@echo ""
@echo "[INFO] -> Compiling $*.cpp"
$(CXX) -c $(FLAGS) $*.cpp
$(CXX) -MM $(FLAGS) $*.cpp >$*.d
####################################################################################################
## [clean]
# - clean up the directory
.PHONY: clean
clean:
$(RM) $(OBJ) $(DEP) $(PREP) $(ASM) $(VERSIONH) $(BUILDH) $(PROGRAM) vgcore.*
####################################################################################################
## [test]
#
.PHONY: test test-%
test:
bash test/runTests.sh
test-%:
bash test/runTests.sh $*
####################################################################################################
## [.activate_module]
.PHONY: .activate_module
.activate_module:
@echo "________________________________________________________________________________"
@echo ""
@echo "[INFO] Activating HTSlib submodule"
@echo ""
git submodule update --init --recursive
$(MAKE) -C $(HTSSRC)
@echo "[INFO] -> HTSlib submodule is now activated"
@echo ""
@echo "________________________________________________________________________________"
####################################################################################################
## [help]
.PHONY: help
help:
@echo ""
@echo "----------------------------------------"
@echo " Program: $(PROGRAM)"
@echo " Version: $(VERSION)"
@echo " License: GNU GPLv3.0"
@echo "----------------------------------------"
@echo ""
@echo " Usage:"
@echo " make [target] [FLAG=value...]"
@echo ""
@echo " Targets:"
@echo " help - Print this help message"
@echo " dev - Compile in developer/debug mode (activates flags: -g -Wall -O0)"
@echo " clean - Clean up the directory"
@echo " test - Run unit tests"
@echo ""
@echo " Flags:"
@echo " HTSSRC - Specifies the source of HTSlib."
@echo " Values:"
@echo " (empty) - Use the HTSlib submodule [default]"
@echo " systemwide - Use the systemwide HTSlib installation"
@echo " /path/to/htslib - Use the HTSlib installation at /path/to/htslib"
@echo ""
@echo " Examples:"
@echo " make - Compile in release mode using HTSlib submodule"
@echo " make HTSSRC=/path/to/htslib - Compile in release mode using /path/to/htslib"
@echo " make dev HTSSRC=systemwide - Compile in developer mode using the systemwide HTSlib installation"
@echo ""
@echo " Note: If no values are provided for HTSSRC, CXX, CXXFLAGS, or LIBS, defaults will be used."
@echo ""
####################################################################################################