Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. # Makefile for htslib, a C library for high-throughput sequencing data formats.
  2. #
  3. # Copyright (C) 2013-2014 Genome Research Ltd.
  4. #
  5. # Author: John Marshall <jm18@sanger.ac.uk>
  6. CC = gcc
  7. AR = ar
  8. RANLIB = ranlib
  9. # TODO: edit cram code to remove need for -DSAMTOOLS
  10. CPPFLAGS = -I. -DSAMTOOLS=1
  11. # TODO: probably update cram code to make it compile cleanly with -Wc++-compat
  12. CFLAGS = -g -Wall -O2
  13. EXTRA_CFLAGS_PIC = -fpic
  14. LDFLAGS =
  15. LDLIBS =
  16. prefix = /usr/local
  17. exec_prefix = $(prefix)
  18. bindir = $(exec_prefix)/bin
  19. includedir = $(prefix)/include
  20. libdir = $(exec_prefix)/lib
  21. mandir = $(prefix)/share/man
  22. man1dir = $(mandir)/man1
  23. man5dir = $(mandir)/man5
  24. INSTALL = install -p
  25. INSTALL_PROGRAM = $(INSTALL)
  26. INSTALL_DATA = $(INSTALL) -m 644
  27. BUILT_PROGRAMS = \
  28. bgzip \
  29. tabix
  30. BUILT_TEST_PROGRAMS = \
  31. test/fieldarith \
  32. test/hfile \
  33. test/sam \
  34. test/test_view \
  35. test/test-vcf-api \
  36. test/test-vcf-sweep
  37. all: lib-static lib-shared $(BUILT_PROGRAMS) $(BUILT_TEST_PROGRAMS)
  38. HTSPREFIX =
  39. include htslib_vars.mk
  40. lib-static: libhts.a
  41. # $(shell), :=, and ifeq/.../endif are GNU Make-specific. If you don't have
  42. # GNU Make, comment out the parts of this conditional that don't apply.
  43. PLATFORM := $(shell uname -s)
  44. ifeq "$(PLATFORM)" "Darwin"
  45. SHLIB_FLAVOUR = dylib
  46. lib-shared: libhts.dylib
  47. else
  48. SHLIB_FLAVOUR = so
  49. lib-shared: libhts.so
  50. endif
  51. PACKAGE_VERSION = 0.0.1
  52. LIBHTS_SOVERSION = 0
  53. # $(NUMERIC_VERSION) is for items that must have a numeric X.Y.Z string
  54. # even if this is a dirty or untagged Git working tree.
  55. NUMERIC_VERSION = $(PACKAGE_VERSION)
  56. # If building from a Git repository, replace $(PACKAGE_VERSION) with the Git
  57. # description of the working tree: either a release tag with the same value
  58. # as $(PACKAGE_VERSION) above, or an exact description likely based on a tag.
  59. # Much of this is also GNU Make-specific. If you don't have GNU Make and/or
  60. # are not building from a Git repository, comment out this conditional.
  61. ifneq "$(wildcard .git)" ""
  62. original_version := $(PACKAGE_VERSION)
  63. PACKAGE_VERSION := $(shell git describe --always --dirty)
  64. # Unless the Git description matches /\d*\.\d*(\.\d*)?/, i.e., is exactly a tag
  65. # with a numeric name, revert $(NUMERIC_VERSION) to the original version number
  66. # written above, but with the patchlevel field bumped to 255.
  67. ifneq "$(subst ..,.,$(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(PACKAGE_VERSION))))))))))))" "."
  68. empty :=
  69. NUMERIC_VERSION := $(subst $(empty) ,.,$(wordlist 1,2,$(subst ., ,$(original_version))) 255)
  70. endif
  71. # Force version.h to be remade if $(PACKAGE_VERSION) has changed.
  72. version.h: $(if $(wildcard version.h),$(if $(findstring "$(PACKAGE_VERSION)",$(shell cat version.h)),,force))
  73. endif
  74. version.h:
  75. echo '#define HTS_VERSION "$(PACKAGE_VERSION)"' > $@
  76. .SUFFIXES: .c .o .pico
  77. .c.o:
  78. $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
  79. .c.pico:
  80. $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS_PIC) -c -o $@ $<
  81. LIBHTS_OBJS = \
  82. kfunc.o \
  83. knetfile.o \
  84. kstring.o \
  85. bgzf.o \
  86. faidx.o \
  87. hfile.o \
  88. hfile_net.o \
  89. hts.o \
  90. sam.o \
  91. synced_bcf_reader.o \
  92. vcf_sweep.o \
  93. tbx.o \
  94. vcf.o \
  95. vcfutils.o \
  96. cram/cram_codecs.o \
  97. cram/cram_decode.o \
  98. cram/cram_encode.o \
  99. cram/cram_index.o \
  100. cram/cram_io.o \
  101. cram/cram_samtools.o \
  102. cram/cram_stats.o \
  103. cram/files.o \
  104. cram/mFILE.o \
  105. cram/md5.o \
  106. cram/open_trace_file.o \
  107. cram/pooled_alloc.o \
  108. cram/sam_header.o \
  109. cram/string_alloc.o \
  110. cram/thread_pool.o \
  111. cram/vlen.o \
  112. cram/zfio.o
  113. libhts.a: $(LIBHTS_OBJS)
  114. @-rm -f $@
  115. $(AR) -rc $@ $(LIBHTS_OBJS)
  116. -$(RANLIB) $@
  117. # The target here is libhts.so, as that is the built file that other rules
  118. # depend upon and that is used when -lhts appears in other program's recipes.
  119. # As a byproduct invisible to make, libhts.so.NN is also created, as it is the
  120. # file used at runtime (when $LD_LIBRARY_PATH includes the build directory).
  121. libhts.so: $(LIBHTS_OBJS:.o=.pico)
  122. $(CC) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS:.o=.pico) $(LDLIBS) -lz
  123. ln -sf $@ libhts.so.$(LIBHTS_SOVERSION)
  124. # Similarly this also creates libhts.NN.dylib as a byproduct, so that programs
  125. # when run can find this uninstalled shared library (when $DYLD_LIBRARY_PATH
  126. # includes this project's build directory).
  127. libhts.dylib: $(LIBHTS_OBJS)
  128. $(CC) -dynamiclib -install_name $(libdir)/libhts.$(LIBHTS_SOVERSION).dylib -current_version $(NUMERIC_VERSION) -compatibility_version $(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS) $(LDLIBS) -lz
  129. ln -sf $@ libhts.$(LIBHTS_SOVERSION).dylib
  130. cram_h = cram/cram.h $(cram_samtools_h) $(cram_sam_header_h) $(cram_structs_h) $(cram_io_h) cram/cram_encode.h cram/cram_decode.h cram/cram_stats.h cram/cram_codecs.h cram/cram_index.h
  131. cram_io_h = cram/cram_io.h $(cram_misc_h)
  132. cram_misc_h = cram/misc.h cram/os.h
  133. cram_sam_header_h = cram/sam_header.h cram/string_alloc.h cram/pooled_alloc.h htslib/khash.h htslib/kstring.h
  134. cram_samtools_h = cram/cram_samtools.h $(htslib_sam_h) $(cram_sam_header_h)
  135. cram_structs_h = cram/cram_structs.h cram/thread_pool.h cram/string_alloc.h htslib/khash.h
  136. cram_open_trace_file_h = cram/open_trace_file.h cram/mFILE.h
  137. hfile_internal_h = hfile_internal.h $(htslib_hfile_h)
  138. bgzf.o bgzf.pico: bgzf.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(htslib_hfile_h) htslib/khash.h
  139. kstring.o kstring.pico: kstring.c htslib/kstring.h
  140. knetfile.o knetfile.pico: knetfile.c htslib/knetfile.h
  141. hfile.o hfile.pico: hfile.c $(htslib_hfile_h) $(hfile_internal_h)
  142. hfile_net.o hfile_net.pico: hfile_net.c $(hfile_internal_h) htslib/knetfile.h
  143. hts.o hts.pico: hts.c version.h $(htslib_hts_h) $(htslib_bgzf_h) $(cram_h) $(htslib_hfile_h) htslib/khash.h htslib/kseq.h htslib/ksort.h
  144. vcf.o vcf.pico: vcf.c $(htslib_vcf_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_hfile_h) htslib/khash.h htslib/kseq.h htslib/kstring.h
  145. sam.o sam.pico: sam.c $(htslib_sam_h) $(htslib_bgzf_h) $(cram_h) $(htslib_hfile_h) htslib/khash.h htslib/kseq.h htslib/kstring.h
  146. tbx.o tbx.pico: tbx.c $(htslib_tbx_h) $(htslib_bgzf_h) htslib/khash.h
  147. faidx.o faidx.pico: faidx.c config.h $(htslib_bgzf_h) $(htslib_faidx_h) htslib/khash.h htslib/knetfile.h
  148. synced_bcf_reader.o synced_bcf_reader.pico: synced_bcf_reader.c $(htslib_synced_bcf_reader_h) htslib/kseq.h htslib/khash_str2int.h
  149. vcf_sweep.o vcf_sweep.pico: vcf_sweep.c $(htslib_vcf_sweep_h) $(htslib_bgzf_h)
  150. vcfutils.o vcfutils.pico: vcfutils.c $(htslib_vcfutils_h)
  151. kfunc.o kfunc.pico: kfunc.c htslib/kfunc.h
  152. cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c $(cram_h)
  153. cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c $(cram_h) cram/os.h cram/md5.h
  154. cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c $(cram_h) cram/os.h cram/md5.h
  155. cram/cram_index.o cram/cram_index.pico: cram/cram_index.c $(htslib_hfile_h) $(cram_h) cram/os.h cram/zfio.h
  156. cram/cram_io.o cram/cram_io.pico: cram/cram_io.c $(cram_h) cram/os.h cram/md5.h $(cram_open_trace_file_h) $(htslib_hfile_h)
  157. cram/cram_samtools.o cram/cram_samtools.pico: cram/cram_samtools.c $(cram_h) $(htslib_sam_h)
  158. cram/cram_stats.o cram/cram_stats.pico: cram/cram_stats.c $(cram_h) cram/os.h
  159. cram/files.o cram/files.pico: cram/files.c $(cram_misc_h)
  160. cram/mFILE.o cram/mFILE.pico: cram/mFILE.c cram/os.h cram/mFILE.h cram/vlen.h
  161. cram/md5.o cram/md5.pico: cram/md5.c cram/md5.h
  162. cram/open_trace_file.o cram/open_trace_file.pico: cram/open_trace_file.c $(cram_open_trace_file_h) $(cram_misc_h)
  163. cram/pooled_alloc.o cram/pooled_alloc.pico: cram/pooled_alloc.c cram/pooled_alloc.h
  164. cram/sam_header.o cram/sam_header.pico: cram/sam_header.c $(cram_sam_header_h) cram/string_alloc.h
  165. cram/string_alloc.o cram/string_alloc.pico: cram/string_alloc.c cram/string_alloc.h
  166. cram/thread_pool.o cram/thread_pool.pico: cram/thread_pool.c cram/thread_pool.h
  167. cram/vlen.o cram/vlen.pico: cram/vlen.c cram/vlen.h cram/os.h
  168. cram/zfio.o cram/zfio.pico: cram/zfio.c cram/os.h cram/zfio.h
  169. bgzip: bgzip.o libhts.a
  170. $(CC) -pthread $(LDFLAGS) -o $@ bgzip.o libhts.a $(LDLIBS) -lz
  171. tabix: tabix.o libhts.a
  172. $(CC) -pthread $(LDFLAGS) -o $@ tabix.o libhts.a $(LDLIBS) -lz
  173. bgzip.o: bgzip.c $(htslib_bgzf_h) $(htslib_hts_h)
  174. tabix.o: tabix.c $(htslib_tbx_h) $(htslib_sam_h) $(htslib_vcf_h) htslib/kseq.h $(htslib_bgzf_h) $(htslib_hts_h)
  175. check test: $(BUILT_TEST_PROGRAMS)
  176. test/fieldarith test/fieldarith.sam
  177. test/hfile
  178. test/sam
  179. cd test && ./test_view.pl
  180. cd test && ./test.pl
  181. test/fieldarith: test/fieldarith.o libhts.a
  182. $(CC) -pthread $(LDFLAGS) -o $@ test/fieldarith.o libhts.a $(LDLIBS) -lz
  183. test/hfile: test/hfile.o libhts.a
  184. $(CC) $(LDFLAGS) -o $@ test/hfile.o libhts.a $(LDLIBS) -lz
  185. test/sam: test/sam.o libhts.a
  186. $(CC) -pthread $(LDFLAGS) -o $@ test/sam.o libhts.a $(LDLIBS) -lz
  187. test/test_view: test/test_view.o libhts.a
  188. $(CC) -pthread $(LDFLAGS) -o $@ test/test_view.o libhts.a $(LDLIBS) -lz
  189. test/test-vcf-api: test/test-vcf-api.o libhts.a
  190. $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-api.o libhts.a $(LDLIBS) -lz
  191. test/test-vcf-sweep: test/test-vcf-sweep.o libhts.a
  192. $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-sweep.o libhts.a $(LDLIBS) -lz
  193. test/fieldarith.o: test/fieldarith.c $(htslib_sam_h)
  194. test/hfile.o: test/hfile.c $(htslib_hfile_h) $(htslib_hts_defs_h)
  195. test/sam.o: test/sam.c $(htslib_sam_h) htslib/kstring.h
  196. test/test_view.o: test/test_view.c $(cram_h) $(htslib_sam_h)
  197. test/test-vcf-api.o: test/test-vcf-api.c $(htslib_hts_h) $(htslib_vcf_h) htslib/kstring.h
  198. test/test-vcf-sweep.o: test/test-vcf-sweep.c $(htslib_vcf_sweep_h)
  199. install: installdirs install-$(SHLIB_FLAVOUR)
  200. $(INSTALL_PROGRAM) $(BUILT_PROGRAMS) $(DESTDIR)$(bindir)
  201. $(INSTALL_DATA) htslib/*.h $(DESTDIR)$(includedir)/htslib
  202. $(INSTALL_DATA) libhts.a $(DESTDIR)$(libdir)/libhts.a
  203. $(INSTALL_DATA) *.1 $(DESTDIR)$(man1dir)
  204. $(INSTALL_DATA) *.5 $(DESTDIR)$(man5dir)
  205. installdirs:
  206. mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(includedir)/htslib $(DESTDIR)$(libdir) $(DESTDIR)$(man1dir) $(DESTDIR)$(man5dir)
  207. # After installation, the real file in $(libdir) will be libhts.so.X.Y.Z,
  208. # with symlinks libhts.so (used via -lhts during linking of client programs)
  209. # and libhts.so.NN (used by client executables at runtime).
  210. install-so: libhts.so installdirs
  211. $(INSTALL_DATA) libhts.so $(DESTDIR)$(libdir)/libhts.so.$(PACKAGE_VERSION)
  212. ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so
  213. ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so.$(LIBHTS_SOVERSION)
  214. install-dylib: libhts.dylib installdirs
  215. $(INSTALL_PROGRAM) libhts.dylib $(DESTDIR)$(libdir)/libhts.$(PACKAGE_VERSION).dylib
  216. ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.dylib
  217. ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.$(LIBHTS_SOVERSION).dylib
  218. testclean:
  219. -rm -f test/*.tmp test/*.tmp.*
  220. mostlyclean: testclean
  221. -rm -f *.o *.pico cram/*.o cram/*.pico test/*.o test/*.dSYM version.h
  222. clean: mostlyclean clean-$(SHLIB_FLAVOUR)
  223. -rm -f libhts.a $(BUILT_PROGRAMS) $(BUILT_TEST_PROGRAMS)
  224. distclean: clean
  225. -rm -f TAGS
  226. clean-so:
  227. -rm -f libhts.so libhts.so.*
  228. clean-dylib:
  229. -rm -f libhts.dylib libhts.*.dylib
  230. tags:
  231. ctags -f TAGS *.[ch] cram/*.[ch] htslib/*.h
  232. force:
  233. .PHONY: all check clean distclean force install installdirs
  234. .PHONY: lib-shared lib-static mostlyclean tags test testclean
  235. .PHONY: clean-so install-so
  236. .PHONY: clean-dylib install-dylib