comparison ezBAMQC/src/htslib/Makefile @ 0:dfa3745e5fd8

Uploaded
author youngkim
date Thu, 24 Mar 2016 17:12:52 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfa3745e5fd8
1 # Makefile for htslib, a C library for high-throughput sequencing data formats.
2 #
3 # Copyright (C) 2013-2015 Genome Research Ltd.
4 #
5 # Author: John Marshall <jm18@sanger.ac.uk>
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
24
25 CC = gcc
26 AR = ar
27 RANLIB = ranlib
28
29 CPPFLAGS = -I.
30 # TODO: probably update cram code to make it compile cleanly with -Wc++-compat
31 CFLAGS = -g -Wall -O2
32 EXTRA_CFLAGS_PIC = -fPIC
33 LDFLAGS =
34 LDLIBS =
35
36 # For now these don't work too well as samtools also needs to know to
37 # add -lbz2 and -llzma if linking against the static libhts.a library.
38 # TODO This needs configury and adding to htslib.pc.in.
39 #
40 # # Bzip2 support; optionally used by CRAM.
41 # HAVE_LIBBZ2 := $(shell echo -e "\#include <bzlib.h>\012int main(void){return 0;}" > .test.c && $(CC) $(CFLAGS) $(CPPFLAGS) -o .test .test.c -lbz2 2>/dev/null && echo yes)
42 # ifeq "$(HAVE_LIBBZ2)" "yes"
43 # CPPFLAGS += -DHAVE_LIBBZ2
44 # LDLIBS += -lbz2
45 # endif
46 #
47 # # Lzma support; optionally used by CRAM.
48 # HAVE_LIBLZMA := $(shell echo -e "\#include <lzma.h>\012int main(void){return 0;}" > .test.c && $(CC) $(CFLAGS) $(CPPFLAGS) -o .test .test.c -llzma 2>/dev/null && echo yes)
49 # ifeq "$(HAVE_LIBLZMA)" "yes"
50 # CPPFLAGS += -DHAVE_LIBLZMA
51 # LDLIBS += -llzma
52 # endif
53
54 prefix = /usr/local
55 exec_prefix = $(prefix)
56 bindir = $(exec_prefix)/bin
57 includedir = $(prefix)/include
58 libdir = $(exec_prefix)/lib
59 datarootdir = $(prefix)/share
60 mandir = $(datarootdir)/man
61 man1dir = $(mandir)/man1
62 man5dir = $(mandir)/man5
63 pkgconfigdir= $(libdir)/pkgconfig
64
65 MKDIR_P = mkdir -p
66 INSTALL = install -p
67 INSTALL_PROGRAM = $(INSTALL)
68 INSTALL_DATA = $(INSTALL) -m 644
69 INSTALL_DIR = $(MKDIR_P) -m 755
70
71 BUILT_PROGRAMS = \
72 bgzip \
73 htsfile \
74 tabix
75
76 BUILT_TEST_PROGRAMS = \
77 test/fieldarith \
78 test/hfile \
79 test/sam \
80 test/test-regidx \
81 test/test_view \
82 test/test-vcf-api \
83 test/test-vcf-sweep
84
85 all: lib-static lib-shared $(BUILT_PROGRAMS) $(BUILT_TEST_PROGRAMS)
86
87 HTSPREFIX =
88 include htslib_vars.mk
89
90 lib-static: libhts.a
91
92 # $(shell), :=, and ifeq/.../endif are GNU Make-specific. If you don't have
93 # GNU Make, comment out the parts of this conditional that don't apply.
94 PLATFORM := $(shell uname -s)
95 ifeq "$(PLATFORM)" "Darwin"
96 SHLIB_FLAVOUR = dylib
97 lib-shared: libhts.dylib
98 else
99 SHLIB_FLAVOUR = so
100 lib-shared: libhts.so
101 endif
102
103
104 PACKAGE_VERSION = 1.2.1
105 LIBHTS_SOVERSION = 1
106
107
108 # $(NUMERIC_VERSION) is for items that must have a numeric X.Y.Z string
109 # even if this is a dirty or untagged Git working tree.
110 NUMERIC_VERSION = $(PACKAGE_VERSION)
111
112 # If building from a Git repository, replace $(PACKAGE_VERSION) with the Git
113 # description of the working tree: either a release tag with the same value
114 # as $(PACKAGE_VERSION) above, or an exact description likely based on a tag.
115 # Much of this is also GNU Make-specific. If you don't have GNU Make and/or
116 # are not building from a Git repository, comment out this conditional.
117 ifneq "$(wildcard .git)" ""
118 original_version := $(PACKAGE_VERSION)
119 PACKAGE_VERSION := $(shell git describe --always --dirty)
120
121 # Unless the Git description matches /\d*\.\d*(\.\d*)?/, i.e., is exactly a tag
122 # with a numeric name, revert $(NUMERIC_VERSION) to the original version number
123 # written above, but with the patchlevel field bumped to 255.
124 ifneq "$(subst ..,.,$(subst 0,,$(subst 1,,$(subst 2,,$(subst 3,,$(subst 4,,$(subst 5,,$(subst 6,,$(subst 7,,$(subst 8,,$(subst 9,,$(PACKAGE_VERSION))))))))))))" "."
125 empty :=
126 NUMERIC_VERSION := $(subst $(empty) ,.,$(wordlist 1,2,$(subst ., ,$(original_version))) 255)
127 endif
128
129 # Force version.h to be remade if $(PACKAGE_VERSION) has changed.
130 version.h: $(if $(wildcard version.h),$(if $(findstring "$(PACKAGE_VERSION)",$(shell cat version.h)),,force))
131 endif
132
133 version.h:
134 echo '#define HTS_VERSION "$(PACKAGE_VERSION)"' > $@
135
136 print-version:
137 @echo $(PACKAGE_VERSION)
138
139
140 .SUFFIXES: .c .o .pico
141
142 .c.o:
143 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
144
145 .c.pico:
146 $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS_PIC) -c -o $@ $<
147
148
149 LIBHTS_OBJS = \
150 kfunc.o \
151 knetfile.o \
152 kstring.o \
153 bgzf.o \
154 faidx.o \
155 hfile.o \
156 hfile_net.o \
157 hts.o \
158 regidx.o \
159 sam.o \
160 synced_bcf_reader.o \
161 vcf_sweep.o \
162 tbx.o \
163 vcf.o \
164 vcfutils.o \
165 cram/cram_codecs.o \
166 cram/cram_decode.o \
167 cram/cram_encode.o \
168 cram/cram_index.o \
169 cram/cram_io.o \
170 cram/cram_samtools.o \
171 cram/cram_stats.o \
172 cram/files.o \
173 cram/mFILE.o \
174 cram/md5.o \
175 cram/open_trace_file.o \
176 cram/pooled_alloc.o \
177 cram/rANS_static.o \
178 cram/sam_header.o \
179 cram/string_alloc.o \
180 cram/thread_pool.o \
181 cram/vlen.o \
182 cram/zfio.o
183
184 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
185 cram_io_h = cram/cram_io.h $(cram_misc_h)
186 cram_misc_h = cram/misc.h cram/os.h
187 cram_sam_header_h = cram/sam_header.h cram/string_alloc.h cram/pooled_alloc.h htslib/khash.h htslib/kstring.h
188 cram_samtools_h = cram/cram_samtools.h $(htslib_sam_h) $(cram_sam_header_h)
189 cram_structs_h = cram/cram_structs.h cram/thread_pool.h cram/string_alloc.h htslib/khash.h
190 cram_open_trace_file_h = cram/open_trace_file.h cram/mFILE.h
191 hfile_internal_h = hfile_internal.h $(htslib_hfile_h)
192
193
194 # To be effective, config.mk needs to appear after most Makefile variables are
195 # set but before most rules appear, so that it can both use previously-set
196 # variables in its own rules' prerequisites and also update variables for use
197 # in later rules' prerequisites.
198
199 # sinclude is GNU Make-specific. If you don't have GNU Make or another make
200 # that understands sinclude, change this to 'include' if you are using the
201 # configure script or just comment the line out if you are not.
202 sinclude config.mk
203
204
205 libhts.a: $(LIBHTS_OBJS:.o=.pico)
206 @-rm -f $@
207 $(AR) -rc $@ $(LIBHTS_OBJS:.o=.pico)
208 -$(RANLIB) $@
209
210
211 # The target here is libhts.so, as that is the built file that other rules
212 # depend upon and that is used when -lhts appears in other program's recipes.
213 # As a byproduct invisible to make, libhts.so.NN is also created, as it is the
214 # file used at runtime (when $LD_LIBRARY_PATH includes the build directory).
215
216 libhts.so: $(LIBHTS_OBJS:.o=.pico)
217 $(CC) -shared -Wl,-soname,libhts.so.$(LIBHTS_SOVERSION) -pthread $(LDFLAGS) -o $@ $(LIBHTS_OBJS:.o=.pico) $(LDLIBS) -lz -lm
218 ln -sf $@ libhts.so.$(LIBHTS_SOVERSION)
219
220 # Similarly this also creates libhts.NN.dylib as a byproduct, so that programs
221 # when run can find this uninstalled shared library (when $DYLD_LIBRARY_PATH
222 # includes this project's build directory).
223
224 libhts.dylib: $(LIBHTS_OBJS)
225 $(CC) -dynamiclib -install_name $(libdir)/libhts.$(LIBHTS_SOVERSION).dylib -current_version $(NUMERIC_VERSION) -compatibility_version $(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS) $(LDLIBS) -lz
226 ln -sf $@ libhts.$(LIBHTS_SOVERSION).dylib
227
228
229 bgzf.o bgzf.pico: bgzf.c $(htslib_hts_h) $(htslib_bgzf_h) $(htslib_hfile_h) htslib/khash.h
230 kstring.o kstring.pico: kstring.c htslib/kstring.h
231 knetfile.o knetfile.pico: knetfile.c htslib/knetfile.h
232 hfile.o hfile.pico: hfile.c $(htslib_hfile_h) $(hfile_internal_h)
233 hfile_irods.o hfile_irods.pico: hfile_irods.c $(hfile_internal_h)
234 hfile_net.o hfile_net.pico: hfile_net.c $(hfile_internal_h) htslib/knetfile.h
235 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
236 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
237 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
238 tbx.o tbx.pico: tbx.c $(htslib_tbx_h) $(htslib_bgzf_h) htslib/khash.h
239 faidx.o faidx.pico: faidx.c $(htslib_bgzf_h) $(htslib_faidx_h) $(htslib_hfile_h) htslib/khash.h
240 synced_bcf_reader.o synced_bcf_reader.pico: synced_bcf_reader.c $(htslib_synced_bcf_reader_h) htslib/kseq.h htslib/khash_str2int.h
241 vcf_sweep.o vcf_sweep.pico: vcf_sweep.c $(htslib_vcf_sweep_h) $(htslib_bgzf_h)
242 vcfutils.o vcfutils.pico: vcfutils.c $(htslib_vcfutils_h)
243 kfunc.o kfunc.pico: kfunc.c htslib/kfunc.h
244 regidx.o regidx.pico: regidx.c $(htslib_hts_h) $(HTSPREFIX)htslib/kstring.h $(HTSPREFIX)htslib/kseq.h $(HTSPREFIX)htslib/khash_str2int.h $(htslib_regidx_h)
245
246 cram/cram_codecs.o cram/cram_codecs.pico: cram/cram_codecs.c $(cram_h)
247 cram/cram_decode.o cram/cram_decode.pico: cram/cram_decode.c $(cram_h) cram/os.h cram/md5.h
248 cram/cram_encode.o cram/cram_encode.pico: cram/cram_encode.c $(cram_h) cram/os.h cram/md5.h
249 cram/cram_index.o cram/cram_index.pico: cram/cram_index.c $(htslib_hfile_h) $(cram_h) cram/os.h cram/zfio.h
250 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) cram/rANS_static.h $(htslib_hfile_h)
251 cram/cram_samtools.o cram/cram_samtools.pico: cram/cram_samtools.c $(cram_h) $(htslib_sam_h)
252 cram/cram_stats.o cram/cram_stats.pico: cram/cram_stats.c $(cram_h) cram/os.h
253 cram/files.o cram/files.pico: cram/files.c $(cram_misc_h)
254 cram/mFILE.o cram/mFILE.pico: cram/mFILE.c cram/os.h cram/mFILE.h cram/vlen.h
255 cram/md5.o cram/md5.pico: cram/md5.c cram/md5.h
256 cram/open_trace_file.o cram/open_trace_file.pico: cram/open_trace_file.c $(cram_open_trace_file_h) $(cram_misc_h) $(htslib_hfile_h)
257 cram/pooled_alloc.o cram/pooled_alloc.pico: cram/pooled_alloc.c cram/pooled_alloc.h
258 cram/rANS_static.o cram/rANS_static.pico: cram/rANS_static.c cram/rANS_static.h cram/rANS_byte.h
259 cram/sam_header.o cram/sam_header.pico: cram/sam_header.c $(cram_sam_header_h) cram/string_alloc.h
260 cram/string_alloc.o cram/string_alloc.pico: cram/string_alloc.c cram/string_alloc.h
261 cram/thread_pool.o cram/thread_pool.pico: cram/thread_pool.c cram/thread_pool.h
262 cram/vlen.o cram/vlen.pico: cram/vlen.c cram/vlen.h cram/os.h
263 cram/zfio.o cram/zfio.pico: cram/zfio.c cram/os.h cram/zfio.h
264
265
266 bgzip: bgzip.o libhts.a
267 $(CC) -pthread $(LDFLAGS) -o $@ bgzip.o libhts.a $(LDLIBS) -lz
268
269 htsfile: htsfile.o libhts.a
270 $(CC) -pthread $(LDFLAGS) -o $@ htsfile.o libhts.a $(LDLIBS) -lz
271
272 tabix: tabix.o libhts.a
273 $(CC) -pthread $(LDFLAGS) -o $@ tabix.o libhts.a $(LDLIBS) -lz
274
275 bgzip.o: bgzip.c $(htslib_bgzf_h) $(htslib_hts_h)
276 htsfile.o: htsfile.c $(htslib_hfile_h) $(htslib_hts_h) $(htslib_sam_h) $(htslib_vcf_h)
277 tabix.o: tabix.c $(htslib_tbx_h) $(htslib_sam_h) $(htslib_vcf_h) htslib/kseq.h $(htslib_bgzf_h) $(htslib_hts_h)
278
279
280 # For tests that might use it, set $REF_PATH explicitly to use only reference
281 # areas within the test suite (or set it to ':' to use no reference areas).
282 check test: $(BUILT_TEST_PROGRAMS)
283 test/fieldarith test/fieldarith.sam
284 test/hfile
285 test/sam test/ce.fa
286 test/test-regidx
287 cd test && REF_PATH=: ./test_view.pl
288 cd test && ./test.pl
289
290 test/fieldarith: test/fieldarith.o libhts.a
291 $(CC) -pthread $(LDFLAGS) -o $@ test/fieldarith.o libhts.a $(LDLIBS) -lz
292
293 test/hfile: test/hfile.o libhts.a
294 $(CC) $(LDFLAGS) -o $@ test/hfile.o libhts.a $(LDLIBS) -lz
295
296 test/sam: test/sam.o libhts.a
297 $(CC) -pthread $(LDFLAGS) -o $@ test/sam.o libhts.a $(LDLIBS) -lz
298
299 test/test-regidx: test/test-regidx.o libhts.a
300 $(CC) -pthread $(LDFLAGS) -o $@ test/test-regidx.o libhts.a $(LDLIBS) -lz
301
302 test/test_view: test/test_view.o libhts.a
303 $(CC) -pthread $(LDFLAGS) -o $@ test/test_view.o libhts.a $(LDLIBS) -lz
304
305 test/test-vcf-api: test/test-vcf-api.o libhts.a
306 $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-api.o libhts.a $(LDLIBS) -lz
307
308 test/test-vcf-sweep: test/test-vcf-sweep.o libhts.a
309 $(CC) -pthread $(LDFLAGS) -o $@ test/test-vcf-sweep.o libhts.a $(LDLIBS) -lz
310
311 test/fieldarith.o: test/fieldarith.c $(htslib_sam_h)
312 test/hfile.o: test/hfile.c $(htslib_hfile_h) $(htslib_hts_defs_h)
313 test/test-regidx.o: test/test-regidx.c $(htslib_regidx_h)
314 test/sam.o: test/sam.c $(htslib_sam_h) $(htslib_faidx_h) htslib/kstring.h
315 test/test_view.o: test/test_view.c $(cram_h) $(htslib_sam_h)
316 test/test-vcf-api.o: test/test-vcf-api.c $(htslib_hts_h) $(htslib_vcf_h) htslib/kstring.h
317 test/test-vcf-sweep.o: test/test-vcf-sweep.c $(htslib_vcf_sweep_h)
318
319
320 install: libhts.a $(BUILT_PROGRAMS) installdirs install-$(SHLIB_FLAVOUR) install-pkgconfig
321 $(INSTALL_PROGRAM) $(BUILT_PROGRAMS) $(DESTDIR)$(bindir)
322 $(INSTALL_DATA) htslib/*.h $(DESTDIR)$(includedir)/htslib
323 $(INSTALL_DATA) libhts.a $(DESTDIR)$(libdir)/libhts.a
324 $(INSTALL_DATA) htsfile.1 tabix.1 $(DESTDIR)$(man1dir)
325 $(INSTALL_DATA) faidx.5 sam.5 vcf.5 $(DESTDIR)$(man5dir)
326
327 installdirs:
328 $(INSTALL_DIR) $(DESTDIR)$(bindir) $(DESTDIR)$(includedir) $(DESTDIR)$(includedir)/htslib $(DESTDIR)$(libdir) $(DESTDIR)$(man1dir) $(DESTDIR)$(man5dir) $(DESTDIR)$(pkgconfigdir)
329
330 # After installation, the real file in $(libdir) will be libhts.so.X.Y.Z,
331 # with symlinks libhts.so (used via -lhts during linking of client programs)
332 # and libhts.so.NN (used by client executables at runtime).
333
334 install-so: libhts.so installdirs
335 $(INSTALL_DATA) libhts.so $(DESTDIR)$(libdir)/libhts.so.$(PACKAGE_VERSION)
336 ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so
337 ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so.$(LIBHTS_SOVERSION)
338
339 install-dylib: libhts.dylib installdirs
340 $(INSTALL_PROGRAM) libhts.dylib $(DESTDIR)$(libdir)/libhts.$(PACKAGE_VERSION).dylib
341 ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.dylib
342 ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.$(LIBHTS_SOVERSION).dylib
343
344 # Substitute these pseudo-autoconf variables only at install time
345 # so that "make install prefix=/prefix/path" etc continue to work.
346 install-pkgconfig: installdirs
347 sed -e 's#@includedir@#$(includedir)#g;s#@libdir@#$(libdir)#g;s#@PACKAGE_VERSION@#$(PACKAGE_VERSION)#g' htslib.pc.in > $(DESTDIR)$(pkgconfigdir)/htslib.pc
348 chmod 644 $(DESTDIR)$(pkgconfigdir)/htslib.pc
349
350 # A pkg-config file (suitable for copying to $PKG_CONFIG_PATH) that provides
351 # flags for building against the uninstalled library in this build directory.
352 htslib-uninstalled.pc: htslib.pc.in
353 sed -e 's#@includedir@#'`pwd`'#g;s#@libdir@#'`pwd`'#g' htslib.pc.in > $@
354
355
356 testclean:
357 -rm -f test/*.tmp test/*.tmp.*
358
359 mostlyclean: testclean
360 -rm -f *.o *.pico cram/*.o cram/*.pico test/*.o test/*.dSYM version.h
361
362 clean: mostlyclean clean-$(SHLIB_FLAVOUR)
363 -rm -f libhts.a $(BUILT_PROGRAMS) $(BUILT_TEST_PROGRAMS)
364
365 distclean: clean
366 -rm -f config.cache config.log config.mk config.status
367 -rm -f TAGS *-uninstalled.pc
368
369 clean-so:
370 -rm -f libhts.so libhts.so.*
371
372 clean-dylib:
373 -rm -f libhts.dylib libhts.*.dylib
374
375
376 tags:
377 ctags -f TAGS *.[ch] cram/*.[ch] htslib/*.h
378
379
380 force:
381
382
383 .PHONY: all check clean distclean force install install-pkgconfig installdirs
384 .PHONY: lib-shared lib-static mostlyclean print-version tags test testclean
385 .PHONY: clean-so install-so
386 .PHONY: clean-dylib install-dylib