From 255cf57be6f6a4c65e272505cd0c40a52ea3057d Mon Sep 17 00:00:00 2001 From: James Bonfield Date: Thu, 13 Jan 2022 17:37:59 +0000 Subject: [PATCH] Improve windows build. Specifically we create the extra files needed for MSVC linkage, and document the MSYS2/MINGW setup process. Also added a win-dist target which attempts to produce a directory structure suitable for binary distribution. This isn't executed by default, but is a good aide-memoire and to simplify testing compatibility with things like MSVC. Ideally we'd have a similar mechanism for all platforms to permit easy creation of binary distributions (see #533). --- .appveyor.yml | 2 +- INSTALL | 21 +++++++++++++++++++++ Makefile | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index eb3059750..dfb378645 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -27,7 +27,7 @@ install: - 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-autotools mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-curl\"" + - "sh -lc \"pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-autotools mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-tools-git mingw-w64-x86_64-llvm\"" build_script: - set HOME=. diff --git a/INSTALL b/INSTALL index d0eb638c5..a11792711 100644 --- a/INSTALL +++ b/INSTALL @@ -269,3 +269,24 @@ OpenSUSE -------- sudo zypper install autoconf automake make gcc perl zlib-devel libbz2-devel xz-devel libcurl-devel libopenssl-devel + +Windows MSYS2/MINGW64 +--------------------- + +Follow MSYS2 installation instructions at +https://www.msys2.org/wiki/MSYS2-installation/ + +Then relaunch to MSYS2 shell using the "MSYS2 MinGW x64" executable. +Once in that environment (check $MSYSTEM equals "MINGW64") install the +compilers using pacman -S and the following package list: + +base-devel mingw-w64-x86_64-toolchain +mingw-w64-x86_64-libdeflate mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 +mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-autotools +mingw-w64-x86_64-tools-git mingw-w64-x86_64-llvm + +(Those last two install gendef and llvm-dlltool and are only needed +for building libraries compatible with MSVC.) + +A working binary distribution may then be made using "./configure && +make win-dist". Building without autoconf is not supported on Windows. \ No newline at end of file diff --git a/Makefile b/Makefile index 37ae76565..a149bad24 100644 --- a/Makefile +++ b/Makefile @@ -282,10 +282,10 @@ SHLIB_FLAVOUR = cygdll lib-shared: cyghts-$(LIBHTS_SOVERSION).dll else ifeq "$(findstring MSYS,$(PLATFORM))" "MSYS" SHLIB_FLAVOUR = dll -lib-shared: hts-$(LIBHTS_SOVERSION).dll +lib-shared: hts-$(LIBHTS_SOVERSION).lib else ifeq "$(findstring MINGW,$(PLATFORM))" "MINGW" SHLIB_FLAVOUR = dll -lib-shared: hts-$(LIBHTS_SOVERSION).dll +lib-shared: hts-$(LIBHTS_SOVERSION).lib else SHLIB_FLAVOUR = so lib-shared: libhts.so @@ -330,6 +330,40 @@ cyghts-$(LIBHTS_SOVERSION).dll libhts.dll.a: $(LIBHTS_OBJS) hts-$(LIBHTS_SOVERSION).dll hts.dll.a: $(LIBHTS_OBJS) $(CC) -shared -Wl,--out-implib=hts.dll.a -Wl,--enable-auto-import -Wl,--exclude-all-symbols $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive $(LIBS) -lpthread +hts-$(LIBHTS_SOVERSION).def: hts-$(LIBHTS_SOVERSION).dll + gendef hts-$(LIBHTS_SOVERSION).dll + +hts-$(LIBHTS_SOVERSION).lib: hts-$(LIBHTS_SOVERSION).def + llvm-dlltool -m i386:x86-64 -d hts-$(LIBHTS_SOVERSION).def -l hts-$(LIBHTS_SOVERSION).lib + +# Bundling libraries, binaries, dll dependencies, and licenses into a +# single directory. +# +# NOTE: only tested on the supported MSYS2/MINGW64 environment. +dist-windows: DESTDIR= +dist-windows: prefix=dist-windows +dist-windows: install + cp hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib dist-windows/lib + cp `ldd hts-$(LIBHTS_SOVERSION).dll| awk '/mingw64/ {print $$3}'` dist-windows/bin + mkdir -p dist-windows/share/licenses/htslib + cp -r /mingw64/share/licenses/mingw-w64-libraries \ + /mingw64/share/licenses/brotli \ + /mingw64/share/licenses/bzip2 \ + /mingw64/share/licenses/gcc-libs \ + /mingw64/share/licenses/libdeflate \ + /mingw64/share/licenses/libpsl \ + /mingw64/share/licenses/libtre \ + /mingw64/share/licenses/libwinpthread \ + /mingw64/share/licenses/openssl \ + /mingw64/share/licenses/xz \ + /mingw64/share/licenses/zlib \ + /mingw64/share/licenses/zstd \ + dist-windows/share/licenses/ + cp -r /usr/share/licenses/curl \ + dist-windows/share/licenses/ + cp LICENSE dist-windows/share/licenses/htslib/ + + # Target to allow htslib.mk to build all the object files before it # links the shared and static libraries. hts-object-files: $(LIBHTS_OBJS)