11# Makefile for htslib, a C library for high-throughput sequencing data formats.
22#
3- # Copyright (C) 2013-2022 Genome Research Ltd.
3+ # Copyright (C) 2013-2023 Genome Research Ltd.
44#
55# Author: John Marshall <jm18@sanger.ac.uk>
66#
@@ -39,6 +39,7 @@ CFLAGS = -g -Wall -O2 -fvisibility=hidden
3939EXTRA_CFLAGS_PIC = -fpic
4040TARGET_CFLAGS =
4141LDFLAGS = -fvisibility=hidden
42+ VERSION_SCRIPT_LDFLAGS = -Wl,-version-script,$(srcprefix ) htslib.map
4243LIBS = $(htslib_default_libs )
4344
4445prefix = /usr/local
@@ -58,7 +59,8 @@ MKDIR_P = mkdir -p
5859INSTALL = install -p
5960INSTALL_DATA = $(INSTALL ) -m 644
6061INSTALL_DIR = $(MKDIR_P ) -m 755
61- INSTALL_LIB = $(INSTALL_DATA )
62+ LIB_PERM = 644
63+ INSTALL_LIB = $(INSTALL ) -m $(LIB_PERM )
6264INSTALL_MAN = $(INSTALL_DATA )
6365INSTALL_PROGRAM = $(INSTALL )
6466
@@ -80,6 +82,7 @@ BUILT_TEST_PROGRAMS = \
8082 test/sam \
8183 test/test_bgzf \
8284 test/test_expr \
85+ test/test_faidx \
8386 test/test_kfunc \
8487 test/test_kstring \
8588 test/test_mod \
@@ -140,8 +143,8 @@ LIBHTS_SOVERSION = 3
140143# is not strictly necessary and should be removed the next time
141144# LIBHTS_SOVERSION is bumped (see #1144 and
142145# https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html#//apple_ref/doc/uid/TP40002013-SW23)
143- MACH_O_COMPATIBILITY_VERSION = 3.1.16
144- MACH_O_CURRENT_VERSION = 3.1.16
146+ MACH_O_COMPATIBILITY_VERSION = 3.1.17
147+ MACH_O_CURRENT_VERSION = 3.1.17
145148
146149# $(NUMERIC_VERSION) is for items that must have a numeric X.Y.Z string
147150# even if this is a dirty or untagged Git working tree.
@@ -160,12 +163,20 @@ show-version:
160163 @echo PACKAGE_VERSION = $(PACKAGE_VERSION )
161164 @echo NUMERIC_VERSION = $(NUMERIC_VERSION )
162165
166+ config_vars.h : override escape=$(subst ',\x27,$(subst ",\",$(subst \,\\,$(1 ) ) ) )
167+ config_vars.h : override hts_cc_escaped=$(call escape,$(CC ) )
168+ config_vars.h : override hts_cppflags_escaped=$(call escape,$(CPPFLAGS ) )
169+ config_vars.h : override hts_cflags_escaped=$(call escape,$(CFLAGS ) )
170+ config_vars.h : override hts_ldflags_escaped=$(call escape,$(LDFLAGS ) )
171+ config_vars.h : override hts_libs_escaped=$(call escape,$(LIBS ) )
172+
163173config_vars.h :
164- echo ' #define HTS_CC "$(CC)"' > $@
165- echo ' #define HTS_CPPFLAGS "$(CPPFLAGS)"' >> $@
166- echo ' #define HTS_CFLAGS "$(CFLAGS)"' >> $@
167- echo ' #define HTS_LDFLAGS "$(LDFLAGS)"' >> $@
168- echo ' #define HTS_LIBS "$(LIBS)"' >> $@
174+ printf ' #define HTS_CC "%s"\n#define HTS_CPPFLAGS "%s"\n#define HTS_CFLAGS "%s"\n#define HTS_LDFLAGS "%s"\n#define HTS_LIBS "%s"\n' \
175+ ' $(hts_cc_escaped)' \
176+ ' $(hts_cppflags_escaped)' \
177+ ' $(hts_cflags_escaped)' \
178+ ' $(hts_ldflags_escaped)' \
179+ ' $(hts_libs_escaped)' > $@
169180
170181.SUFFIXES : .bundle .c .cygdll .dll .o .pico .so
171182
@@ -344,7 +355,7 @@ print-config:
344355# file used at runtime (when $LD_LIBRARY_PATH includes the build directory).
345356
346357libhts.so : $(LIBHTS_OBJS:.o=.pico )
347- $(CC ) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION ) $(LDFLAGS ) -o $@ $(LIBHTS_OBJS:.o=.pico ) $(LIBS ) -lpthread
358+ $(CC ) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION ) $(VERSION_SCRIPT_LDFLAGS ) $( LDFLAGS ) -o $@ $(LIBHTS_OBJS:.o=.pico ) $(LIBS ) -lpthread
348359 ln -sf $@ libhts.so.$(LIBHTS_SOVERSION )
349360
350361# Similarly this also creates libhts.NN.dylib as a byproduct, so that programs
@@ -494,7 +505,7 @@ htsfile: htsfile.o libhts.a
494505tabix : tabix.o libhts.a
495506 $(CC ) $(LDFLAGS ) -o $@ tabix.o libhts.a $(LIBS ) -lpthread
496507
497- bgzip.o : bgzip.c config.h $(htslib_bgzf_h ) $(htslib_hts_h )
508+ bgzip.o : bgzip.c config.h $(htslib_bgzf_h ) $(htslib_hts_h ) $( htslib_hfile_h )
498509htsfile.o : htsfile.c config.h $(htslib_hfile_h ) $(htslib_hts_h ) $(htslib_sam_h ) $(htslib_vcf_h )
499510tabix.o : tabix.c config.h $(htslib_tbx_h ) $(htslib_sam_h ) $(htslib_vcf_h ) $(htslib_kseq_h ) $(htslib_bgzf_h ) $(htslib_hts_h ) $(htslib_regidx_h ) $(htslib_hts_defs_h ) $(htslib_hts_log_h )
500511
@@ -583,12 +594,13 @@ check test: all $(HTSCODECS_TEST_TARGETS)
583594 fi
584595 test/test_bgzf test/bgziptest.txt
585596 test/test-parse-reg -t test/colons.bam
597+ cd test/faidx && ./test-faidx.sh faidx.tst
586598 cd test/sam_filter && ./filter.sh filter.tst
587599 cd test/tabix && ./test-tabix.sh tabix.tst
588600 cd test/mpileup && ./test-pileup.sh mpileup.tst
589601 cd test/fastq && ./test-fastq.sh
590602 cd test/base_mods && ./base-mods.sh base-mods.tst
591- REF_PATH=: test/sam test/ce.fa test/faidx.fa test/fastqs.fq
603+ REF_PATH=: test/sam test/ce.fa test/faidx/faidx .fa test/faidx /fastqs.fq
592604 test/test-regidx
593605 cd test && REF_PATH=: ./test.pl $$ {TEST_OPTS:-}
594606
@@ -622,6 +634,9 @@ test/test_bgzf: test/test_bgzf.o libhts.a
622634test/test_expr : test/test_expr.o libhts.a
623635 $(CC ) $(LDFLAGS ) -o $@ test/test_expr.o libhts.a -lz $(LIBS ) -lpthread
624636
637+ test/test_faidx : test/test_faidx.o libhts.a
638+ $(CC ) $(LDFLAGS ) -o $@ test/test_faidx.o libhts.a -lz $(LIBS ) -lpthread
639+
625640test/test_kfunc : test/test_kfunc.o libhts.a
626641 $(CC ) $(LDFLAGS ) -o $@ test/test_kfunc.o libhts.a -lz $(LIBS ) -lpthread
627642
@@ -739,6 +754,7 @@ test/test-regidx.o: test/test-regidx.c config.h $(htslib_kstring_h) $(htslib_reg
739754test/test_str2int.o : test/test_str2int.c config.h $(textutils_internal_h )
740755test/test_time_funcs.o : test/test_time_funcs.c config.h $(hts_time_funcs_h )
741756test/test_view.o : test/test_view.c config.h $(cram_h ) $(htslib_sam_h ) $(htslib_vcf_h ) $(htslib_hts_log_h )
757+ test/test_faidx.o : test/test_faidx.c config.h $(htslib_faidx_h )
742758test/test_index.o : test/test_index.c config.h $(htslib_sam_h ) $(htslib_vcf_h )
743759test/test-vcf-api.o : test/test-vcf-api.c config.h $(htslib_hts_h ) $(htslib_vcf_h ) $(htslib_kstring_h ) $(htslib_kseq_h )
744760test/test-vcf-sweep.o : test/test-vcf-sweep.c config.h $(htslib_vcf_sweep_h )
@@ -789,14 +805,39 @@ header-exports.txt: test/header_syms.pl htslib/*.h
789805 test/header_syms.pl htslib/* .h | sort -u -o $@
790806
791807shlib-exports-so.txt : libhts.so
792- nm -D -g libhts.so | awk ' $$2 == "T" { print $$3 }' | sort -u -o $@
808+ nm -D -g libhts.so | awk ' $$2 == "T" { sub("@.*", "", $$3); print $$3 }' | sort -u -o $@
793809
794810shlib-exports-dylib.txt : libhts.dylib
795811 nm -Ug libhts.dylib | awk ' $$2 == "T" { sub("^_", "", $$3); print $$3 }' | sort -u -o $@
796812
797813shlib-exports-dll.txt : hts.dll.a
798814 nm -g hts.dll.a | awk ' $$2 == "T" { print $$3 }' | sort -u -o $@
799815
816+ $(srcprefix ) htslib.map : libhts.so
817+ LC_ALL=C ; export LC_ALL; \
818+ curr_vers=` expr ' X$(PACKAGE_VERSION)' : ' X\([0-9]*\.[0-9.]*\)' ` ; \
819+ last_vers=` awk ' /^HTSLIB_[0-9](\.[0-9]+)+/ { lv = $$1 } END { print lv }' htslib.map` ; \
820+ if test " x$$ curr_vers" = ' x' || test " x$$ last_vers" = ' x' ; then \
821+ echo " Version check failed : $$ curr_vers / $$ las_vers" 1>&2 ; \
822+ exit 1 ; \
823+ fi && \
824+ if test " HTSLIB_$$ curr_vers" = " $$ last_vers" ; then \
825+ echo " Refusing to update $@ - HTSlib version not changed" 1>&2 ; \
826+ exit 1 ; \
827+ fi && \
828+ nm --with-symbol-versions -D -g libhts.so | awk ' $$2 ~ /^[DGRT]$$/ && $$3 ~ /@@Base$$/ && $$3 !~ /^(_init|_fini|_edata)@@/ { sub(/@@Base$$/, ";", $$3); print " " $$3 }' > $@ .tmp && \
829+ if [ -s $@ .tmp ] ; then \
830+ cat $@ > $@ .new.tmp && \
831+ printf ' \n%s {\n' " HTSLIB_$$ curr_vers" >> $@ .new.tmp && \
832+ cat $@ .tmp >> $@ .new.tmp && \
833+ printf ' } %s;\n' " $$ last_vers" >> $@ .new.tmp && \
834+ rm -f $@ .tmp && \
835+ mv $@ .new.tmp $@ ; \
836+ fi ; \
837+ else \
838+ rm -f $@ .tmp ; \
839+ fi
840+
800841install : libhts.a $(BUILT_PROGRAMS ) $(BUILT_PLUGINS ) installdirs install-$(SHLIB_FLAVOUR ) install-pkgconfig
801842 $(INSTALL_PROGRAM ) $(BUILT_PROGRAMS ) $(DESTDIR )$(bindir )
802843 if test -n " $( BUILT_PLUGINS) " ; then $( INSTALL_PROGRAM) $( BUILT_PLUGINS) $( DESTDIR) $( plugindir) ; fi
@@ -845,7 +886,9 @@ htslib-uninstalled.pc: htslib.pc.tmp
845886
846887
847888testclean :
848- -rm -f test/* .tmp test/* .tmp.* test/longrefs/* .tmp.* test/tabix/* .tmp.* test/tabix/FAIL* header-exports.txt shlib-exports-$(SHLIB_FLAVOUR ) .txt
889+ -rm -f test/* .tmp test/* .tmp.* test/faidx/* .tmp* test/faidx/FAIL* \
890+ test/longrefs/*.tmp.* test/tabix/*.tmp.* test/tabix/FAIL* \
891+ header-exports.txt shlib-exports-$(SHLIB_FLAVOUR).txt
849892 -rm -rf htscodecs/tests/test.out
850893
851894# Only remove this in git checkouts
0 commit comments