Skip to content

Commit

Permalink
[Makefile] Use user's CPPFLAGS/LDFLAGS/LIBS variables
Browse files Browse the repository at this point in the history
Use these variables in relevant compilation and linking rules so they can
be overridden by the user in the usual autoconf-style way.  Fixes samtools#222.

Remove DFLAGS and INCLUDES, using the conventional CPPFLAGS instead.
Add EXTRA_CPPFLAGS in their place, for our own various options that
need to stay set even if the user overrides CPPFLAGS.  If we end up
with necessary compiler or linker options or libraries, we'll add
EXTRA_CFLAGS, EXTRA_LDFLAGS, or EXTRA_LIBS accordingly.

Rename *_LDLIBS to *_LIBS; it seems that LDLIBS doesn't particularly
exist outside GNU Make's built-in rules.  Instead LIBS is configure's
conventional variable for the purpose, so is the right thing to use
for a user-visible variable.
  • Loading branch information
jmarshall committed Mar 16, 2015
1 parent 7fa0d25 commit 54d6c82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,28 @@ BGZIP = $(HTSDIR)/bgzip
TABIX = $(HTSDIR)/tabix

CC = gcc
CPPFLAGS =
CFLAGS = -g -Wall -Wc++-compat -O2
DFLAGS =
LDFLAGS =
LIBS =

OBJS = main.o vcfindex.o tabix.o \
vcfstats.o vcfisec.o vcfmerge.o vcfquery.o vcffilter.o filter.o vcfsom.o \
vcfnorm.o vcfgtcheck.o vcfview.o vcfannotate.o vcfroh.o vcfconcat.o \
vcfcall.o mcall.o vcmp.o gvcf.o reheader.o convert.o vcfconvert.o tsv2vcf.o \
vcfcnv.o HMM.o vcfplugin.o consensus.o ploidy.o version.o \
ccall.o em.o prob1.o kmin.o # the original samtools calling
INCLUDES = -I. -I$(HTSDIR)

EXTRA_CPPFLAGS = -I. -I$(HTSDIR)
GSL_LIBS =

# The polysomy command is not compiled by default because it brings dependency
# on libgsl. The command can be compiled wth `make USE_GPL=1`. See the INSTALL
# and LICENSE documents to understand license implications.
ifdef USE_GPL
CFLAGS += -DUSE_GPL
OBJS += polysomy.o
LDLIBS = -lgsl -lcblas
EXTRA_CPPFLAGS += -DUSE_GPL
OBJS += polysomy.o
GSL_LIBS = -lgsl -lcblas
endif

prefix = /usr/local
Expand Down Expand Up @@ -88,7 +93,7 @@ version.h:
force:

.c.o:
$(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@
$(CC) $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -c -o $@ $<

test: $(PROG) plugins test/test-rbuf $(BGZIP) $(TABIX)
./test/test.pl --exec bgzip=$(BGZIP) --exec tabix=$(TABIX)
Expand All @@ -103,7 +108,7 @@ PLUGINS = $(PLUGINC:.c=.so)
PLUGINM = $(PLUGINC:.c=.mk)

%.so: %.c version.h version.c $(HTSDIR)/libhts.so
$(CC) $(CFLAGS) $(INCLUDES) -fPIC -shared -o $@ version.c $< -L$(HTSDIR) -lhts
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ version.c $< -lhts $(LIBS)

-include $(PLUGINM)

Expand Down Expand Up @@ -156,10 +161,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) $(CFLAGS) -o $@ -lm -ldl $<
$(CC) $(LDFLAGS) -o $@ $^ -lm -ldl $(LIBS)

bcftools: $(HTSLIB) $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(HTSLIB) -lpthread -lz -lm -ldl $(LDLIBS)
$(CC) $(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
2 changes: 1 addition & 1 deletion 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) $(CFLAGS) $(INCLUDES) -fPIC -shared -o $@ ploidy.c version.c $< -L$(HTSDIR) -lhts
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ ploidy.c version.c $< -lhts $(LIBS)
2 changes: 1 addition & 1 deletion 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) $(CFLAGS) $(INCLUDES) -fPIC -shared -o $@ ploidy.c version.c $< -L$(HTSDIR) -lhts
$(CC) -fPIC -shared $(CFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS) -L$(HTSDIR) $(LDFLAGS) -o $@ ploidy.c version.c $< -lhts $(LIBS)

0 comments on commit 54d6c82

Please sign in to comment.