Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows compilation. #609

Merged
merged 7 commits into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions .appveyor.yml
@@ -0,0 +1,54 @@
# version format.
# you can use {branch} name in version format too
# version: 1.0.{build}-{branch}
version: 'vers.{build}'

# branches to build
branches:
# Whitelist
only:
- develop

# Blacklist
except:
- gh-pages

# Do not build on tags (GitHub and BitBucket)
skip_tags: true

# Skipping commits affecting specific files (GitHub only). More details here: /docs/appveyor-yml
#skip_commits:
# files:
# - docs/*
# - '**/*.html'

# We use Mingw/Msys, so use pacman for installs
install:
- set HOME=.
- set MSYSTEM=MINGW64
- set PATH=C:/msys64/usr/bin;C:/msys64/mingw64/bin;%PATH%
- set MINGWPREFIX=x86_64-w64-mingw32
- "sh -lc \"pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-curl\""

# The user may have e.g. jkbonfield/bcftools branch FOO and an associated
# jkbonfield/htslib branch FOO. If so use that related htslib, obtained by
# munging $APPVEYOR_REPO_NAME. Otherwise we assume this is a PR only to
# bcftools and should be linked against samtools(org)/htslib develop branch.
clone_script:
- "sh -lc \"if test x$APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME != x ; then git clone --branch=$APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH https://github.com/$APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME $APPVEYOR_BUILD_FOLDER ; else false ; fi || git clone --branch=$APPVEYOR_REPO_BRANCH https://github.com/$APPVEYOR_REPO_NAME $APPVEYOR_BUILD_FOLDER\""
- "sh -lc \"git show-branch --sha1-name HEAD"
- "sh -lc \"git clone --branch=$APPVEYOR_REPO_BRANCH https://github.com/`echo $APPVEYOR_REPO_NAME|sed 's#/bcftools#/htslib#'`.git $APPVEYOR_BUILD_FOLDER/htslib || git clone https://github.com/samtools/htslib.git $APPVEYOR_BUILD_FOLDER/htslib \""
- "sh -lc \"cd $APPVEYOR_BUILD_FOLDER/htslib && git show-branch --sha1-name HEAD\""

build_script:
- set HOME=.
- set MSYSTEM=MINGW64
- set PATH=C:/msys64/usr/bin;C:/msys64/mingw64/bin;%PATH%
- "sh -lc \"(cd htslib; aclocal && autoheader && autoconf)\""
- "sh -lc \"aclocal && autoheader && autoconf && ./configure && make -j2\""

test_script:
- set HOME=.
- set MSYSTEM=MINGW64
- set PATH=C:/msys64/usr/bin;C:/msys64/mingw64/bin;%APPVEYOR_BUILD_FOLDER%/htslib;%PATH%
- "sh -lc \"MSYS2_ARG_CONV_EXCL=* make test-plugins\""
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ bcftools
plugins/*.so
plugins/*.dSYM
plugins/*.P
plugins/*.dll

aclocal.m4
autom4te.cache
Expand Down
78 changes: 57 additions & 21 deletions Makefile
Expand Up @@ -23,6 +23,8 @@
# DEALINGS IN THE SOFTWARE.

CC = gcc
AR = ar
RANLIB = ranlib
CPPFLAGS =
CFLAGS = -g -Wall -Wc++-compat -O2
LDFLAGS =
Expand All @@ -36,11 +38,12 @@ 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 bin.o hclust.o version.o \
vcfcnv.o HMM.o consensus.o ploidy.o bin.o hclust.o version.o \
regidx.o smpl_ilist.o csq.o vcfbuf.o \
mpileup.o bam2bcf.o bam2bcf_indel.o bam_sample.o \
vcfsort.o cols.o \
ccall.o em.o prob1.o kmin.o # the original samtools calling
PLUGIN_OBJS = vcfplugin.o

prefix = /usr/local
exec_prefix = $(prefix)
Expand Down Expand Up @@ -72,12 +75,22 @@ MISC_SCRIPTS = \
misc/run-roh.pl \
misc/vcfutils.pl
TEST_PROGRAMS = test/test-rbuf test/test-regidx

all: $(PROGRAMS) $(TEST_PROGRAMS) plugins
PLUGINC =
PLUGINS =
PLUGINM =

ALL_CPPFLAGS = -I. $(HTSLIB_CPPFLAGS) $(CPPFLAGS)
ALL_LDFLAGS = $(HTSLIB_LDFLAGS) $(LDFLAGS)
ifeq "$(shell uname -o)" "Msys"
ALL_LIBS = -lz $(LIBS)
else
ALL_LIBS = -lz -ldl $(LIBS)
endif

all: $(PROGRAMS) $(TEST_PROGRAMS) plugins

EXTRA_CPPFLAGS =
GSL_LIBS =

# Usually config.mk and config.h are generated by running configure
# or config.status, but if those aren't used create defaults here.
Expand All @@ -88,7 +101,7 @@ config.h:
echo '/* Basic config.h generated by Makefile */' > $@
ifneq "$(PLUGINS_ENABLED)" "no"
echo '#define ENABLE_BCF_PLUGINS 1' >> $@
echo '#define PLUGIN_EXT ".so"' >> $@
echo '#define PLUGIN_EXT "$(PLUGIN_EXT)"' >> $@
endif

include config.mk
Expand Down Expand Up @@ -134,27 +147,42 @@ ifdef USE_GPL
GSL_LIBS ?= -lgsl -lcblas
endif

bcftools: $(OBJS) $(HTSLIB)
$(CC) $(DYNAMIC_FLAGS) -pthread $(ALL_LDFLAGS) -o $@ $(OBJS) $(HTSLIB_LIB) -lm $(ALL_LIBS) $(GSL_LIBS) $(PERL_LIBS)
print-%:
@echo '$*=$($*)'

# Plugin rules
ifneq "$(PLUGINS_ENABLED)" "no"
PLUGINC = $(foreach dir, plugins, $(wildcard $(dir)/*.c))
PLUGINS = $(PLUGINC:.c=$(PLUGIN_EXT))
PLUGINM = $(PLUGINC:.c=.mk)
OBJS += $(PLUGIN_OBJS)

ifneq "$(origin PLATFORM)" "file"
PLATFORM := $(shell uname -s)
endif
ifeq "$(PLATFORM)" "Darwin"
$(PLUGINS): | bcftools
PLUGIN_FLAGS = -bundle -bundle_loader bcftools -Wl,-undefined,dynamic_lookup
else ifeq "$(shell uname -o)" "Msys"
DYNAMIC_FLAGS =
$(PLUGINS): | bcftools
PLUGIN_FLAGS = -fPIC -shared -Wl,-export-all-symbols
PLUGIN_LIBS = libbcftools.a $(HTSLIB_DLL) $(ALL_LIBS)
# On windows, plugins need to be fully linked, including bcftools_version() symbol
# from the application they will be loaded into.
else
PLUGIN_FLAGS = -fPIC -shared
endif

libbcftools.a: $(OBJS)
@-rm -f $@
$(AR) -rc $@ $(OBJS)
-$(RANLIB) $@

vcfplugin.o: EXTRA_CPPFLAGS += -DPLUGINPATH='"$(pluginpath)"'

%.dll: %.c version.h version.c libbcftools.a $(HTSLIB_DLL)
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(EXTRA_CPPFLAGS) $(LDFLAGS) -o $@ version.c $< $(PLUGIN_LIBS)
%.so: %.c version.h version.c
$(CC) $(PLUGIN_FLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(EXTRA_CPPFLAGS) $(LDFLAGS) -o $@ version.c $< $(LIBS)

Expand All @@ -172,9 +200,12 @@ test check: test-no-plugins

endif # PLUGINS_ENABLED

plugins: $(PLUGINS)
bcftools: $(OBJS) $(HTSLIB)
$(CC) $(DYNAMIC_FLAGS) -pthread $(ALL_LDFLAGS) -o $@ $(OBJS) $(HTSLIB_LIB) -lm $(ALL_LIBS) $(GSL_LIBS) $(PERL_LIBS)

plugins: $(PLUGINS)
bcftools_h = bcftools.h $(htslib_hts_defs_h) $(htslib_vcf_h)
bin_h = bin.h $(htslib_hts_h)
call_h = call.h $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) vcmp.h
variantkey_h = variantkey.h
convert_h = convert.h $(htslib_vcf_h) $(variantkey_h)
Expand All @@ -186,6 +217,8 @@ ploidy_h = ploidy.h regidx.h
prob1_h = prob1.h $(htslib_vcf_h) $(call_h)
smpl_ilist_h = smpl_ilist.h $(htslib_vcf_h)
vcfbuf_h = vcfbuf.h $(htslib_vcf_h)
roh_h = HMM.h $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kstring_h) $(htslib_kseq_h) $(bcftools_h)
cnv_h = HMM.h $(htslib_vcf_h) $(htslib_synced_bcf_reader_h)
bam2bcf_h = bam2bcf.h $(htslib_hts_h) $(htslib_vcf_h)
bam_sample_h = bam_sample.h $(htslib_sam_h)

Expand All @@ -202,11 +235,11 @@ vcfisec.o: vcfisec.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfu
vcfmerge.o: vcfmerge.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfutils_h) $(htslib_faidx_h) regidx.h $(bcftools_h) vcmp.h $(htslib_khash_h)
vcfnorm.o: vcfnorm.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_faidx_h) $(htslib_khash_str2int_h) $(bcftools_h) rbuf.h
vcfquery.o: vcfquery.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_khash_str2int_h) $(htslib_vcfutils_h) $(bcftools_h) $(filter_h) $(convert_h)
vcfroh.o: vcfroh.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kstring_h) $(htslib_kseq_h) $(htslib_bgzf_h) $(bcftools_h) HMM.h $(smpl_ilist_h) $(filter_h)
vcfcnv.o: vcfcnv.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kstring_h) $(htslib_kfunc_h) $(htslib_khash_str2int_h) $(bcftools_h) HMM.h rbuf.h
vcfroh.o: vcfroh.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kstring_h) $(htslib_kseq_h) $(htslib_bgzf_h) $(bcftools_h) HMM.h $(smpl_ilist_h) $(filter_h) $(roh_h)
vcfcnv.o: vcfcnv.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_kstring_h) $(htslib_kfunc_h) $(htslib_khash_str2int_h) $(bcftools_h) HMM.h rbuf.h $(cnv_h)
vcfsom.o: vcfsom.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfutils_h) $(bcftools_h)
vcfsort.o: vcfsort.c $(htslib_vcf_h) $(htslib_kstring_h) kheap.h $(bcftools_h)
vcfstats.o: vcfstats.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfutils_h) $(htslib_faidx_h) $(bcftools_h) $(filter_h) bin.h
vcfstats.o: vcfstats.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfutils_h) $(htslib_faidx_h) $(bcftools_h) $(filter_h) $(bin_h)
vcfview.o: vcfview.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(htslib_vcfutils_h) $(bcftools_h) $(filter_h) $(htslib_khash_str2int_h)
reheader.o: reheader.c $(htslib_vcf_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_kseq_h) $(htslib_thread_pool_h) $(bcftools_h) $(khash_str2str_h)
tabix.o: tabix.c $(htslib_bgzf_h) $(htslib_tbx_h)
Expand All @@ -216,19 +249,19 @@ tsv2vcf.o: tsv2vcf.c $(tsv2vcf_h)
em.o: em.c $(htslib_vcf_h) kmin.h $(call_h)
filter.o: filter.c $(htslib_khash_str2int_h) $(htslib_hts_defs_h) $(htslib_vcfutils_h) $(htslib_kfunc_h) config.h $(filter_h) $(bcftools_h)
$(CC) $(CFLAGS) $(ALL_CPPFLAGS) $(EXTRA_CPPFLAGS) $(PERL_CFLAGS) -c -o $@ $<
gvcf.o: gvcf.c $(gvcf_h) $(bcftools_h)
gvcf.o: gvcf.c $(gvcf_h) $(bcftools_h) $(call_h)
kmin.o: kmin.c kmin.h
mcall.o: mcall.c $(htslib_kfunc_h) $(call_h)
prob1.o: prob1.c $(prob1_h)
vcmp.o: vcmp.c $(htslib_hts_h) $(htslib_vcf_h) vcmp.h
ploidy.o: ploidy.c $(htslib_khash_str2int_h) $(htslib_kseq_h) $(htslib_hts_h) $(bcftools_h) $(ploidy_h)
ploidy.o: ploidy.c regidx.h $(htslib_khash_str2int_h) $(htslib_kseq_h) $(htslib_hts_h) $(bcftools_h) $(ploidy_h)
polysomy.o: polysomy.c $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(bcftools_h) peakfit.h
peakfit.o: peakfit.c peakfit.h $(htslib_hts_h) $(htslib_kstring_h)
bin.o: bin.c $(bcftools_h) bin.h
bin.o: bin.c $(bcftools_h) $(bin_h)
cols.o: cols.c cols.h
regidx.o: regidx.c $(htslib_hts_h) $(htslib_kstring_h) $(htslib_kseq_h) $(htslib_khash_str2int_h) regidx.h
consensus.o: consensus.c $(htslib_vcf_h) $(htslib_kstring_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_bgzf_h) regidx.h $(bcftools_h) rbuf.h $(filter_h)
mpileup.o: mpileup.c $(htslib_sam_h) $(htslib_faidx_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) regidx.h $(bcftools_h) $(bam2bcf_h) $(bam_sample_h) $(gvcf_h)
consensus.o: consensus.c $(htslib_hts_h) $(htslib_vcf_h) $(htslib_kstring_h) $(htslib_synced_bcf_reader_h) $(htslib_kseq_h) $(htslib_bgzf_h) regidx.h $(bcftools_h) rbuf.h $(filter_h)
mpileup.o: mpileup.c $(htslib_sam_h) $(htslib_faidx_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) regidx.h $(bcftools_h) $(bam2bcf_h) $(bam_sample_h) $(gvcf_h) $(call_h)
bam2bcf.o: bam2bcf.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_kstring_h) $(htslib_kfunc_h) $(bam2bcf_h) mw.h
bam2bcf_indel.o: bam2bcf_indel.c $(htslib_hts_h) $(htslib_sam_h) $(htslib_khash_str2int_h) $(bam2bcf_h) $(htslib_ksort_h)
bam_sample.o: bam_sample.c $(htslib_hts_h) $(htslib_kstring_h) $(htslib_khash_str2int_h) $(khash_str2str_h) $(bam_sample_h) $(bcftools_h)
Expand All @@ -244,15 +277,18 @@ csq.o: csq.c $(htslib_hts_h) $(htslib_vcf_h) $(htslib_synced_bcf_reader_h) $(hts
# For tests that might use it, set $REF_PATH explicitly to use only reference
# areas within the test suite (or set it to ':' to use no reference areas).
# (regression.sh sets $REF_PATH to a subdirectory itself.)
test-no-plugins: $(PROGRAMS) $(TEST_PROGRAMS) $(BGZIP) $(TABIX)
#
# If using MSYS, avoid poor shell expansion via:
# MSYS2_ARG_CONV_EXCL="*" make check
check test-no-plugins: $(PROGRAMS) $(TEST_PROGRAMS) $(BGZIP) $(TABIX)
./test/test-rbuf
./test/test-regidx
REF_PATH=: ./test/test.pl --exec bgzip=$(BGZIP) --exec tabix=$(TABIX)
REF_PATH=: ./test/test.pl --exec bgzip=$(BGZIP) --exec tabix=$(TABIX) $${TEST_OPTS:-}

test-plugins: $(PROGRAMS) $(TEST_PROGRAMS) $(BGZIP) $(TABIX) plugins
check-plugins test-plugins: $(PROGRAMS) $(TEST_PROGRAMS) $(BGZIP) $(TABIX) plugins
./test/test-rbuf
./test/test-regidx
REF_PATH=: ./test/test.pl --plugins --exec bgzip=$(BGZIP) --exec tabix=$(TABIX)
REF_PATH=: ./test/test.pl --plugins --exec bgzip=$(BGZIP) --exec tabix=$(TABIX) $${TEST_OPTS:-}

test/test-rbuf.o: test/test-rbuf.c rbuf.h

Expand Down Expand Up @@ -287,11 +323,11 @@ install: $(PROGRAMS) $(PLUGINS)
$(INSTALL_PROGRAM) plugins/*.so $(DESTDIR)$(plugindir)

clean: testclean clean-plugins
-rm -f gmon.out *.o *~ $(PROGRAMS) version.h plugins/*.so plugins/*.P
-rm -f gmon.out *.o *.a *~ $(PROGRAMS) version.h plugins/*.so plugins/*.P
-rm -rf *.dSYM plugins/*.dSYM test/*.dSYM

clean-plugins:
-rm -f plugins/*.so plugins/*.P
-rm -f plugins/*.so plugins/*.P plugins/*.dll
-rm -rf plugins/*.dSYM

testclean:
Expand Down
1 change: 1 addition & 0 deletions bam2bcf_indel.c
Expand Up @@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE. */
#include <htslib/hts.h>
#include <htslib/sam.h>
#include <htslib/khash_str2int.h>
#include <htslib/hts_os.h>
#include "bam2bcf.h"

#include <htslib/ksort.h>
Expand Down
1 change: 1 addition & 0 deletions config.mk.in
Expand Up @@ -58,6 +58,7 @@ PLUGIN_EXT = @PLUGIN_EXT@
@Hsource@include $(HTSDIR)/htslib_static.mk
@Hsource@HTSLIB = $(HTSDIR)/libhts.a
@Hsource@HTSLIB_LIB = $(HTSLIB) $(HTSLIB_static_LIBS)
@Hsource@HTSLIB_DLL = $(HTSDIR)/hts.dll.a
@Hsource@HTSLIB_LDFLAGS = $(HTSLIB_static_LDFLAGS)
@Hsource@BGZIP = $(HTSDIR)/bgzip
@Hsource@TABIX = $(HTSDIR)/tabix
Expand Down
48 changes: 41 additions & 7 deletions configure.ac
Expand Up @@ -120,8 +120,18 @@ AS_IF([test "$enable_bcftools_plugins" != "no"], [dnl
[*-cygwin* | *-CYGWIN*],[dnl
host_result="Cygwin DLL"
PLATFORM=CYGWIN
PLUGIN_EXT=.cygdll],

PLUGIN_EXT=.cygdll
],

[*-msys* | *-MSYS* | *-mingw* | *-MINGW*],[dnl
host_result="MSYS dll"
PLATFORM=MSYS
PLUGIN_EXT=.dll
# This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64,
# %lld and %z printf formats work. It also enforces the snprintf to
# be C99 compliant so it returns the correct values (in kstring.c).
CPPFLAGS="$CPPCFLAGS -D_XOPEN_SOURCE=600"],

[*-darwin* | *-Darwin*],[dnl
host_result="Darwin dylib"
PLATFORM=Darwin
Expand All @@ -139,12 +149,20 @@ AS_IF([test "$enable_bcftools_plugins" != "no"], [dnl
AC_DEFINE([ENABLE_BCF_PLUGINS], 1,
[Define if BCFtools should enable plugins.])

AC_SEARCH_LIBS([dlopen], [dl], [],
[AC_MSG_ERROR([dlopen() not found

AS_CASE([$PLUGIN_EXT],
[*cygdll | *so],
[AC_SEARCH_LIBS([dlopen], [dl], [],
[AC_MSG_ERROR([dlopen() not found
Plugin support requires dynamic linking facilities from the operating system.
Either configure with --disable-bcftools-plugins or resolve this error to
build bcftools.])])],
[*dll],
[AC_SEARCH_LIBS([LoadLibraryA], [], [],
[AC_MSG_ERROR([LoadLibraryA() not found
Plugin support requires dynamic linking facilities from the operating system.
Either configure with --disable-bcftools-plugins or resolve this error to
build bcftools.])])
build bcftools.])])],
)

AC_MSG_CHECKING([if the compiler accepts -rdynamic])
save_CFLAGS=$CFLAGS
Expand All @@ -156,7 +174,6 @@ build bcftools.])])
[CC_RDYNAMIC_OPT=-rdynamic],[CC_RDYNAMIC_OPT=])
AC_SUBST([CC_RDYNAMIC_OPT])
])

save_LIBS=$LIBS
zlib_devel=ok
dnl Set a trivial non-empty INCLUDES to avoid excess default includes tests
Expand Down Expand Up @@ -226,6 +243,23 @@ AS_IF([test "$enable_perl_filters" != "no" ], [dnl
dnl Apply value from HTS_PROG_CC_WERROR (if set)
AS_IF([test "x$hts_late_cflags" != x],[CFLAGS="$CFLAGS $hts_late_cflags"])

dnl Look for regcomp in various libraries (needed on windows/mingw).
AC_SEARCH_LIBS(regcomp, regex, [libregex=needed], [])

dnl Force POSIX mode on Windows/Mingw
test -n "$host_alias" || host_alias=unknown-`uname -s`
case $host_alias in
*-msys* | *-MSYS* | *-mingw* | *-MINGW*)
host_result="MSYS dll"
PLATFORM=MSYS
PLUGIN_EXT=.dll
# This also sets __USE_MINGW_ANSI_STDIO which in turn makes PRId64,
# %lld and %z printf formats work. It also enforces the snprintf to
# be C99 compliant so it returns the correct values (in kstring.c).
CPPFLAGS="$CPPCFLAGS -D_XOPEN_SOURCE=600"
;;
esac

AC_CONFIG_FILES([config.mk])
AC_OUTPUT

Expand Down