Skip to content

Commit

Permalink
Dynamically export bcftools symbols to plugins
Browse files Browse the repository at this point in the history
...instead of linking the plugins against libhts.so.  This simplifies
building and installation, as plugins no longer need to be able to find
libhts.so/.dylib at runtime -- which to date has unfortunately often
been done via $LD_LIBRARY_PATH.

On OS X, build plugins as Mach-O bundles rather than shared libraries
(and ensure that bcftools is built first, so is available for use with
-bundle_loader).  Fixes samtools#225.

(TODO) The advice in print_plugin_usage_hint() should be revisited.

When bcftools is linked to libhts.a statically, there is a small chance
that a plugin will need HTSlib functions that have not been pulled in by
the bcftools executable.  This is surely unlikely, and can be prevented
by linking bcftools or your plugin against a shared libhts.so.

Fixes samtools#249; fixes samtools#224; supersedes and closes samtools#254.
  • Loading branch information
jmarshall committed Nov 10, 2015
1 parent 06ce5a1 commit 2e5fda7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for bcftools, utilities for Variant Call Format VCF/BCF files.
#
# Copyright (C) 2012-2014 Genome Research Ltd.
# Copyright (C) 2012-2015 Genome Research Ltd.
#
# Author: Petr Danecek <pd3@sanger.ac.uk>
#
Expand Down Expand Up @@ -113,8 +113,16 @@ PLUGINC = $(foreach dir, plugins, $(wildcard $(dir)/*.c))
PLUGINS = $(PLUGINC:.c=.so)
PLUGINM = $(PLUGINC:.c=.mk)

%.so: %.c version.h version.c $(HTSDIR)/libhts.so
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ version.c $< -lhts $(LIBS)
ifeq "$(shell uname -s)" "Darwin"
$(PLUGINS): | bcftools

PLUGIN_FLAGS = -bundle -bundle_loader bcftools
else
PLUGIN_FLAGS = -fPIC -shared
endif

%.so: %.c version.h version.c
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ version.c $< $(LIBS)

-include $(PLUGINM)

Expand Down Expand Up @@ -170,10 +178,10 @@ version.o: version.h version.c
test/test-rbuf.o: test/test-rbuf.c rbuf.h

test/test-rbuf: test/test-rbuf.o
$(CC) $(LDFLAGS) -o $@ $^ -lm -ldl $(LIBS)
$(CC) $(LDFLAGS) -o $@ $^ -lm $(LIBS)

bcftools: $(HTSLIB) $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(HTSLIB) -lpthread -lz -lm -ldl $(GSL_LIBS) $(LIBS)
$(CC) -rdynamic $(LDFLAGS) -o $@ $(OBJS) $(HTSLIB) -lpthread -lz -lm -ldl $(GSL_LIBS) $(LIBS)

doc/bcftools.1: doc/bcftools.txt
cd doc && a2x -adate="$(DOC_DATE)" -aversion=$(DOC_VERSION) --doctype manpage --format manpage bcftools.txt
Expand Down
4 changes: 2 additions & 2 deletions plugins/color-chrs.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
plugins/color-chrs.so: plugins/color-chrs.c version.h version.c HMM.h HMM.c $(HTSDIR)/libhts.so
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ HMM.c version.c $< -lhts $(LIBS)
plugins/color-chrs.so: plugins/color-chrs.c version.h version.c HMM.h HMM.c
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ HMM.c version.c $< $(LIBS)
4 changes: 2 additions & 2 deletions plugins/fixploidy.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
plugins/fixploidy.so: plugins/fixploidy.c version.h version.c ploidy.h ploidy.c $(HTSDIR)/libhts.so
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ ploidy.c version.c $< -lhts $(LIBS)
plugins/fixploidy.so: plugins/fixploidy.c version.h version.c ploidy.h ploidy.c
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ ploidy.c version.c $< $(LIBS)
4 changes: 2 additions & 2 deletions plugins/vcf2sex.mk
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
plugins/vcf2sex.so: plugins/vcf2sex.c version.h version.c ploidy.h ploidy.c $(HTSDIR)/libhts.so
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ ploidy.c version.c $< -lhts $(LIBS)
plugins/vcf2sex.so: plugins/vcf2sex.c version.h version.c ploidy.h ploidy.c
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ ploidy.c version.c $< $(LIBS)

0 comments on commit 2e5fda7

Please sign in to comment.