-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
203 lines (166 loc) · 5.72 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
all: bkc bkc_dump
dummy := $(shell git submodule update --init --recursive)
BKC_MAIN_DIR = src/bkc
BKC_DUMP_DIR = src/bkc_dump
BKC_COMMON_DIR = src/common
BKC_LIBS_DIR = libs
LIBS_DIR = . #/usr/local/lib
INCLUDE_DIR= libs
ZLIB_INCLUDE_DIR = libs/zlib-ng/build-g++
ZLIB_INCLUDE_DIR_FOR_FILE_WRAPPER = libs/zlib-ng/build-g++/zlib-ng
ZSTD_INCLUDE_DIR = libs/zstd/lib
LIBDEFLATE_INCLUDE_DIR = libs/libdeflate
ISAL_INCLUDE_DIR = libs/isa-l/include
MIMALLOC_INLUCDE_DIR = libs/mimalloc/include
SHARED_INCLUDE_DIR ?= ./shared/
BKC_OUT_BIN_DIR ?= bin
MIMALLOC_OBJ=libs/mimalloc/mimalloc.o
ifdef MSVC # Avoid the MingW/Cygwin sections
UNAME_S := Windows
else # If uname not available => 'not'
UNAME_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
UNAME_M := $(shell uname -m)
endif
D_OS =
D_ARCH =
ifeq ($(UNAME_S),Darwin)
D_OS=MACOS
ifeq ($(UNAME_M),arm64)
D_ARCH=ARM64
else
D_ARCH=X64
endif
else
D_OS=LINUX
D_ARCH=X64
ifeq ($(UNAME_M),arm64)
D_ARCH=ARM64
endif
ifeq ($(UNAME_M),aarch64)
D_ARCH=ARM64
endif
endif
#ifeq ($(D_ARCH),X64)
# dummy_install_nasm := $(shell \
# if [ ! -f build_tools/nasm/nasm ]; then \
# cd build_tools/nasm && ./autogen.sh && ./configure && make -j; \
# fi)
#endif
#NASM_V := $(shell build_tools/nasm/nasm --version 2>/dev/null)
CPU_FLAGS =
STATIC_LFLAGS =
PLATFORM_SPECIFIC_FLAGS =
#in some cases we can have different results on ARM
#I guess this is exactly the same as here: https://bugs.mysql.com/bug.php?id=82760
ifeq ($(D_ARCH),ARM64)
PLATFORM_SPECIFIC_FLAGS = -ffp-contract=off
endif
ifeq ($(D_OS),MACOS)
ifeq ($(D_ARCH),ARM64)
CPU_FLAGS = -march=armv8.4-a
else
CPU_FLAGS = -m64
endif
STATIC_LFLAGS = -static-libgcc -static-libstdc++ -pthread
else
ifeq ($(D_ARCH),ARM64)
CPU_FLAGS = -march=armv8-a
STATIC_LFLAGS = -static-libgcc -static-libstdc++ -lpthread
else
CPU_FLAGS = -m64
STATIC_LFLAGS = -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
endif
endif
LIB_ZLIB=$(BKC_LIBS_DIR)/zlib-ng/build-g++/zlib-ng/libz.a
LIB_ISAL=$(BKC_LIBS_DIR)/isa-l/bin/isa-l.a
LIB_ZSTD=$(BKC_LIBS_DIR)/zstd/lib/libzstd.a
LIB_LIBDEFLATE=$(BKC_LIBS_DIR)/libdeflate/build/libdeflate.a
LIB_GZ=$(LIB_ZLIB)
REFRESH_FLAGS =
ifeq ($(UNAME_S),Linux)
ifeq ($(UNAME_M),x86_64)
REFRESH_FLAGS +=-DARCH_X64
# ifdef NASM_V
# LIB_GZ=$(LIB_ISAL)
# REFRESH_FLAGS += -DREFRESH_USE_IGZIP -I $(ISAL_INCLUDE_DIR)
# else
REFRESH_FLAGS +=-DREFRESH_USE_ZLIB
# endif
else
REFRESH_FLAGS +=-DREFRESH_USE_ZLIB
endif
else
REFRESH_FLAGS +=-DREFRESH_USE_ZLIB
endif
CFLAGS = -fPIC -Wall -O3 $(PLATFORM_SPECIFIC_FLAGS) $(CPU_FLAGS) $(REFRESH_FLAGS) -std=c++20 -pthread -I $(SHARED_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR_FOR_FILE_WRAPPER) -I $(INCLUDE_DIR) -I $(MIMALLOC_INLUCDE_DIR) -I $(ZSTD_INCLUDE_DIR) -I $(LIBDEFLATE_INCLUDE_DIR) -fpermissive
CLINK = -lm -std=c++20 -lpthread
release: CLINK = -lm -std=c++20 $(STATIC_LFLAGS)
release: CFLAGS = -fPIC -Wall -O3 -DNDEBUG $(PLATFORM_SPECIFIC_FLAGS) $(CPU_FLAGS) $(REFRESH_FLAGS) -std=c++20 -pthread -I $(SHARED_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR_FOR_FILE_WRAPPER) -I $(INCLUDE_DIR) -I $(MIMALLOC_INLUCDE_DIR) -I $(ZSTD_INCLUDE_DIR) -fpermissive
#release: satc_undump satc_filter satc_to_fasta fafq_filter
release: all
debug: CFLAGS = -fPIC -Wall -O0 -g $(PLATFORM_SPECIFIC_FLAGS) $(CPU_FLAGS) $(REFRESH_FLAGS) -std=c++20 -pthread -I $(SHARED_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR) -I $(ZLIB_INCLUDE_DIR_FOR_FILE_WRAPPER) -I $(INCLUDE_DIR) -I $(MIMALLOC_INLUCDE_DIR) -I $(ZSTD_INCLUDE_DIR) -fpermissive
debug: all
ifeq ($(UNAME_S),Linux)
CLINK+=-fabi-version=6
endif
# default install location (binary placed in the /bin folder)
prefix = /usr/local
# optional install location
exec_prefix = $(prefix)
$(LIB_ZLIB):
cd $(BKC_LIBS_DIR)/zlib-ng; cmake -DCMAKE_CXX_COMPILER=$(CXX) -DCMAKE_C_COMPILER=$(CC) -B build-g++/zlib-ng -S . -DZLIB_COMPAT=ON; cmake --build build-g++/zlib-ng --config Release
#$(LIB_ISAL):
# cd $(BKC_LIBS_DIR)/isa-l && PATH=../../build_tools/nasm:$$PATH make -f Makefile.unx
$(LIB_ZSTD):
cd $(BKC_LIBS_DIR)/zstd; make -j
$(LIB_LIBDEFLATE):
cd $(BKC_LIBS_DIR)/libdeflate; cmake -B build && cmake --build build
$(MIMALLOC_OBJ):
$(CXX) -DMI_MALLOC_OVERRIDE -O3 -DNDEBUG -fPIC -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden -ftls-model=initial-exec -fno-builtin-malloc -c -I libs/mimalloc/include libs/mimalloc/src/static.c -o $(MIMALLOC_OBJ)
%.o: %.cpp $(LIB_ZLIB) $(LIB_GZ)
$(CXX) $(CFLAGS) -c $< -o $@
bkc: $(BKC_OUT_BIN_DIR)/bkc
#seems to be important to have mimalloc first in link list, else segfault
$(BKC_OUT_BIN_DIR)/bkc: $(BKC_MAIN_DIR)/bkc.o \
$(BKC_COMMON_DIR)/bkc_file.o \
$(BKC_MAIN_DIR)/kmer_counter.o \
$(BKC_MAIN_DIR)/fq_reader.o \
$(BKC_MAIN_DIR)/memory_pool.o \
$(BKC_COMMON_DIR)/utils.o \
$(LIB_ZLIB) \
$(LIB_ZSTD) \
$(MIMALLOC_OBJ)
-mkdir -p $(BKC_OUT_BIN_DIR)
$(CXX) -o $@ \
$(MIMALLOC_OBJ) \
$(BKC_MAIN_DIR)/bkc.o \
$(BKC_COMMON_DIR)/bkc_file.o \
$(BKC_MAIN_DIR)/kmer_counter.o \
$(BKC_MAIN_DIR)/fq_reader.o \
$(BKC_MAIN_DIR)/memory_pool.o \
$(BKC_COMMON_DIR)/utils.o \
$(LIB_ZLIB) \
$(LIB_ZSTD) \
$(CLINK)
bkc_dump: $(BKC_OUT_BIN_DIR)/bkc_dump
#seems to be important to have mimalloc first in link list, else segfault
$(BKC_OUT_BIN_DIR)/bkc_dump: $(BKC_DUMP_DIR)/bkc_dump.o \
$(BKC_COMMON_DIR)/bkc_file.o \
$(BKC_DUMP_DIR)/dumper.o \
$(LIB_ZSTD) \
$(MIMALLOC_OBJ)
-mkdir -p $(BKC_OUT_BIN_DIR)
$(CXX) -o $@ \
$(MIMALLOC_OBJ) \
$(BKC_DUMP_DIR)/bkc_dump.o \
$(BKC_COMMON_DIR)/bkc_file.o \
$(BKC_DUMP_DIR)/dumper.o \
$(LIB_ZSTD) \
$(CLINK)
clean:
-rm $(BKC_MAIN_DIR)/*.o
-rm $(BKC_DUMP_DIR)/*.o
-rm $(BKC_COMMON_DIR)/*.o
-rm -rf $(BKC_OUT_BIN_DIR)
cd $(BKC_LIBS_DIR)/zlib-ng && $(MAKE) -f Makefile.in clean
cd $(BKC_LIBS_DIR)/zstd && make clean