forked from Phelimb/mccortex
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
337 lines (268 loc) · 11.4 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
332
333
334
335
336
337
#Arguments (all are optional):
# MAXK=31
# RELEASE=1 (release build)
# DEBUG=1 (debug build)
# VERBOSE=1 (compile to print all the things!)
# HASH=<CITY,LOOKUP3,XXHASH> (default hash function)
# RECOMPILE=1 (recompile all from source)
# NOLIBS=1 (do not attempt to recompile library code)
# STRICT=1 (compile with stricter CC warnings)
# Resolve some issues linking libz:
# e.g. for WTCHG cluster3
# 1) pass LIB_PATH=/usr/local/lib/ to compile on WTCHG cluster3
# 2) set LD_LIBRARY_PATH=/usr/local/lib/:$(LD_LIBRARY_PATH) before running
# Targets:
# make
# make clean
# make all
# make [mccortex|tables|debug|test]
# make tests <- run tests
# Use bash as shell
SHELL := /bin/bash
## Toggle Release Version
#
# RELEASE=1
# RECOMPILE=1
#
##
MAXK = 31
LOWK = $(word 1, $(shell echo 31 $(MAXK) | sort -n))
TEST_KMER=$(shell echo $$[(($(MAXK)+31)/32)*32 - 1])
ifneq ($(MAXK),$(TEST_KMER))
KMERERROR=1
endif
ifneq ($(LOWK),31)
KMERERROR=1
endif
ifdef KMERERROR
$(error Invalid MAXK value '$(MAXK)'. Please choose from 31,63,95,..(32*n-1) [default: 31] $(TEST_KMER) $(LOWK))
endif
MAX_KMER_SIZE=$(MAXK)
MIN_KMER_SIZE=$(shell echo $$[$(MAX_KMER_SIZE)-30] | sed 's/^1$$/3/g')
# Use City hash instead of lookup3?
ifdef HASH
ifeq ($(HASH),CITY)
HASH_KEY_FLAGS=-DUSE_CITY_HASH=1
else ifeq ($(HASH),XXHASH)
HASH_KEY_FLAGS=-DUSE_XXHASH=1
else ifeq ($(HASH),LOOKUP3)
# default
else
$(error Please set HASH to a valid value HASH=<LOOKUP3,CITY,XXHASH>)
endif
endif
# Library paths
# IDIR_GSL_HEADERS=libs/gsl-1.16
IDIR_HTS=libs/htslib
IDIR_STRS=libs/string_buffer
IDIR_SEQ=libs/seq_file
IDIR_ALIGN=libs/seq-align/src
IDIR_BITARR=libs/bit_array
IDIR_MSGPOOL=libs/msg-pool
IDIR_MISC=libs/misc
# LIB_GSL=libs/gsl-1.16/.libs/libgsl.a
LIB_HTS=libs/htslib/libhts.a
LIB_ALIGN=libs/seq-align/src/libalign.a
# LIB_STRS=libs/string_buffer/libstrbuf.a
LIB_STRS=libs/string_buffer/string_buffer.o
LIB_CARRAYS=libs/carrays/carrays.o
MISC_SRCS=$(wildcard libs/misc/*.c)
MISC_HDRS=$(wildcard libs/misc/*.h)
MISC_OBJS=$(MISC_SRCS:.c=.o)
LIB_MISC=$(MISC_SRCS) libs/xxHash/xxhash.c
# LIB_MISC=$(MISC_OBJS)
ifdef LIB_PATH
EXTRA_INCS := -I $(LIB_PATH) -L $(LIB_PATH)
endif
INCS=-I libs -I $(IDIR_HTS) $(EXTRA_INCS)
# Library linking
LIB_OBJS=$(LIB_MISC) $(LIB_STRS) $(LIB_CARRAYS) $(LIB_HTS) $(LIB_ALIGN) libs/cJSON/cJSON.o
LINK=-lpthread -lz -lm
# Preprocessor declarations
CPPFLAGS=$(HASH_KEY_FLAGS) -D_USESAM=1
KMERARGS=-DMIN_KMER_SIZE=$(MIN_KMER_SIZE) -DMAX_KMER_SIZE=$(MAX_KMER_SIZE)
# C Compiler flags
CFLAGS = -std=c99 -Wall -Wextra
# -fno-strict-aliasing
CFLAGS_USEFUL = -Wshadow -Wstrict-aliasing=2 \
-Winit-self -Wmissing-include-dirs \
-Wdiv-by-zero -Wsign-compare \
-Wmissing-noreturn -Wreturn-type \
-Wwrite-strings -Wundef -Wpointer-arith \
-Wfloat-equal -Wbad-function-cast
ifdef STRICT
CFLAGS_STRICT = -Wcast-qual -fstack-protector-all
ifneq (,$(findstring clang,$(COMPILER)))
CFLAGS_STRICT := $(CFLAGS_STRICT) -fsanitize-undefined-trap-on-error
endif
endif
CFLAGS := $(CFLAGS) $(CFLAGS_USEFUL) $(CFLAGS_STRICT)
PLATFORM := $(shell uname)
COMPILER := $(shell ($(CC) -v 2>&1) | tr A-Z a-z )
ARCH = -m64
UNAME_P := $(shell uname -p)
ifneq ($(filter arm%,$(UNAME_P)),)
ARCH =
endif
ifneq ($(filter aarch%,$(UNAME_P)),)
ARCH =
endif
# If not debugging, add optimisations and -DNDEBUG=1 to turn off assert() calls
ifdef DEBUG
OPT = -O0 -g -ggdb -gdwarf-2 -g3
else
# Could add -DNDEBUG=1 here to turn off asserts
OPT = -O3 $(ARCH)
endif
CFLAGS := $(OPT) $(CFLAGS)
ifdef VERBOSE
CPPFLAGS := $(CPPFLAGS) -DCTXVERBOSE=1
endif
ifdef RELEASE
RECOMPILE=1 -DNDEBUG=1
else
CPPFLAGS := $(CPPFLAGS) -DCTXCHECKS=1
endif
KMER_OBJDIR=build/kmer$(MAXK)
KMER_SRCS=$(wildcard src/kmer/*.c)
KMER_HDRS=$(wildcard src/kmer/*.h) src/global/version.h
KMER_FILES=$(notdir $(KMER_SRCS))
KMER_OBJS=$(addprefix $(KMER_OBJDIR)/, $(KMER_FILES:.c=.o))
GLOBAL_OBJDIR=build/global
GLOBAL_SRCS=$(wildcard src/global/*.c)
GLOBAL_HDRS=$(wildcard src/global/*.h) src/global/version.h
GLOBAL_FILES=$(notdir $(GLOBAL_SRCS))
GLOBAL_OBJS=$(addprefix $(GLOBAL_OBJDIR)/, $(GLOBAL_FILES:.c=.o))
BASIC_OBJDIR=build/basic
BASIC_SRCS=$(wildcard src/basic/*.c)
BASIC_HDRS=$(wildcard src/basic/*.h)
BASIC_FILES=$(notdir $(BASIC_SRCS))
BASIC_OBJS=$(addprefix $(BASIC_OBJDIR)/, $(BASIC_FILES:.c=.o))
PATHS_OBJDIR=build/paths
PATHS_SRCS=$(wildcard src/paths/*.c)
PATHS_HDRS=$(wildcard src/paths/*.h)
PATHS_FILES=$(notdir $(PATHS_SRCS))
PATHS_OBJS=$(addprefix $(PATHS_OBJDIR)/, $(PATHS_FILES:.c=.o))
GRAPH_OBJDIR=build/graph$(MAXK)
GRAPH_SRCS=$(wildcard src/graph/*.c)
GRAPH_HDRS=$(wildcard src/graph/*.h)
GRAPH_FILES=$(notdir $(GRAPH_SRCS))
GRAPH_OBJS=$(addprefix $(GRAPH_OBJDIR)/, $(GRAPH_FILES:.c=.o))
GRAPH_PATHS_OBJDIR=build/graph_paths$(MAXK)
GRAPH_PATHS_SRCS=$(wildcard src/graph_paths/*.c)
GRAPH_PATHS_HDRS=$(wildcard src/graph_paths/*.h)
GRAPH_PATHS_FILES=$(notdir $(GRAPH_PATHS_SRCS))
GRAPH_PATHS_OBJS=$(addprefix $(GRAPH_PATHS_OBJDIR)/, $(GRAPH_PATHS_FILES:.c=.o))
DB_ALN_OBJDIR=build/alignment$(MAXK)
DB_ALN_SRCS=$(wildcard src/alignment/*.c)
DB_ALN_HDRS=$(wildcard src/alignment/*.h)
DB_ALN_FILES=$(notdir $(DB_ALN_SRCS))
DB_ALN_OBJS=$(addprefix $(DB_ALN_OBJDIR)/, $(DB_ALN_FILES:.c=.o))
TOOLS_OBJDIR=build/tools$(MAXK)
TOOLS_SRCS=$(wildcard src/tools/*.c)
TOOLS_HDRS=$(wildcard src/tools/*.h)
TOOLS_FILES=$(notdir $(TOOLS_SRCS))
TOOLS_OBJS=$(addprefix $(TOOLS_OBJDIR)/, $(TOOLS_FILES:.c=.o))
CMDS_OBJDIR=build/commands$(MAXK)
CMDS_SRCS=$(wildcard src/commands/*.c)
CMDS_HDRS=$(wildcard src/commands/*.h)
CMDS_FILES=$(notdir $(CMDS_SRCS))
CMDS_OBJS=$(addprefix $(CMDS_OBJDIR)/, $(CMDS_FILES:.c=.o))
TESTS_OBJDIR=build/tests$(MAXK)
TESTS_SRCS=$(wildcard src/tests/*.c)
TESTS_HDRS=$(wildcard src/tests/*.h)
TESTS_FILES=$(notdir $(TESTS_SRCS))
TESTS_OBJS=$(addprefix $(TESTS_OBJDIR)/, $(TESTS_FILES:.c=.o))
HDRS=$(GLOBAL_HDRS) $(BASIC_HDRS) $(PATHS_HDRS) $(GRAPH_HDRS) $(GRAPH_PATHS_HDRS) \
$(DB_ALN_HDRS) $(TOOLS_HDRS) $(CMDS_HDRS)
DIRS=bin \
$(KMER_OBJDIR) $(GLOBAL_OBJDIR) $(BASIC_OBJDIR) \
$(PATHS_OBJDIR) $(GRAPH_OBJDIR) \
$(GRAPH_PATHS_OBJDIR) $(DB_ALN_OBJDIR) $(TOOLS_OBJDIR) $(CMDS_OBJDIR) \
$(TESTS_OBJDIR)
# DEPS dependencies that do not need to be re-built per target
ifdef NOLIBS
DEPS=Makefile $(DIRS) $(LIB_OBJS)
else
DEPS=Makefile $(DIRS) $(LIB_OBJS) libs-core
endif
REQ=
# RECOMPILE=1 to recompile all from source
ifdef RECOMPILE
OBJS=$(CMDS_SRCS) $(TOOLS_SRCS) $(DB_ALN_SRCS) $(GRAPH_PATHS_SRCS) $(GRAPH_SRCS) $(PATHS_SRCS) $(BASIC_SRCS) $(GLOBAL_SRCS) $(KMER_SRCS) $(LIB_OBJS)
TESTS_OBJS=$(TESTS_SRCS)
REQ=force
else
OBJS=$(CMDS_OBJS) $(TOOLS_OBJS) $(DB_ALN_OBJS) $(GRAPH_PATHS_OBJS) $(GRAPH_OBJS) $(PATHS_OBJS) $(BASIC_OBJS) $(GLOBAL_OBJS) $(KMER_OBJS) $(LIB_OBJS)
endif
.DEFAULT_GOAL := mccortex
all: mccortex tests tables libs-other
# Update libraries
libs-core:
cd libs && $(MAKE) core
libs-other:
cd libs && $(MAKE) other
# Run tests
test: tests
./bin/tests$(MAXK)
# This Makefile mastery borrowed from htslib [https://github.com/samtools/htslib]
# If git repo, grab commit hash to use in version
# Force version.h to be remade if $(CTX_VERSION) has changed.
ifndef CTX_VERSION
ifneq "$(wildcard .git)" ""
CTX_VERSION := $(shell git describe --always --dirty)
# CTX_VERSION := $(shell git log --pretty=format:'%h' -n 1 --tags)
src/global/version.h: $(if $(wildcard src/global/version.h),$(if $(findstring "$(CTX_VERSION)",$(shell cat src/global/version.h)),,force))
endif
endif
src/global/version.h:
echo '#define CTX_VERSION "$(CTX_VERSION)"' > $@
$(KMER_OBJDIR)/%.o: src/kmer/%.c $(KMER_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/kmer/ -I src/kmer/ $(INCS) -c $<
$(GLOBAL_OBJDIR)/%.o: src/global/%.c $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -I src/global/ -I src/kmer/ $(INCS) -c $<
$(BASIC_OBJDIR)/%.o: src/basic/%.c $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(PATHS_OBJDIR)/%.o: src/paths/%.c $(PATHS_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(GRAPH_OBJDIR)/%.o: src/graph/%.c $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(GRAPH_PATHS_OBJDIR)/%.o: src/graph_paths/%.c $(GRAPH_PATHS_HDRS) $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(DB_ALN_OBJDIR)/%.o: src/alignment/%.c $(DB_ALN_HDRS) $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/alignment/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(TOOLS_OBJDIR)/%.o: src/tools/%.c $(TOOLS_HDRS) $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(CMDS_OBJDIR)/%.o: src/commands/%.c $(CMDS_HDRS) $(TOOLS_HDRS) $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/commands/ -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
$(TESTS_OBJDIR)/%.o: src/tests/%.c $(TESTS_HDRS) $(TOOLS_HDRS) $(GRAPH_HDRS) $(BASIC_HDRS) $(GLOBAL_HDRS) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) -c $<
# Misc library code
libs/misc/%.o: libs/misc/%.c libs/misc/%.h
$(CC) -o libs/misc/$*.o $(CFLAGS) -c libs/misc/$*.c
libs/cJSON/cJSON.o: libs/cJSON/cJSON.c libs/cJSON/cJSON.h
$(CC) -o $@ $(CFLAGS) -c $<
mccortex: bin/mccortex$(MAXK)
bin/mccortex$(MAXK): src/main/mccortex.c $(OBJS) $(HDRS) $(REQ) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/commands/ -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) src/main/mccortex.c $(OBJS) $(LINK)
tests: bin/tests$(MAXK)
bin/tests$(MAXK): src/main/tests.c $(TESTS_OBJS) $(TESTS_HDRS) $(OBJS) $(HDRS) $(REQ) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/tests/ -I src/commands/ -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) src/main/tests.c $(TESTS_OBJS) $(OBJS) $(LINK)
tables: bin/tables
bin/tables: src/main/tables.c | $(DEPS)
$(CC) -o $@ $(CFLAGS) $<
debug: bin/debug$(MAXK)
bin/debug$(MAXK): src/main/debug.c $(OBJS) $(HDRS) $(REQ) | $(DEPS)
$(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(KMERARGS) -I src/commands/ -I src/tools/ -I src/alignment/ -I src/graph_paths/ -I src/graph/ -I src/paths/ -I src/basic/ -I src/global/ -I src/kmer/ $(INCS) src/main/debug.c $(OBJS) $(LINK)
# directories
$(DIRS):
mkdir -p $@
# libraries
# This triggers the compiling of library dependencies for first install
$(LIB_OBJS): libs/string_buffer/string_buffer.h
libs/string_buffer/string_buffer.h:
cd libs; make
clean:
rm -rf bin build libs/misc/*.o libs/cJSON/*.o
force:
.PHONY: all clean mccortex test force libs