Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1360 lines (1187 loc) · 75.9 KB
/
Copy pathMakefile
File metadata and controls
1360 lines (1187 loc) · 75.9 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
DEP_DIR:=./deps
SRC_DIR:=src
ALGORITHMS_SRC_DIR:=$(SRC_DIR)/algorithms
CONFIG_SRC_DIR:=$(SRC_DIR)/config
IO_SRC_DIR:=$(SRC_DIR)/io
SUBCOMMAND_SRC_DIR:=$(SRC_DIR)/subcommand
UNITTEST_SRC_DIR:=$(SRC_DIR)/unittest
UNITTEST_SUPPORT_SRC_DIR:=$(SRC_DIR)/unittest/support
# Machine-written code that no one has yet read and cleared for reading. It builds like src/.
ARTIFACTS_SRC_DIR:=artifacts
ARTIFACTS_UNITTEST_SRC_DIR:=$(ARTIFACTS_SRC_DIR)/unittest
ARTIFACTS_UNITTEST_SUPPORT_SRC_DIR:=$(ARTIFACTS_UNITTEST_SRC_DIR)/support
BIN_DIR:=bin
UNITTEST_BIN_DIR:=$(BIN_DIR)/unittest
OBJ_DIR:=obj
SHARED_OBJ_DIR:=obj/pic
ALGORITHMS_OBJ_DIR:=$(OBJ_DIR)/algorithms
ALGORITHMS_SHARED_OBJ_DIR:=$(SHARED_OBJ_DIR)/algorithms
CONFIG_OBJ_DIR:=$(OBJ_DIR)/config
IO_OBJ_DIR:=$(OBJ_DIR)/io
IO_SHARED_OBJ_DIR:=$(SHARED_OBJ_DIR)/io
SUBCOMMAND_OBJ_DIR:=$(OBJ_DIR)/subcommand
UNITTEST_OBJ_DIR:=$(OBJ_DIR)/unittest
UNITTEST_SUPPORT_OBJ_DIR:=$(OBJ_DIR)/unittest/support
ARTIFACTS_OBJ_DIR:=$(OBJ_DIR)/artifacts
ARTIFACTS_SHARED_OBJ_DIR:=$(SHARED_OBJ_DIR)/artifacts
ARTIFACTS_UNITTEST_OBJ_DIR:=$(ARTIFACTS_OBJ_DIR)/unittest
ARTIFACTS_UNITTEST_SUPPORT_OBJ_DIR:=$(ARTIFACTS_UNITTEST_OBJ_DIR)/support
# The per-file unit test binaries from artifacts/ go beside the ones from src/.
ARTIFACTS_UNITTEST_BIN_DIR:=$(UNITTEST_BIN_DIR)
LIB_DIR:=lib
# INC_DIR must be a relative path
INC_DIR:=include
CWD:=$(shell pwd)
PKG_CONFIG ?= pkg-config
SFX :=
EXE:=vg$(SFX)
# Expose compiler we want to use to all build commands as an environment variable.
export CC CXX
all: $(BIN_DIR)/$(EXE)
# Magic dependencies (see <http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#tldr>)
include $(wildcard $(OBJ_DIR)/*.d)
include $(wildcard $(SHARED_OBJ_DIR)/*.d)
include $(wildcard $(ALGORITHMS_OBJ_DIR)/*.d)
include $(wildcard $(ALGORITHMS_SHARED_OBJ_DIR)/*.d)
include $(wildcard $(CONFIG_OBJ_DIR)/*.d)
include $(wildcard $(IO_OBJ_DIR)/*.d)
include $(wildcard $(IO_SHARED_OBJ_DIR)/*.d)
include $(wildcard $(SUBCOMMAND_OBJ_DIR)/*.d)
include $(wildcard $(UNITTEST_OBJ_DIR)/*.d)
include $(wildcard $(UNITTEST_SUPPORT_OBJ_DIR)/*.d)
include $(wildcard $(UNITTEST_BIN_DIR)/*.d)
include $(wildcard $(ARTIFACTS_OBJ_DIR)/*.d)
include $(wildcard $(ARTIFACTS_SHARED_OBJ_DIR)/*.d)
include $(wildcard $(ARTIFACTS_UNITTEST_OBJ_DIR)/*.d)
include $(wildcard $(ARTIFACTS_UNITTEST_SUPPORT_OBJ_DIR)/*.d)
include $(wildcard test/*.d)
# What pkg-config-controlled system dependencies should we use compile and link flags from?
# Use PKG_CONFIG_PATH to point the build system at the right versions of these, if they aren't picked up automatically.
# We can't do this for our bundled, pkg-config-supporting dependencies (like htslib) because they won't be built yet.
PKG_CONFIG_DEPS := libzstd libcrypto
# These are like PKG_CONFIG_DEPS but we try to always link them statically, if possible.
# Note that we then must *always* link anything *else* that uses them statically.
# Jansson has to be in here because it has to come after libvgio, which is in the static deps.
PKG_CONFIG_STATIC_DEPS := protobuf jansson
# What pkg-config-controlled system dependencies should we only use compiler and not linker flags from?
# We manually load these libraries at runtime.
PKG_CONFIG_HEADER_DEPS :=
# We don't ask for -fopenmp here because how we get it can depend on the compiler.
# We don't ask for automatic Make dependency file (*.d) generation here because
# the options we pass can interfere with similar options in dependency project.
# DO NOT PUT ANY INCLUDE FLAGS IN HERE; put them in INCLUDE_FLAGS so they can
# always be in the right order, so our bundled dependencies replace system
# ones.
# DO NOT use CPPFLAGS; use this instead.
CXXFLAGS := -O3 -Werror=return-type -ggdb -g $(CXXFLAGS) $(CPPFLAGS)
# Keep dependency generation flags for just our own sources
DEPGEN_FLAGS := -MMD -MP
# Set include flags. All -I options need to go in here, so the first directory
# listed is genuinely searched first.
# Also, Protobuf produces an absurd number of pkg-config flags now, so we deduplicate them
# even though that's not *always* safe. See
# <https://stackoverflow.com/a/11532197> and
# <https://github.com/protocolbuffers/protobuf/issues/12998>
INCLUDE_FLAGS :=-I$(CWD)/$(INC_DIR) -I$(CWD)/$(INC_DIR)/GFAz -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(UNITTEST_SUPPORT_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic -I$(CWD)/$(INC_DIR)/cairo $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_DEPS) $(PKG_CONFIG_STATIC_DEPS) $(PKG_CONFIG_HEADER_DEPS) | tr ' ' '\n' | awk '!x[$$0]++' | tr '\n' ' ')
# Define libraries to link vg against.
# These need to come before library search paths from LDFLAGS or we won't
# prefer linking vg-installed dependencies over system ones.
LD_LIB_DIR_FLAGS := -L$(CWD)/$(LIB_DIR)
LD_LIB_FLAGS := -lvcflib -lwfa2 -ltabixpp -lgssw -lssw -lsublinearLS -lpthread -lncurses -lgcsa2 -lgbwtgraph -lgbwt -lkff -ldivsufsort -ldivsufsort64 -lraptor2 -lpinchesandcacti -l3edgeconnected -lsonlib -lstructures -lbdsg -lxg -lsdsl -lhandlegraph -lgfaz_compress -lgfaz_core -lzstd
# We omit Cairo for now because its transitive dependencies can't be determined until after it's built. Set them lazily
LD_CAIRO_LIB_FLAGS = $(shell PKG_CONFIG_PATH=$(CWD)/$(LIB_DIR)/pkgconfig:$(PKG_CONFIG_PATH) pkg-config --libs --static cairo)
# We omit Boost Program Options for now; we find it in a platform-dependent way.
# By default it has no suffix
BOOST_SUFFIX=""
# We define some more libraries to link against at the end, in static linking mode if possible, so we can use faster non-PIC code. These have both .so/.dylib and .a versions available.
LD_STATIC_LIB_FLAGS := -lvgio -lhts -ldeflate -lz -lbz2 -llzma
# Some of our static libraries depend on libraries that may not always be avilable in static form.
LD_STATIC_LIB_DEPS := -lpthread -lm
# Use pkg-config to find dependencies.
# Always use --static so that we have the -l flags for transitive dependencies, in case we're doing a full static build.
# But only force static linking of the dependencies we want to use non-PIC code for, for speed.
LD_LIB_FLAGS += $(shell $(PKG_CONFIG) --libs --static $(PKG_CONFIG_DEPS))
LD_STATIC_LIB_FLAGS += $(shell $(PKG_CONFIG) --libs --static $(PKG_CONFIG_STATIC_DEPS))
# Some libraries need to be linked only into the binary
LD_EXE_LIB_FLAGS :=
# We also use plain LDFLAGS to point at system library directories that we want
# to propagate through to dependencies' builds.
# CMake builds that need to find OpenMP might not know about all the prefixes it could be installed into.
# So we make a list of prefixes to search for it.
OMP_PREFIXES:=/
COMPILER_ID=$(strip $(shell $(CXX) --version 2>&1))
ifeq ($(shell uname -s),Darwin)
$(info OS is Mac)
# Don't try and set an rpath on any dependency utilities because that's not
# a thing and install names will work.
LD_UTIL_RPATH_FLAGS=""
# Homebrew installs a Protobuf that uses an Abseil that is built with C++17, so we need to build with at least C++17
# C++20 for spaceship operator and ranges
CXX_STANDARD?=20
# We may need libraries from Macports
ifeq ($(shell if [ -d /opt/local/lib ];then echo 1;else echo 0;fi), 1)
# Use /opt/local/lib if present when building dependencies
LDFLAGS += -L/opt/local/lib
endif
ifeq ($(shell if [ -d /usr/local/lib ];then echo 1;else echo 0;fi), 1)
# Use /usr/local/lib if present.
LDFLAGS += -L/usr/local/lib
endif
ifeq ($(shell if [ -d /usr/local/include ];then echo 1;else echo 0;fi), 1)
# Use /usr/local/include to the end of the include search path.
# Make sure it is system level only so it comes after other -I paths.
INCLUDE_FLAGS += -isystem /usr/local/include
endif
ifndef HOMEBREW_PREFIX
BREW_PATH=$(shell which brew 2>/dev/null)
ifneq ($(BREW_PATH),)
# Get prefix from Homebrew instead of environment
HOMEBREW_PREFIX=$(shell brew --prefix)
endif
endif
ifdef HOMEBREW_PREFIX
# We need Bison from Homebrew instead of Apple's old Bison, and GNU coreutils
export PATH:=$(HOMEBREW_PREFIX)/opt/bison/bin:$(HOMEBREW_PREFIX)/opt/coreutils/libexec/gnubin:$(PATH)
# If we have homebrew, use Homebrew in general
INCLUDE_FLAGS += -I$(HOMEBREW_PREFIX)/include
LDFLAGS += -L$(HOMEBREW_PREFIX)/lib
endif
# We need to find Boost Program Options. It is usually
# -lboost_program_options, except for on Macports installs of Boost where
# it is -lboost_program_options-mt. If we were a real build system we would
# try things until it worked. Instead, we guess.
ifeq ($(shell if [ -f /opt/local/lib/libboost_program_options-mt.dylib ];then echo 1;else echo 0;fi), 1)
# This is where Macports puts it, so use that name
BOOST_SUFFIX="-mt"
endif
# Our compiler might be Apple clang, which doesn't have -fopenmp.
ifneq ($(strip $(shell echo "$(COMPILER_ID)" | grep -i clang | wc -l)), 0)
# This is Clang.
$(info Compiler $(CXX) is Clang)
# We need to use the hard way of getting OpenMP not bundled with the compiler.
# The compiler only needs to do the preprocessing
CXXFLAGS += -Xpreprocessor -fopenmp
ifeq ($(shell if [ -e $(HOMEBREW_PREFIX)/include/omp.h ]; then echo 1; else echo 0; fi), 1)
# libomp used to be globally installed in Homebrew
$(info OMP source is Homebrew libomp global install)
OMP_PREFIXES:=$(OMP_PREFIXES);$(HOMEBREW_PREFIX)
else ifeq ($(shell if [ -d $(HOMEBREW_PREFIX)/opt/libomp/include ]; then echo 1; else echo 0; fi), 1)
# libomp moved to these directories, recently, because it is now keg-only to not fight GCC
$(info OMP source is Homebrew libomop keg)
INCLUDE_FLAGS += -I$(HOMEBREW_PREFIX)/opt/libomp/include
LDFLAGS += -L$(HOMEBREW_PREFIX)/opt/libomp/lib
OMP_PREFIXES:=$(OMP_PREFIXES);$(HOMEBREW_PREFIX)/opt/libomp
else ifeq ($(shell if [ -d /opt/local/lib/libomp ]; then echo 1; else echo 0; fi), 1)
# Macports installs libomp to /opt/local/lib/libomp
$(info OMP source Macports)
INCLUDE_FLAGS += -I/opt/local/include/libomp
LDFLAGS += -L/opt/local/lib/libomp
OMP_PREFIXES:=$(OMP_PREFIXES);/opt/local
else
$(error OMP is not available from either Homebrew or Macports)
endif
# We also need to link it
LD_LIB_FLAGS += -lomp
else
$(info Compiler $(CXX) is GCC)
# The compiler is (probably?) GNU GCC
# On Mac, we need to make sure to configure it to use libc++ like
# Clang, and not GNU libstdc++.
# Otherwise, we won't be able to use any C++ system libraries from
# Homebrew or Macports, which will be built against libc++.
# See https://stackoverflow.com/q/22228208
CXXFLAGS += -fopenmp
# Find includes using Clang
LIBCXX_INCLUDES := $(shell clang++ -print-search-dirs | perl -ne 's{^libraries: =(.*)}{$$1/../../../} && print')
# Use them and libc++ and not the normal standard library
INCLUDE_FLAGS := -isystem $(LIBCXX_INCLUDES)/include/c++/v1 $(INCLUDE_FLAGS)
CXXFLAGS := -nostdinc++ -nodefaultlibs -lc -lc++ -lc++abi -lgcc_s.1 -Wl,-no_compact_unwind $(CXXFLAGS)
# Make sure to use the right libgomp to go with libomp
LD_LIB_FLAGS += -lomp -lgomp.1
endif
# We care about building only for the current machine. If we do something
# more restrictive we can have trouble inlining parts of the standard
# library that were built for something less restrictive. However,
# Apple Clang does not recognize -march=native on ARM.
ifeq ($(shell uname -m), x86_64)
CXXFLAGS += -march=native
endif
# Note shared libraries are dylibs
SHARED_SUFFIX = dylib
# Define options to start static linking of libraries.
# We don't actually do any static linking on Mac, so we leave this empty.
START_STATIC =
END_STATIC =
# We need to use special flags to let us rename libraries.
# See <https://github.com/Homebrew/legacy-homebrew/issues/20233>
LD_RENAMEABLE_FLAGS = -Wl,-headerpad_max_install_names
else
# We are not running on OS X
$(info OS is Linux)
$(info Compiler $(CXX) is assumed to be GCC)
# gbwtgraph uses inline variables and our oldest supported compiler has
# C++17, so we should use at least C++17.
# C++20 for spaceship operator and ranges
CXX_STANDARD?=20
# Set an rpath for vg and dependency utils to find installed libraries
LD_UTIL_RPATH_FLAGS="-Wl,-rpath,$(CWD)/$(LIB_DIR)"
LD_LIB_FLAGS += $(LD_UTIL_RPATH_FLAGS)
# Make sure to allow backtrace access to all our symbols, even those which are not exported.
# Absolutely no help in a static build.
LD_LIB_FLAGS += -rdynamic
# We want to link against the elfutils libraries we build ourselves, in
# $(LIB_DIR), rather than the system ones. See the libelf.a rule for why the
# system libdw cannot be used in a static build.
# 0.195 split out two libraries 0.186 did not have, and both have to be here
# or the static link fails: libdwfl calls dwflst_* in libdwfl_stacktrace, and
# libdw, libelf and libdwfl all call the eu_* tsearch wrappers in libeu.
# -leu goes last because libeu calls back into none of them.
LD_LIB_FLAGS += -ldwfl -ldwfl_stacktrace -ldw -ldwelf -lelf -lebl -leu
# We want to link against libatomic which the GNU C++ standard library needs.
# See <https://github.com/nodejs/node/issues/30093> and <https://stackoverflow.com/q/30591313>
LD_LIB_FLAGS += -latomic
# We get OpenMP the normal way, using whatever the compiler knows about
CXXFLAGS += -fopenmp
ifeq ($(shell arch), x86_64)
# We care about building for SSE4.2 only and not AVX, to have vaguely portable binaries
CXXFLAGS += -msse4.2
endif
# Note shared libraries are so files
SHARED_SUFFIX = so
# Define options to start static linking of libraries on GNU ld.
START_STATIC = -Wl,-Bstatic
# Note that END_STATIC is only safe to use in a mostly-dynamic build, and has to appear or we will try to statically link secret trailing libraries.
END_STATIC = -Wl,-Bdynamic
# We don't need any flags because we don't need to rename libraries with install_name_tool
LD_RENAMEABLE_FLAGS =
endif
# Control variable for address sanitizer
# Like valgrind but fast!
# You can `make clean && make jemalloc=off asan=on` to build with it.
asan = off
ifeq ($(asan),on)
CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
endif
# Control variables for networking support in htslib
curl = off
s3 = off
ifeq ($(s3),on)
# We need libcurl to do S3
curl = on
endif
ifeq ($(curl),on)
# Build htslib with libcurl
HTSLIB_CURL_FLAGS := --enable-libcurl --enable-gcs
LD_STATIC_LIB_DEPS += $(shell $(PKG_CONFIG) --libs --static libcurl)
ifeq ($(s3),on)
# And also with S3 support, which needs libcrypto
HTSLIB_CURL_FLAGS += --enable-s3
LD_STATIC_LIB_DEPS += $(shell $(PKG_CONFIG) --libs --static libcrypto)
else
HTSLIB_CURL_FLAGS += --disable-s3
endif
else
ifeq ($(s3),on)
unused := $(error "Error: htslib cannot be built with S3 support but not curl support")
endif
HTSLIB_CURL_FLAGS := --disable-libcurl --disable-s3 --disable-gcs
endif
# Control variable for mimalloc allocator
# On the command line, you can `make mimalloc=on` if you want mimalloc.
mimalloc = off
# Control variable for jemalloc allocator
# On the command line, you can `make jemalloc=off` if you definitely don't want jemalloc.
# Or you can `make jemalloc=debug` to use a version that tries to find memory errors.
jemalloc = on
ifeq ($(mimalloc),on)
jemalloc = off
endif
ifeq ($(shell uname -s),Darwin)
jemalloc = off
endif
# Sometimes I say jemalloc=yes and then make a face when that doesn't work. Put
# a stop to this.
ifneq ($(asan),on)
ifneq ($(asan),off)
unused := $(error "Error: asan must be on or off, not $(asan)")
endif
endif
ifneq ($(mimalloc),on)
ifneq ($(mimalloc),off)
unused := $(error "Error: mimalloc must be on or off, not $(mimalloc)")
endif
endif
ifneq ($(jemalloc),on)
ifneq ($(jemalloc),off)
ifneq ($(jemalloc),debug)
unused := $(error "Error: jemalloc must be on, off, or debug, not $(jemalloc)")
endif
endif
endif
ifeq ($(mimalloc),on)
ifneq ($(jemalloc),off)
unused := $(error "Error: mimalloc and jemalloc cannot be used together")
endif
endif
# Set the C++ standard we are using
CXXFLAGS := -std=c++$(CXX_STANDARD) $(CXXFLAGS)
# Propagate CXXFLAGS and LDFLAGS to child makes and other build processes
export CXXFLAGS
$(info CXXFLAGS are $(CXXFLAGS))
export LDFLAGS
$(info LDFLAGS are $(LDFLAGS))
OMP_MISSING=$(strip $(shell echo \\\#include \<omp.h\> | $(CXX) $(CXXFLAGS) $(INCLUDE_FLAGS) -x c++ -E /dev/stdin -o /dev/null 2>&1 | head -n1 | grep error | wc -l))
ifeq ($(OMP_MISSING), 1)
$(warning OpenMP header omp.h is not available! vg will not be able to build!)
endif
# Actually set the Boost library option, with the determined suffix
LD_LIB_FLAGS += "-lboost_program_options$(BOOST_SUFFIX)"
# These libs need to come after libdw if used, because libdw depends on them
LD_LIB_FLAGS += -ldl -llzma -lbz2 -lzstd
# Sometimes we need to filter the assembler output. The assembler can run during
# ./configure scripts, compiler calls, or $(MAKE) calls (other than $(MAKE)
# install). So we just stick $(FILTER) at the end of all such commands.
ifeq ($(shell uname -s),Darwin)
# We need to apply a filter to all our build command output. This discards
# all the assembler warnings which can overwhelm Travis log storage.
FILTER=2>&1 | python3 $(CWD)/scripts/filter-noisy-assembler-warnings.py
# For the filter to work and not just swallow errors we also need to turn on
# pipefail in the shell
SHELL=/bin/bash -o pipefail
else
# No filter
FILTER=
endif
# Make remakes Automake Makefiles even in dry runs, which reruns configure.
# So when dry-running, have Automake projects treat Makefile as up to date.
# See https://stackoverflow.com/a/77055033
# Detect a dry run as in https://stackoverflow.com/a/41303169
ifneq (,$(findstring n,$(firstword -$(MAKEFLAGS))))
AUTOMAKE_MAKEFLAGS=--assume-old=Makefile Makefile "AM_MAKEFLAGS=--assume-old=Makefile Makefile"
else
AUTOMAKE_MAKEFLAGS=
endif
STATIC_FLAGS=-static -static-libstdc++ -static-libgcc
SRC = $(wildcard $(SRC_DIR)/*.cpp)
ALGORITHMS_SRC = $(wildcard $(ALGORITHMS_SRC_DIR)/*.cpp)
IO_SRC = $(wildcard $(IO_SRC_DIR)/*.cpp)
SUBCOMMAND_SRC = $(wildcard $(SUBCOMMAND_SRC_DIR)/*.cpp)
UNITTEST_SRC = $(wildcard $(UNITTEST_SRC_DIR)/*.cpp)
UNITTEST_SUPPORT_SRC = $(wildcard $(UNITTEST_SUPPORT_SRC_DIR)/*.cpp)
ARTIFACTS_SRC = $(wildcard $(ARTIFACTS_SRC_DIR)/*.cpp)
ARTIFACTS_UNITTEST_SRC = $(wildcard $(ARTIFACTS_UNITTEST_SRC_DIR)/*.cpp)
ARTIFACTS_UNITTEST_SUPPORT_SRC = $(wildcard $(ARTIFACTS_UNITTEST_SUPPORT_SRC_DIR)/*.cpp)
# These are put into libvg. Grab everything except main
OBJ = $(filter-out $(OBJ_DIR)/main.o,$(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC)))
SHARED_OBJ = $(patsubst $(OBJ_DIR)/%.o,$(SHARED_OBJ_DIR)/%.o,$(OBJ))
# The library code in artifacts/ also goes into libvg
ARTIFACTS_OBJ = $(patsubst $(ARTIFACTS_SRC_DIR)/%.cpp,$(ARTIFACTS_OBJ_DIR)/%.o,$(ARTIFACTS_SRC))
ARTIFACTS_SHARED_OBJ = $(patsubst $(ARTIFACTS_OBJ_DIR)/%.o,$(ARTIFACTS_SHARED_OBJ_DIR)/%.o,$(ARTIFACTS_OBJ))
# And all the algorithms
ALGORITHMS_OBJ = $(patsubst $(ALGORITHMS_SRC_DIR)/%.cpp,$(ALGORITHMS_OBJ_DIR)/%.o,$(ALGORITHMS_SRC))
ALGORITHMS_SHARED_OBJ = $(patsubst $(ALGORITHMS_OBJ_DIR)/%.o,$(ALGORITHMS_SHARED_OBJ_DIR)/%.o,$(ALGORITHMS_OBJ))
# These aren't put into libvg. They are linked into vg itself to communicate
# things about the platform.
# Config objects are built individually and conditionally; that's the point.
CONFIG_OBJ =
# But always build all the IO logic
IO_OBJ = $(patsubst $(IO_SRC_DIR)/%.cpp,$(IO_OBJ_DIR)/%.o,$(IO_SRC))
IO_SHARED_OBJ = $(patsubst $(IO_OBJ_DIR)/%.o,$(IO_SHARED_OBJ_DIR)/%.o,$(IO_OBJ))
# These aren't put into libvg, but they provide subcommand implementations for the vg bianry
SUBCOMMAND_OBJ = $(patsubst $(SUBCOMMAND_SRC_DIR)/%.cpp,$(SUBCOMMAND_OBJ_DIR)/%.o,$(SUBCOMMAND_SRC))
# These aren't put into libvg. But they do go into the main vg binary to power its self-test.
UNITTEST_OBJ = $(patsubst $(UNITTEST_SRC_DIR)/%.cpp,$(UNITTEST_OBJ_DIR)/%.o,$(UNITTEST_SRC))
# And so do the unit tests in artifacts/
ARTIFACTS_UNITTEST_OBJ = $(patsubst $(ARTIFACTS_UNITTEST_SRC_DIR)/%.cpp,$(ARTIFACTS_UNITTEST_OBJ_DIR)/%.o,$(ARTIFACTS_UNITTEST_SRC))
# These support the tests and go in the main vg binary and all the test binaries
UNITTEST_SUPPORT_OBJ_COMMON = $(filter-out $(UNITTEST_SUPPORT_OBJ_DIR)/driver.o,$(patsubst $(UNITTEST_SUPPORT_SRC_DIR)/%.cpp,$(UNITTEST_SUPPORT_OBJ_DIR)/%.o,$(UNITTEST_SUPPORT_SRC)))
# These are the ones that go in all the test binaries (including the test driver with main())
# The test support code in artifacts/ goes wherever the common test support code goes
ARTIFACTS_UNITTEST_SUPPORT_OBJ = $(patsubst $(ARTIFACTS_UNITTEST_SUPPORT_SRC_DIR)/%.cpp,$(ARTIFACTS_UNITTEST_SUPPORT_OBJ_DIR)/%.o,$(ARTIFACTS_UNITTEST_SUPPORT_SRC))
UNITTEST_SUPPORT_OBJ_COMMON += $(ARTIFACTS_UNITTEST_SUPPORT_OBJ)
UNITTEST_SUPPORT_OBJ = $(UNITTEST_SUPPORT_OBJ_DIR)/driver.o $(UNITTEST_SUPPORT_OBJ_COMMON)
# These are per-test-suite binaries we can build faster
UNITTEST_EXE = $(patsubst $(UNITTEST_SRC_DIR)/%.cpp,$(UNITTEST_BIN_DIR)/%,$(UNITTEST_SRC))
ARTIFACTS_UNITTEST_EXE = $(patsubst $(ARTIFACTS_UNITTEST_SRC_DIR)/%.cpp,$(ARTIFACTS_UNITTEST_BIN_DIR)/%,$(ARTIFACTS_UNITTEST_SRC))
ELFUTILS_DIR:=deps/elfutils
RAPTOR_DIR:=deps/raptor
JEMALLOC_DIR:=deps/jemalloc
MIMALLOC_DIR:=deps/mimalloc
SDSL_DIR:=deps/sdsl-lite
GCSA2_DIR:=deps/gcsa2
GBWT_DIR:=deps/gbwt
GBWTGRAPH_DIR=deps/gbwtgraph
KFF_DIR=deps/kff-cpp-api
PROGRESS_BAR_DIR:=deps/progress_bar
VCFLIB_DIR:=deps/vcflib
TABIXPP_DIR:=deps/tabixpp
HTSLIB_DIR:=deps/htslib
GSSW_DIR:=deps/gssw
SPARSEHASH_DIR:=deps/sparsehash
SPARSEPP_DIR:=deps/sparsepp
SHA1_DIR:=deps/sha1
DYNAMIC_DIR:=deps/DYNAMIC
SSW_DIR:=deps/ssw/src
LINLS_DIR:=deps/sublinear-Li-Stephens
STRUCTURES_DIR:=deps/structures
BACKWARD_CPP_DIR:=deps/backward-cpp
DOZEU_DIR:=deps/dozeu
LIBDEFLATE_DIR:=deps/libdeflate
LIBVGIO_DIR:=deps/libvgio
LIBHANDLEGRAPH_DIR:=deps/libhandlegraph
LIBBDSG_DIR:=deps/libbdsg
XG_DIR:=deps/xg
MMMULTIMAP_DIR=deps/mmmultimap
IPS4O_DIR=deps/ips4o
BBHASH_DIR=deps/BBHash
MIO_DIR=deps/mio
ATOMIC_QUEUE_DIR=deps/atomic_queue
GFAz_DIR=deps/GFAz
CAIRO_DIR=deps/cairo
PIXMAN_DIR=deps/pixman
# Dependencies that go into libvg's archive
# These go in libvg but come from dependencies
DEP_OBJ =
DEP_OBJ += $(OBJ_DIR)/progress_bar.o
DEP_OBJ += $(OBJ_DIR)/sha1.o
DEP_SHARED_OBJ = $(patsubst $(OBJ_DIR)/%.o,$(SHARED_OBJ_DIR)/%.o,$(DEP_OBJ))
# These are libraries that we need to build before we link vg.
# It would be nice to dump their contents into libvg to make it stand-alone.
# But that requires fancy ar scripting.
# If you just pass them to ar it puts the library *file* in libvg where nothing can read it.
LIB_DEPS =
LIB_DEPS += $(LIB_DIR)/libsdsl.a
LIB_DEPS += $(LIB_DIR)/libssw.a
LIB_DEPS += $(LIB_DIR)/libgcsa2.a
LIB_DEPS += $(LIB_DIR)/libgbwt.a
LIB_DEPS += $(LIB_DIR)/libgbwtgraph.a
LIB_DEPS += $(LIB_DIR)/libkff.a
LIB_DEPS += $(LIB_DIR)/libhts.a
LIB_DEPS += $(LIB_DIR)/libtabixpp.a
LIB_DEPS += $(LIB_DIR)/libvcflib.a
LIB_DEPS += $(LIB_DIR)/libgssw.a
LIB_DEPS += $(LIB_DIR)/libsonlib.a
LIB_DEPS += $(LIB_DIR)/libpinchesandcacti.a
LIB_DEPS += $(LIB_DIR)/libraptor2.a
LIB_DEPS += $(LIB_DIR)/libsublinearLS.a
LIB_DEPS += $(LIB_DIR)/libstructures.a
LIB_DEPS += $(LIB_DIR)/libdeflate.a
LIB_DEPS += $(LIB_DIR)/libvgio.a
LIB_DEPS += $(LIB_DIR)/libhandlegraph.a
LIB_DEPS += $(LIB_DIR)/libbdsg.a
LIB_DEPS += $(LIB_DIR)/libxg.a
LIB_DEPS += $(LIB_DIR)/libgfaz_core.a
LIB_DEPS += $(LIB_DIR)/libgfaz_compress.a
LIB_DEPS += $(LIB_DIR)/libcairo.a
LIB_DEPS += $(LIB_DIR)/libpixman-1.a
ifneq ($(shell uname -s),Darwin)
# On non-Mac (i.e. Linux), where ELF binaries are used, pull in libdw which
# backward-cpp will use.
LIB_DEPS += $(LIB_DIR)/libdw.a
LIB_DEPS += $(LIB_DIR)/libdwfl.a
LIB_DEPS += $(LIB_DIR)/libdwelf.a
LIB_DEPS += $(LIB_DIR)/libebl.a
LIB_DEPS += $(LIB_DIR)/libelf.a
LIB_DEPS += $(LIB_DIR)/libeu.a
LIB_DEPS += $(LIB_DIR)/libdwfl_stacktrace.a
endif
# Only depend on these files for the final linking stage.
# These libraries provide no headers to affect the vg build.
LINK_DEPS =
# Only depend on these files for the final linking stage, but link them in
# before all other files.
PRE_LINK_DEPS =
ifeq ($(mimalloc),on)
# Use mimalloc at link time
PRE_LINK_DEPS += $(LIB_DIR)/mimalloc.o
# Use the config object for mimalloc
CONFIG_OBJ += $(CONFIG_OBJ_DIR)/allocator_config_mimalloc.o
else ifeq ($(jemalloc),on)
# Use jemalloc at link time
LINK_DEPS += $(LIB_DIR)/libjemalloc.a
# We have to use it statically or we can't get at its secret symbols.
LD_EXE_LIB_FLAGS += $(LIB_DIR)/libjemalloc.a
# Use the config object for jemalloc
CONFIG_OBJ += $(CONFIG_OBJ_DIR)/allocator_config_jemalloc.o
else ifeq ($(jemalloc),debug)
# Use jemalloc at link time
LINK_DEPS += $(LIB_DIR)/libjemalloc_debug.a $(LIB_DIR)/libjemalloc_debug_pic.a
# We have to use it statically or we can't get at its secret symbols.
LD_EXE_LIB_FLAGS += $(LIB_DIR)/libjemalloc_debug.a
# Use the config object for jemalloc
CONFIG_OBJ += $(CONFIG_OBJ_DIR)/allocator_config_jemalloc_debug.o
else
# Use the config object for the normal allocator
CONFIG_OBJ += $(CONFIG_OBJ_DIR)/allocator_config_system.o
endif
# common dependencies to build before all vg src files
DEPS = $(LIB_DEPS)
DEPS += $(INC_DIR)/gcsa/gcsa.h
DEPS += $(INC_DIR)/gbwt/dynamic_gbwt.h
DEPS += $(INC_DIR)/gbwtgraph/gbwtgraph.h
DEPS += $(INC_DIR)/kff_io.hpp
DEPS += $(INC_DIR)/lru_cache.h
DEPS += $(INC_DIR)/dynamic/dynamic.hpp
DEPS += $(INC_DIR)/sparsehash/sparse_hash_map
DEPS += $(INC_DIR)/sparsepp/spp.h
DEPS += $(INC_DIR)/sha1.hpp
DEPS += $(INC_DIR)/progress_bar.hpp
DEPS += $(INC_DIR)/backward.hpp
DEPS += $(INC_DIR)/dozeu/dozeu.h
DEPS += $(INC_DIR)/mmmultimap.hpp
DEPS += $(INC_DIR)/ips4o.hpp
DEPS += $(INC_DIR)/raptor2/raptor2.h
DEPS += $(INC_DIR)/BooPHF.h
DEPS += $(INC_DIR)/mio/mmap.hpp
DEPS += $(INC_DIR)/atomic_queue.h
DEPS += $(LIB_DIR)/cleaned_old_elfutils_v004
.PHONY: clean clean-tests get-deps deps lint test set-path objs static static-docker docs man version
# Aggregate all libvg deps, and exe deps other than libvg
LIBVG_DEPS = $(OBJ) $(ARTIFACTS_OBJ) $(ALGORITHMS_OBJ) $(IO_OBJ) $(DEP_OBJ) $(DEPS)
LIBVG_SHARED_DEPS = $(SHARED_OBJ) $(ARTIFACTS_SHARED_OBJ) $(ALGORITHMS_SHARED_OBJ) $(IO_SHARED_OBJ) $(DEP_SHARED_OBJ) $(DEPS)
EXE_DEPS = $(OBJ_DIR)/main.o $(UNITTEST_OBJ) $(ARTIFACTS_UNITTEST_OBJ) $(UNITTEST_SUPPORT_OBJ_COMMON) $(SUBCOMMAND_OBJ) $(CONFIG_OBJ) $(DEPS) $(LINK_DEPS) $(PRE_LINK_DEPS)
# We have a target we can build to do everything but link the library and executable
objs: $(LIBVG_DEPS) $(EXE_DEPS)
$(LIB_DIR)/libvg.a: $(LIBVG_DEPS)
rm -f $@
ar rs $@ $(OBJ) $(ARTIFACTS_OBJ) $(ALGORITHMS_OBJ) $(IO_OBJ) $(DEP_OBJ)
$(LIB_DIR)/libvg.$(SHARED_SUFFIX): $(LIBVG_SHARED_DEPS)
rm -f $@
$(CXX) -shared -o $@ $(SHARED_OBJ) $(ARTIFACTS_SHARED_OBJ) $(ALGORITHMS_SHARED_OBJ) $(IO_SHARED_OBJ) $(DEP_SHARED_OBJ) $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(LD_LIB_FLAGS) $(LD_STATIC_LIB_FLAGS) $(LD_STATIC_LIB_DEPS)
# Each test set can have its own binary, and not link everything static
$(UNITTEST_EXE): $(UNITTEST_BIN_DIR)/%: $(UNITTEST_OBJ_DIR)/%.o $(UNITTEST_SUPPORT_OBJ) $(CONFIG_OBJ) $(LIB_DIR)/libvg.$(SHARED_SUFFIX)
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -o $@ $< $(UNITTEST_SUPPORT_OBJ) $(CONFIG_OBJ) $(LIB_DIR)/libvg.$(SHARED_SUFFIX) $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(LD_LIB_FLAGS) $(LD_STATIC_LIB_FLAGS) $(LD_STATIC_LIB_DEPS) $(LD_EXE_LIB_FLAGS) $(LD_CAIRO_LIB_FLAGS)
$(ARTIFACTS_UNITTEST_EXE): $(ARTIFACTS_UNITTEST_BIN_DIR)/%: $(ARTIFACTS_UNITTEST_OBJ_DIR)/%.o $(UNITTEST_SUPPORT_OBJ) $(CONFIG_OBJ) $(LIB_DIR)/libvg.$(SHARED_SUFFIX)
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -o $@ $< $(UNITTEST_SUPPORT_OBJ) $(CONFIG_OBJ) $(LIB_DIR)/libvg.$(SHARED_SUFFIX) $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(LD_LIB_FLAGS) $(LD_STATIC_LIB_FLAGS) $(LD_STATIC_LIB_DEPS) $(LD_EXE_LIB_FLAGS) $(LD_CAIRO_LIB_FLAGS)
# For a normal dynamic build we remove the static build marker
$(BIN_DIR)/$(EXE): $(LIB_DIR)/libvg.a $(EXE_DEPS)
-rm -f $(LIB_DIR)/vg_is_static
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -o $(BIN_DIR)/$(EXE) $(PRE_LINK_DEPS) $(OBJ_DIR)/main.o $(UNITTEST_OBJ) $(ARTIFACTS_UNITTEST_OBJ) $(UNITTEST_SUPPORT_OBJ_COMMON) $(SUBCOMMAND_OBJ) $(CONFIG_OBJ) $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(LIB_DIR)/libvg.a $(LD_LIB_FLAGS) $(START_STATIC) $(LD_STATIC_LIB_FLAGS) $(END_STATIC) $(LD_STATIC_LIB_DEPS) $(LD_EXE_LIB_FLAGS) $(LD_CAIRO_LIB_FLAGS)
# We keep a file that we touch on the last static build.
# If the vg linkables are newer than the last static build, we do a build
$(LIB_DIR)/vg_is_static: $(LIB_DIR)/libvg.a $(EXE_DEPS)
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -o $(BIN_DIR)/$(EXE) $(PRE_LINK_DEPS) $(OBJ_DIR)/main.o $(UNITTEST_OBJ) $(ARTIFACTS_UNITTEST_OBJ) $(UNITTEST_SUPPORT_OBJ_COMMON) $(SUBCOMMAND_OBJ) $(CONFIG_OBJ) $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(STATIC_FLAGS) $(LIB_DIR)/libvg.a $(LD_LIB_FLAGS) $(LD_STATIC_LIB_FLAGS) $(LD_STATIC_LIB_DEPS) $(LD_EXE_LIB_FLAGS) $(LD_CAIRO_LIB_FLAGS)
-touch $(LIB_DIR)/vg_is_static
# We don't want to always rebuild the static vg if no files have changed.
# But we do need to rebuild it if files have changed.
# TODO: is there a way to query the mtimes of all the files and rebuild if they changed *or* vg isn't static?
# For now we link dynamically and then link statically, if we actually need to rebuild anything.
static: $(LIB_DIR)/vg_is_static
# Make sure to strip out the symbols that make the binary 300 MB, but leave the
# symbols perf needs for profiling.
static-docker: static scripts/*
strip -d $(BIN_DIR)/$(EXE)
DOCKER_BUILDKIT=1 docker build . -f Dockerfile.static -t vg
# We have system-level deps to install
# We want the One True Place for them to be in the Dockerfile.
# TODO: when libssl-dev on modern Ubuntu no longer needs libjitterentropy3-dev
# (not available for older Ubuntu) manually installed, we can stop polling for
# it and filtering it here. See
# <https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/2158026>.
# We also need to work around meson being available but too old on older
# Ubuntu, by getting it from pip.
get-deps:
sudo DEBIAN_FRONTEND=$(DEBIAN_FRONTEND) apt-get install -qq -y --no-upgrade $(shell cat Dockerfile | sed -n '/^###DEPS_BEGIN###/,$${p;/^###DEPS_END###/q}' | grep -v '^ *#' | grep -v "^RUN" | tr ' ' '\n' | (if ! apt-cache show libjitterentropy3-dev >/dev/null 2>&1 ; then grep -v libjitterentropy3-dev ; else cat ; fi) | tr '\n' ' ' | tr -d '\\')
MESON_MAJOR="$$(meson --version | cut -f1 -d'.')" ; \
MESON_MINOR="$$(meson --version | cut -f2 -d'.')" ; \
if [ "$${MESON_MAJOR}" -lt 1 ] || ( [ "$${MESON_MAJOR}" -eq 1 ] && [ "$${MESON_MINOR}" -lt 3 ] ) ; then \
sudo DEBIAN_FRONTEND=$(DEBIAN_FRONTEND) apt-get install -qq -y --no-upgrade pipx && \
pipx install meson ; \
fi
# And we have submodule deps to build
deps: $(DEPS) $(LINK_DEPS) $(PRE_LINK_DEPS)
# Record the compiler commands that building vg runs, for editors and linters.
# The dry run needs the dependencies to really be built first.
# Depend on the sources so that new source files get picked up.
compile_commands.json: Makefile $(DEPS) $(LINK_DEPS) $(PRE_LINK_DEPS) $(SRC) $(ARTIFACTS_SRC) $(ARTIFACTS_UNITTEST_SRC) $(ARTIFACTS_UNITTEST_SUPPORT_SRC) $(ALGORITHMS_SRC) $(IO_SRC) $(SUBCOMMAND_SRC) $(UNITTEST_SRC) $(UNITTEST_SUPPORT_SRC)
$(MAKE) --dry-run --always-make $(BIN_DIR)/$(EXE) >$(OBJ_DIR)/dry_run_build_log.txt
compiledb --overwrite --output $@ --parse $(OBJ_DIR)/dry_run_build_log.txt
lint: $(ARTIFACTS_SRC_DIR)/*.cpp $(ARTIFACTS_SRC_DIR)/*.hpp $(ARTIFACTS_UNITTEST_SRC_DIR)/*.cpp $(SRC_DIR)/*.cpp $(SRC_DIR)/*.hpp $(ALGORITHMS_SRC_DIR)/*.cpp $(ALGORITHMS_SRC_DIR)/*.hpp $(SUBCOMMAND_SRC_DIR)/*.cpp $(SUBCOMMAND_SRC_DIR)/*.hpp $(UNITTEST_SRC_DIR)/*.cpp $(UNITTEST_SRC_DIR)/*.hpp $(UNITTEST_SUPPORT_SRC_DIR)/*.cpp
scripts/lint.py 1>&2
test: lint $(BIN_DIR)/$(EXE) $(LIB_DIR)/libvg.a test/build_graph $(BIN_DIR)/shuf $(BIN_DIR)/rapper
cd test && prove -v t
# Hide the compiler configuration from the doc tests, so that the ones that
# build code can't pick up libraries out of the vg build itself.
# But still supply vg on the PATH. Hope it knows where its own libraries are.
CFLAGS= CXXFLAGS= CPPFLAGS= LDFLAGS= INCLUDE_FLAGS= LIBRARY_PATH= LD_LIBRARY_PATH= DYLD_LIBRARY_PATH= DYLD_FALLBACK_LIBRARY_PATH= LD_INCLUDE_PATH= CC= CXX= CXX_STANDARD= PATH=$(CWD)/bin:$(PATH) doc/test-docs.sh
# Somebody has been polluting the test directory with temporary files that are not deleted after the tests.
# To make git status more useful, we delete everything that looks like a temporary file.
clean-tests:
cd test && rm -rf tmp && mkdir tmp && mv 2_2.mat build_graph.cpp default.mat tmp && rm -f *.* zipcodes && mv tmp/* . && rmdir tmp
docs: $(SRC_DIR)/*.cpp $(SRC_DIR)/*.hpp $(ALGORITHMS_SRC_DIR)/*.cpp $(ALGORITHMS_SRC_DIR)/*.hpp $(SUBCOMMAND_SRC_DIR)/*.cpp $(SUBCOMMAND_SRC_DIR)/*.hpp $(UNITTEST_SRC_DIR)/*.cpp $(UNITTEST_SRC_DIR)/*.hpp $(UNITTEST_SUPPORT_SRC_DIR)/*.cpp
doxygen
echo "View documentation at: file://$(PWD)/doc/doxygen/html/index.html"
man: doc/wiki/vg-manpage.md doc/man/vg.1
#The manpage markdown has an extra line needed for the actual manpage format
doc/man/vg-manpage.md: $(BIN_DIR)/$(EXE) doc/vgmanmd.desc.md doc/vgmanmd.py
mkdir -p doc/man && ./doc/vgmanmd.py > $@.tmp && mv $@.tmp $@
doc/wiki/vg-manpage.md: doc/man/vg-manpage.md
sed 1d doc/man/vg-manpage.md > $@
doc/man/vg.1: doc/man/vg-manpage.md
pandoc --standalone --to man $< -o $@
# Hack to use gshuf or shuf as appropriate to the platform when testing
$(BIN_DIR)/shuf:
ifeq ($(shell uname -s),Darwin)
ln -s `which gshuf` $(BIN_DIR)/shuf
else
ln -s `which shuf` $(BIN_DIR)/shuf
endif
test/build_graph: test/build_graph.o $(LIB_DIR)/libvg.a
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -o test/build_graph $(PRE_LINK_DEPS) test/build_graph.o $(LD_LIB_DIR_FLAGS) $(LDFLAGS) $(LIB_DIR)/libvg.a $(LD_LIB_FLAGS) $(START_STATIC) $(LD_STATIC_LIB_FLAGS) $(END_STATIC) $(LD_STATIC_LIB_DEPS) $(LD_EXE_LIB_FLAGS)
# UCSC's HX Antimalware endpoint security thinks test/build_graph is Atomic
# macOS Stealer if the debug symbols are in it. It probably isn't. But we
# need to delete the debug symbols or our binary will get deleted shortly
# after being written.
# -g0 and no other -g flags in the build command didn't work.
# Hope we can do this before enpoint security notices.
strip test/build_graph
$(LIB_DIR)/mimalloc.o: $(MIMALLOC_DIR)/src/*.c $(MIMALLOC_DIR)/src/*/*.c $(MIMALLOC_DIR)/src/*/*/*.c $(MIMALLOC_DIR)/include/*.h $(MIMALLOC_DIR)/include/*/*.h $(MIMALLOC_DIR)/CMakeLists.txt
rm -f $(LIB_DIR)/mimalloc.o && rm -Rf $(INC_DIR)/mimalloc $(INC_DIR)/mimalloc*.h && rm -Rf $(MIMALLOC_DIR)/build
cd $(MIMALLOC_DIR) && mkdir -p build && cd build && cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_C_FLAGS="$(CFLAGS)" -DCMAKE_CXX_FLAGS="$(CXXFLAGS)" ..
cd $(MIMALLOC_DIR)/build && $(MAKE) $(FILTER)
cd $(MIMALLOC_DIR)/build && cp -r ../include/* $(CWD)/$(INC_DIR)/ && cp mimalloc.o $(CWD)/$(LIB_DIR)/
# TODO: The normal and debug jemalloc builds can't safely be run at the same time.
$(LIB_DIR)/libjemalloc.a: $(JEMALLOC_DIR)/src/*.c
rm -f $(LIB_DIR)/libjemalloc*.* && rm -Rf $(CWD)/$(INC_DIR)/jemalloc
cd $(JEMALLOC_DIR) && ./autogen.sh && ./configure --enable-prof --disable-libdl --prefix=`pwd` $(FILTER)
cd $(JEMALLOC_DIR) && $(MAKE) clean && $(MAKE) $(FILTER)
cd $(JEMALLOC_DIR) && cp -r include/* $(CWD)/$(INC_DIR)/ && cp lib/libjemalloc.a $(CWD)/$(LIB_DIR)/
$(LIB_DIR)/libjemalloc_debug.a: $(JEMALLOC_DIR)/src/*.c
rm -f $(LIB_DIR)/libjemalloc*.* && rm -Rf $(CWD)/$(INC_DIR)/jemalloc
cd $(JEMALLOC_DIR) && ./autogen.sh && ./configure --enable-prof --disable-libdl --enable-debug --enable-fill --prefix=`pwd` $(FILTER)
cd $(JEMALLOC_DIR) && $(MAKE) clean && $(MAKE) $(FILTER)
cd $(JEMALLOC_DIR) && cp -r include/* $(CWD)/$(INC_DIR)/ && cp lib/libjemalloc.a $(CWD)/$(LIB_DIR)/libjemalloc_debug.a
# Use fake patterns to tell Make that this rule generates all these files when run once.
# Here % should always match "lib" which is a common substring.
# See https://stackoverflow.com/a/19822767
$(LIB_DIR)/%sdsl.a $(LIB_DIR)/%divsufsort.a $(LIB_DIR)/%divsufsort64.a : $(SDSL_DIR)/lib/*.cpp $(SDSL_DIR)/include/sdsl/*.hpp
ifeq ($(shell uname -s),Darwin)
cd $(SDSL_DIR) && AS_INTEGRATED_ASSEMBLER=1 BUILD_PORTABLE=1 CXXFLAGS="-fPIC $(CXXFLAGS)" ./install.sh $(CWD) $(FILTER)
else
cd $(SDSL_DIR) && BUILD_PORTABLE=1 CXXFLAGS="-fPIC $(CXXFLAGS)" ./install.sh $(CWD) $(FILTER)
endif
$(LIB_DIR)/libssw.a: $(SSW_DIR)/*.c $(SSW_DIR)/*.cpp $(SSW_DIR)/*.h
cd $(SSW_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(SSW_DIR) && ar rs $(CWD)/$(LIB_DIR)/libssw.a ssw.o ssw_cpp.o && cp ssw_cpp.h ssw.h $(CWD)/$(INC_DIR)
$(INC_DIR)/gcsa/gcsa.h: $(LIB_DIR)/libgcsa2.a
$(LIB_DIR)/libgcsa2.a: $(LIB_DIR)/libsdsl.a $(LIB_DIR)/libdivsufsort.a $(LIB_DIR)/libdivsufsort64.a $(wildcard $(GCSA2_DIR)/*.cpp) $(wildcard $(GCSA2_DIR)/include/gcsa/*.h)
ifeq ($(shell uname -s),Darwin)
cp -r $(GCSA2_DIR)/include/gcsa $(CWD)/$(INC_DIR)/
cd $(GCSA2_DIR) && $(MAKE) clean && $(MAKE) directories && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" AS_INTEGRATED_ASSEMBLER=1 $(MAKE) lib/libgcsa2.a $(FILTER)
cd $(GCSA2_DIR) && cp lib/libgcsa2.a $(CWD)/$(LIB_DIR)
else
cp -r $(GCSA2_DIR)/include/gcsa $(CWD)/$(INC_DIR)/
cd $(GCSA2_DIR) && $(MAKE) clean && $(MAKE) directories && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) lib/libgcsa2.a $(FILTER)
cd $(GCSA2_DIR) && cp lib/libgcsa2.a $(CWD)/$(LIB_DIR)
endif
$(INC_DIR)/gbwt/dynamic_gbwt.h: $(LIB_DIR)/libgbwt.a
$(LIB_DIR)/libgbwt.a: $(LIB_DIR)/libsdsl.a $(LIB_DIR)/libdivsufsort.a $(LIB_DIR)/libdivsufsort64.a $(wildcard $(GBWT_DIR)/src/*.cpp) $(wildcard $(GBWT_DIR)/include/gbwt/*.h)
ifeq ($(shell uname -s),Darwin)
cp -r $(GBWT_DIR)/include/gbwt $(CWD)/$(INC_DIR)/
cd $(GBWT_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" AS_INTEGRATED_ASSEMBLER=1 $(MAKE) $(FILTER)
cd $(GBWT_DIR) && cp lib/libgbwt.a $(CWD)/$(LIB_DIR)
else
cp -r $(GBWT_DIR)/include/gbwt $(CWD)/$(INC_DIR)/
cd $(GBWT_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(GBWT_DIR) && cp lib/libgbwt.a $(CWD)/$(LIB_DIR)
endif
$(INC_DIR)/gbwtgraph/gbwtgraph.h: $(LIB_DIR)/libgbwtgraph.a
$(LIB_DIR)/libgbwtgraph.a: $(LIB_DIR)/libgbwt.a $(LIB_DIR)/libsdsl.a $(LIB_DIR)/libdivsufsort.a $(LIB_DIR)/libdivsufsort64.a $(LIB_DIR)/libhandlegraph.a $(wildcard $(GBWTGRAPH_DIR)/src/*.cpp) $(wildcard $(GBWTGRAPH_DIR)/include/gbwtgraph/*.h)
ifeq ($(shell uname -s),Darwin)
cp -r $(GBWTGRAPH_DIR)/include/gbwtgraph $(CWD)/$(INC_DIR)/
cd $(GBWTGRAPH_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" AS_INTEGRATED_ASSEMBLER=1 $(MAKE) $(FILTER)
cd $(GBWTGRAPH_DIR) && cp lib/libgbwtgraph.a $(CWD)/$(LIB_DIR)
else
cp -r $(GBWTGRAPH_DIR)/include/gbwtgraph $(CWD)/$(INC_DIR)/
cd $(GBWTGRAPH_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(GBWTGRAPH_DIR) && cp lib/libgbwtgraph.a $(CWD)/$(LIB_DIR)
endif
$(INC_DIR)/kff_io.hpp: $(LIB_DIR)/libkff.a
$(LIB_DIR)/libkff.a: $(KFF_DIR)/kff_io.cpp $(KFF_DIR)/kff_io.hpp.in
ifeq ($(shell uname -s),Darwin)
rm -Rf $(KFF_DIR)/build
cd $(KFF_DIR) && mkdir -p build && cd build && cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_CXX_FLAGS="-fPIC -Wall -Ofast -g $(CXXFLAGS)" ..
cd $(KFF_DIR)/build && AS_INTEGRATED_ASSEMBLER=1 $(MAKE) kff $(FILTER)
cd $(KFF_DIR)/build && cp kff_io.hpp $(CWD)/$(INC_DIR) && cp libkff.a $(CWD)/$(LIB_DIR)
else
rm -Rf $(KFF_DIR)/build
cd $(KFF_DIR) && mkdir -p build && cd build && cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_CXX_FLAGS="-fPIC -Wall -Ofast -g $(CXXFLAGS)" ..
cd $(KFF_DIR)/build && $(MAKE) kff $(FILTER)
cd $(KFF_DIR)/build && cp kff_io.hpp $(CWD)/$(INC_DIR) && cp libkff.a $(CWD)/$(LIB_DIR)
endif
$(INC_DIR)/BooPHF.h: $(BBHASH_DIR)/BooPHF.h
cp $(BBHASH_DIR)/BooPHF.h $(CWD)/$(INC_DIR)
$(INC_DIR)/progress_bar.hpp: $(PROGRESS_BAR_DIR)/progress_bar.hpp
cp $(PROGRESS_BAR_DIR)/progress_bar.hpp $(CWD)/$(INC_DIR)
$(OBJ_DIR)/progress_bar.o: $(PROGRESS_BAR_DIR)/progress_bar.cpp $(PROGRESS_BAR_DIR)/*.hpp
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -c -o $@ $<
$(SHARED_OBJ_DIR)/progress_bar.o: $(PROGRESS_BAR_DIR)/progress_bar.cpp $(PROGRESS_BAR_DIR)/*.hpp
$(CXX) $(INCLUDE_FLAGS) $(CXXFLAGS) -fPIC -c -o $@ $<
# We have this target to clean up the old Protobuf we used to have.
# We can remove it after we no longer care about building properly on a dirty
# build from vg versions that shipped Protobuf themselves.
$(LIB_DIR)/cleaned_old_protobuf_v003: $(wildcard $(LIB_DIR)/libproto*) $(wildcard $(LIB_DIR)/pkgconfig/protobuf*)
rm -f $(LIB_DIR)/cleaned_old_protobuf*
rm -f $(LIB_DIR)/libproto* $(LIB_DIR)/pkgconfig/protobuf* $(BIN_DIR)/protoc
rm -Rf $(INC_DIR)/google/protobuf deps/protobuf
touch $(LIB_DIR)/cleaned_old_protobuf_v003
# We used to ship our own version of boost, but now we use the system version instead.
$(LIB_DIR)/cleaned_old_boost: $(wildcard $(LIB_DIR)/libboost_*) $(wildcard $(INC_DIR)/boost/*)
rm -f $(LIB_DIR)/libboost_*
rm -Rf $(INC_DIR)/boost
touch $(LIB_DIR)/cleaned_old_boost
# We briefly used the system elfutils, and before that built a different
# version of our own, so clear out whatever either left behind.
$(LIB_DIR)/cleaned_old_elfutils_v004:
rm -f $(LIB_DIR)/libelf.a $(LIB_DIR)/libebl.a $(LIB_DIR)/libdwfl.a $(LIB_DIR)/libdwelf.a $(LIB_DIR)/libdw.a $(LIB_DIR)/libeu.a $(LIB_DIR)/libdwfl_stacktrace.a
touch $(LIB_DIR)/cleaned_old_elfutils_v004
# We used to accidentally bring vcflib's intervaltree's copy of catch.hpp into the global include
$(LIB_DIR)/cleaned_old_catch:
rm -f $(INC_DIR)/catch.hpp
touch $(LIB_DIR)/cleaned_old_catch
$(LIB_DIR)/libvgio.a: $(LIB_DIR)/libhts.a $(LIB_DIR)/libhandlegraph.a $(LIB_DIR)/pkgconfig/htslib.pc $(LIB_DIR)/cleaned_old_protobuf_v003 $(LIBVGIO_DIR)/CMakeLists.txt $(LIBVGIO_DIR)/src/*.cpp $(LIBVGIO_DIR)/include/vg/io/*.hpp $(LIBVGIO_DIR)/deps/vg.proto
@protoc --version >/dev/null 2>/dev/null || (echo "Error: protobuf compiler (protoc) not available!" ; exit 1)
rm -f $(CWD)/$(INC_DIR)/vg.pb.h $(CWD)/$(INC_DIR)/vg/vg.pb.h
rm -Rf $(CWD)/$(INC_DIR)/vg/io/
cd $(LIBVGIO_DIR) && rm -Rf CMakeCache.txt CMakeFiles *.cmake install_manifest.txt *.pb.cc *.pb.h *.a && rm -rf build-vg
export CXXFLAGS="$(CXXFLAGS)" && export LDFLAGS="$(LD_LIB_DIR_FLAGS) $(LDFLAGS)" && cd $(LIBVGIO_DIR) && mkdir -p build-vg && cd build-vg && PKG_CONFIG_PATH=$(CWD)/$(LIB_DIR)/pkgconfig:$(PKG_CONFIG_PATH) cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_CXX_STANDARD=$(CXX_STANDARD) -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_PREFIX_PATH="/usr;$(OMP_PREFIXES)" -DCMAKE_INSTALL_PREFIX=$(CWD) -DCMAKE_INSTALL_LIBDIR=lib -DUSE_INSTALLED_LIBHANDLEGRAPH_ONLY=ON .. $(FILTER)
export CXXFLAGS="$(CXXFLAGS)" && export LDFLAGS="$(LD_LIB_DIR_FLAGS) $(LDFLAGS)" && cd $(LIBVGIO_DIR)/build-vg && $(MAKE) clean && VERBOSE=1 $(MAKE) $(FILTER) && $(MAKE) install
$(LIB_DIR)/libhandlegraph.a: $(LIBHANDLEGRAPH_DIR)/src/include/handlegraph/*.hpp $(LIBHANDLEGRAPH_DIR)/src/*.cpp
rm -f $(LIB_DIR)/libhandlegraph.a $(LIB_DIR)/libhandlegraph.$(SHARED_SUFFIX)
rm -Rf $(INC_DIR)/handlegraph $(LIB_DIR)/cmake/libhandlegraph
cd $(LIBHANDLEGRAPH_DIR) && rm -Rf build CMakeCache.txt CMakeFiles
cd $(LIBHANDLEGRAPH_DIR) && mkdir -p build && cd build && CXXFLAGS="$(CXXFLAGS)" cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=$(CWD) -DCMAKE_INSTALL_LIBDIR=lib ..
cd $(LIBHANDLEGRAPH_DIR)/build && $(MAKE) $(FILTER) && $(MAKE) install
# On Linux, libdeflate builds a .so.
# On Mac, it *still* builds an so, which is just a dylib with .so extension.
# On Mac we need to make sure to set the install name. We do that by renaming to dylib.
# We don't just leave it as .so because we need to deal with outdated .so files with no paths set.
$(LIB_DIR)/libdeflate.$(SHARED_SUFFIX): $(LIB_DIR)/libdeflate.a
cd $(LIBDEFLATE_DIR) && cp libdeflate.so $(CWD)/$(LIB_DIR)
touch $(CWD)/$(LIB_DIR)/libdeflate.so
ifeq ($(shell uname -s),Darwin)
mv $(LIB_DIR)/libdeflate.so $(LIB_DIR)/libdeflate.$(SHARED_SUFFIX)
install_name_tool -id $(CWD)/$(LIB_DIR)/libdeflate.$(SHARED_SUFFIX) $(LIB_DIR)/libdeflate.$(SHARED_SUFFIX)
endif
$(LIB_DIR)/libdeflate.a: $(LIBDEFLATE_DIR)/*.h $(LIBDEFLATE_DIR)/lib/*.h $(LIBDEFLATE_DIR)/lib/*/*.h $(LIBDEFLATE_DIR)/lib/*.c $(LIBDEFLATE_DIR)/lib/*/*.c
cd $(LIBDEFLATE_DIR) && V=1 LDFLAGS="$(LDFLAGS) $(LD_RENAMEABLE_FLAGS)" $(MAKE) $(FILTER)
cd $(LIBDEFLATE_DIR) && cp libdeflate.a $(CWD)/$(LIB_DIR) && cp libdeflate.h $(CWD)/$(INC_DIR)
# We build htslib after libdeflate so it can use libdeflate.
# We need to do some wizardry to get it to pick up the right build and target system types on modern autotools.
# We have to do a full build in order to install, to get the pkg-config file so libvgio can link against it.
# We also have to have the shared libdeflate or we will get complaints that the static one is not position independent.
# If we need either the library or the pkg-config file (which we didn't used to ship), run the whole build.
# We use a wildcard match to make sure make understands that both files come from one command run.
# See https://stackoverflow.com/a/3077254
# We also need to make sure that htslib searches itself before system paths, as
# a system path, in case another htslib is installed on the system. Some HTSlib
# headers look for the current HTSlib with <>.
# Under --always-make, htslib's fallback rule for htscodecs.mk would run and
# write through configure's symlink into htscodecs_bundled.mk.
$(LIB_DIR)/libhts%a $(LIB_DIR)/pkgconfig/htslib%pc $(LIB_DIR)/libhts%$(SHARED_SUFFIX): $(LIB_DIR)/libdeflate.a $(LIB_DIR)/libdeflate.$(SHARED_SUFFIX) $(HTSLIB_DIR)/*.c $(HTSLIB_DIR)/*.h $(HTSLIB_DIR)/htslib/*.h $(HTSLIB_DIR)/cram/*.c $(HTSLIB_DIR)/cram/*.h
rm -Rf $(CWD)/$(INC_DIR)/htslib $(CWD)/$(LIB_DIR)/libhts*
cd $(HTSLIB_DIR) && autoreconf -i && autoheader && autoconf || true
cd $(HTSLIB_DIR) && (./configure -n 2>&1 || true) | grep "build system type" | rev | cut -f1 -d' ' | rev >systype.txt
cd $(HTSLIB_DIR) && CFLAGS="-I$(CWD)/$(HTSLIB_DIR) -isystem $(CWD)/$(HTSLIB_DIR) -I$(CWD)/$(INC_DIR) $(CFLAGS)" LDFLAGS="$(LDFLAGS) -L$(CWD)/$(LIB_DIR) $(LD_UTIL_RPATH_FLAGS)" ./configure --with-libdeflate $(HTSLIB_CURL_FLAGS) --disable-plugins --prefix=$(CWD) --host=$$(cat systype.txt) $(FILTER)
cd $(HTSLIB_DIR) && $(MAKE) --assume-old=htscodecs.mk clean && $(MAKE) --assume-old=htscodecs.mk $(FILTER) && $(MAKE) --assume-old=htscodecs.mk install
# Build and install tabixpp for vcflib.
$(LIB_DIR)/libtabixpp.a: $(LIB_DIR)/libhts.a $(TABIXPP_DIR)/*.cpp $(TABIXPP_DIR)/*.hpp
cd $(TABIXPP_DIR) && rm -f tabix.o libtabixpp.a
cd $(TABIXPP_DIR) && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" INCLUDES="$(INCLUDE_FLAGS)" HTS_HEADERS="" $(MAKE) tabix.o $(FILTER)
cd $(TABIXPP_DIR) && ar rcs libtabixpp.a tabix.o
cp $(TABIXPP_DIR)/libtabixpp.a $(LIB_DIR) && cp $(TABIXPP_DIR)/tabix.hpp $(INC_DIR)
echo "Name: tabixpp" > $(LIB_DIR)/pkgconfig/tabixpp.pc
echo "Description: Self-packaged tabixpp" >> $(LIB_DIR)/pkgconfig/tabixpp.pc
echo "Version: 1.0" >> $(LIB_DIR)/pkgconfig/tabixpp.pc
echo "Cflags: -I$(CWD)/$(INC_DIR)" >> $(LIB_DIR)/pkgconfig/tabixpp.pc
echo "Libs: -L$(CWD)/$(LIB_DIR) -ltabixpp" >> $(LIB_DIR)/pkgconfig/tabixpp.pc
# Build vcflib. Build the library and any needed binaries. Install the library
# and headers but not binaries or man pages. We need to build as RelWithDebInfo
# to avoid vcflib using its own
# -march=native, which would conflict with the -march that comes in through
# CXXFLAGS from the vg Dockerfile. We also need to use the magic path hint to
# let CMake find Mac OpenMP. We need to use /usr first for CMake search or
# Ubuntu 22.04 will decide pybind11 is installed in / when actually it is only
# fully installed in /usr.
# We also have to make sure to point at a Python that probably has its headers,
# because there's no way to turn off vcflib's pybind11 build and pybind11 will
# try and use the latest installed Python over the default one that probably
# has headers.
# We now need to tell it to build static libraries, and to make them position-independent so that
# libvg.so can contain them.
# And we also now need to tell it to actually build its bundled WFA.
#
# Note that on MacOS we rely on the Makefile putting GNU coreutils on the PATH
# in order to avoid the dreaded "Could NOT find Threads".
$(LIB_DIR)/libvcflib%a $(LIB_DIR)/libwfa2%a: $(LIB_DIR)/libhts.a $(LIB_DIR)/libtabixpp.a $(VCFLIB_DIR)/src/*.cpp $(VCFLIB_DIR)/src/*.hpp $(VCFLIB_DIR)/contrib/*/*.cpp $(VCFLIB_DIR)/contrib/*/*.h $(LIB_DIR)/cleaned_old_catch
rm -f $(VCFLIB_DIR)/contrib/WFA2-lib/VERSION
env
cd $(VCFLIB_DIR) && rm -Rf build && mkdir build && cd build && PKG_CONFIG_PATH="$(CWD)/$(LIB_DIR)/pkgconfig:$(PKG_CONFIG_PATH)" cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DZIG=OFF -DCMAKE_C_FLAGS="$(CFLAGS)" -DCMAKE_CXX_FLAGS="$(CXXFLAGS)" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=$(CWD) -DCMAKE_PREFIX_PATH="/usr;$(OMP_PREFIXES)" -DPYTHON_EXECUTABLE="$(shell which python3)" -DBUILD_STATIC_LIBS=ON -DBUILD_POSITION_INDEPENDENT_CODE=ON -DWFA_GITMODULE=ON .. && cmake --build . --target vcflib wfa2_static
cp $(VCFLIB_DIR)/contrib/filevercmp/*.h* $(INC_DIR)
cp $(VCFLIB_DIR)/contrib/fastahack/*.h* $(INC_DIR)
cp $(VCFLIB_DIR)/contrib/smithwaterman/*.h* $(INC_DIR)
cp $(VCFLIB_DIR)/contrib/intervaltree/IntervalTree.h $(INC_DIR)
cp $(VCFLIB_DIR)/contrib/multichoose/*.h* $(INC_DIR)
cp $(VCFLIB_DIR)/src/*.h* $(INC_DIR)
cp $(VCFLIB_DIR)/build/libvcflib.a $(LIB_DIR)
cp $(VCFLIB_DIR)/build/contrib/WFA2-lib/libwfa2.a $(LIB_DIR)
$(LIB_DIR)/libgssw.a: $(GSSW_DIR)/src/gssw.c $(GSSW_DIR)/src/gssw.h
cd $(GSSW_DIR) && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(GSSW_DIR) && cp lib/libgssw.a $(CWD)/$(LIB_DIR)/ && cp src/gssw.h $(CWD)/$(INC_DIR)/
$(INC_DIR)/lru_cache.h: $(DEP_DIR)/lru_cache/*.h $(DEP_DIR)/lru_cache/*.cc
cd $(DEP_DIR)/lru_cache && cp *.h* $(CWD)/$(INC_DIR)/
# We moved the Dynamic headers so make sure to clean up the old ones.
$(INC_DIR)/dynamic/dynamic.hpp: $(DYNAMIC_DIR)/include/dynamic/*.hpp $(DYNAMIC_DIR)/include/dynamic/*/*.hpp
rm -Rf $(INC_DIR)/dynamic.hpp $(INC_DIR)/dynamic
# annoyingly doesn't have an install option on the cmake, so we manually move their external dependency headers
rm -Rf $(CWD)/$(DYNAMIC_DIR)/build
cd $(CWD)/$(DYNAMIC_DIR) && mkdir -p build && cd build && export CXXFLAGS="$(CXXFLAGS)" && cmake -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_VERBOSE_MAKEFILE=ON ..
cd $(CWD)/$(DYNAMIC_DIR)/build && export CXXFLAGS="$(CXXFLAGS)" && $(MAKE)
cp -r $(CWD)/$(DYNAMIC_DIR)/deps/hopscotch_map/include/* $(CWD)/$(INC_DIR)/
# Do the copy of the main file last so we can tell if this recipe failed and redo it.
# Otherwise we get dynamic.hpp without its deps
mkdir -p $(INC_DIR)/dynamic && cp -r $(CWD)/$(DYNAMIC_DIR)/include/dynamic/* $(INC_DIR)/dynamic/
$(INC_DIR)/sparsehash/sparse_hash_map: $(wildcard $(SPARSEHASH_DIR)/**/*.cc) $(wildcard $(SPARSEHASH_DIR)/**/*.h)
cd $(SPARSEHASH_DIR) && ./autogen.sh && LDFLAGS="$(LD_LIB_DIR_FLAGS) $(LDFLAGS)" ./configure --prefix=$(CWD) $(FILTER)
cd $(SPARSEHASH_DIR) && $(MAKE) $(AUTOMAKE_MAKEFLAGS) src/sparsehash/internal/sparseconfig.h $(FILTER) && $(MAKE) $(AUTOMAKE_MAKEFLAGS) install-data $(FILTER)
$(INC_DIR)/sparsepp/spp.h: $(wildcard $(SPARSEPP_DIR)/sparsepp/*.h)
cp -r $(SPARSEPP_DIR)/sparsepp $(INC_DIR)/
$(LIB_DIR)/libsonlib.a: $(CWD)/$(DEP_DIR)/sonLib/C/inc/*.h $(CWD)/$(DEP_DIR)/sonLib/C/impl/*.c
cd $(DEP_DIR)/sonLib && $(MAKE) clean && kyotoTycoonLib="" CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(DEP_DIR)/sonLib && cp lib/sonLib.a $(CWD)/$(LIB_DIR)/libsonlib.a && mkdir -p $(CWD)/$(INC_DIR)/sonLib && cp lib/*.h $(CWD)/$(INC_DIR)/sonLib
$(LIB_DIR)/libpinchesandcacti.a: $(LIB_DIR)/libsonlib.a $(CWD)/$(DEP_DIR)/pinchesAndCacti/inc/*.h $(CWD)/$(DEP_DIR)/pinchesAndCacti/impl/*.c
cd $(DEP_DIR)/pinchesAndCacti && $(MAKE) clean && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" $(MAKE) $(FILTER)
cd $(CWD)/$(DEP_DIR)/sonLib && cp lib/stPinchesAndCacti.a $(CWD)/$(LIB_DIR)/libpinchesandcacti.a && cp lib/3EdgeConnected.a $(CWD)/$(LIB_DIR)/lib3edgeconnected.a && mkdir -p $(CWD)/$(INC_DIR)/sonLib && cp lib/*.h $(CWD)/$(INC_DIR)/sonLib
# When building raptor we need to make sure to pre-generate and fix up the lexer
# We also need to clear out its cmake stuff in case it found a wrong Bison and cached it.
$(LIB_DIR)/libraptor2.a: $(RAPTOR_DIR)/src/* $(wildcard $(RAPTOR_DIR)/build/*)
which bison
cd $(RAPTOR_DIR)/build && rm -Rf CMakeCache.txt CMakeFiles CTestTestfile.cmake Makefile cmake_install.cmake src tests utils
cd $(RAPTOR_DIR)/build && CFLAGS="-fPIC $(CFLAGS)" CXXFLAGS="-fPIC $(CXXFLAGS)" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_C_COMPILER="$(CC)" -DCMAKE_CXX_COMPILER="$(CXX)" ..
cd $(RAPTOR_DIR)/build && rm -f src/turtle_parser.c && rm -f src/turtle_lexer.c
cd $(RAPTOR_DIR)/build && $(MAKE) turtle_lexer_tgt && $(MAKE) -f src/CMakeFiles/raptor2.dir/build.make src/turtle_lexer.c
cd $(RAPTOR_DIR)/build && sed -i.bak '/yycleanup/d' src/turtle_lexer.c
cd $(RAPTOR_DIR)/build && $(MAKE) $(FILTER)
cd $(RAPTOR_DIR)/build && cp src/libraptor2.a $(CWD)/$(LIB_DIR)
touch $(LIB_DIR)/libraptor2.a
# We need rapper from Raptor for the tests
$(BIN_DIR)/rapper: $(LIB_DIR)/libraptor2.a
cp $(RAPTOR_DIR)/build/utils/rapper $(BIN_DIR)/
# The Raptor header needs to be newer than the library.
# Mac Travis managed to get an old header with a new binary.
$(INC_DIR)/raptor2/raptor2.h: $(LIB_DIR)/libraptor2.a $(RAPTOR_DIR)/build/*
cd $(RAPTOR_DIR)/build && mkdir -p $(CWD)/$(INC_DIR)/raptor2 && cp src/*.h $(CWD)/$(INC_DIR)/raptor2
touch $(INC_DIR)/raptor2/raptor2.h