Skip to content

Commit 8aa1499

Browse files
committed
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 samtools#533).
1 parent e2d1f25 commit 8aa1499

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ install:
2727
- set MSYSTEM=MINGW64
2828
- set PATH=C:/msys64/usr/bin;C:/msys64/mingw64/bin;%PATH%
2929
- set MINGWPREFIX=x86_64-w64-mingw32
30-
- "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\""
30+
- "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\""
3131

3232
build_script:
3333
- set HOME=.

INSTALL

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,20 @@ OpenSUSE
269269
--------
270270

271271
sudo zypper install autoconf automake make gcc perl zlib-devel libbz2-devel xz-devel libcurl-devel libopenssl-devel
272+
273+
Windows MSYS2/MINGW64
274+
---------------------
275+
276+
Follow MSYS2 installation instructions at
277+
https://www.msys2.org/wiki/MSYS2-installation/
278+
279+
Then relaunch to MSYS2 shell using the "MSYS2 MinGW x64" executable.
280+
Once in that environment (check $MSYSTEM equals "MINGW64") install the
281+
compilers using pacman -S and the following package list:
282+
283+
base-devel mingw-w64-x86_64-toolchain
284+
mingw-w64-x86_64-libdeflate mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2
285+
mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-autotools
286+
mingw-w64-x86_64-tools-git
287+
288+
(The last is only needed for building libraries compatible with MSVC.)

Makefile

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ SHLIB_FLAVOUR = cygdll
282282
lib-shared: cyghts-$(LIBHTS_SOVERSION).dll
283283
else ifeq "$(findstring MSYS,$(PLATFORM))" "MSYS"
284284
SHLIB_FLAVOUR = dll
285-
lib-shared: hts-$(LIBHTS_SOVERSION).dll
285+
lib-shared: hts-$(LIBHTS_SOVERSION).dll hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib
286286
else ifeq "$(findstring MINGW,$(PLATFORM))" "MINGW"
287287
SHLIB_FLAVOUR = dll
288-
lib-shared: hts-$(LIBHTS_SOVERSION).dll
288+
lib-shared: hts-$(LIBHTS_SOVERSION).dll hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib
289289
else
290290
SHLIB_FLAVOUR = so
291291
lib-shared: libhts.so
@@ -330,6 +330,41 @@ cyghts-$(LIBHTS_SOVERSION).dll libhts.dll.a: $(LIBHTS_OBJS)
330330
hts-$(LIBHTS_SOVERSION).dll hts.dll.a: $(LIBHTS_OBJS)
331331
$(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
332332

333+
hts-$(LIBHTS_SOVERSION).def: hts-$(LIBHTS_SOVERSION).dll
334+
gendef hts-$(LIBHTS_SOVERSION).dll
335+
336+
hts-$(LIBHTS_SOVERSION).lib: hts-$(LIBHTS_SOVERSION).def
337+
dlltool -m i386:x86-64 -d hts-$(LIBHTS_SOVERSION).def -l hts-$(LIBHTS_SOVERSION).lib
338+
339+
# Bundling libraries, binaries, dll dependencies, and licenses into a
340+
# single directory. NB: This is not needed for end-users, but a test bed
341+
# for maintainers building binary distributions.
342+
#
343+
# NOTE: only tested on the supported MSYS2/MINGW64 environment.
344+
dist-windows: DESTDIR=
345+
dist-windows: prefix=dist-windows
346+
dist-windows: install
347+
cp hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib dist-windows/lib
348+
cp `ldd hts-$(LIBHTS_SOVERSION).dll| awk '/mingw64/ {print $$3}'` dist-windows/bin
349+
mkdir -p dist-windows/share/licenses/htslib
350+
-cp -r /mingw64/share/licenses/mingw-w64-libraries \
351+
/mingw64/share/licenses/brotli \
352+
/mingw64/share/licenses/bzip2 \
353+
/mingw64/share/licenses/gcc-libs \
354+
/mingw64/share/licenses/libdeflate \
355+
/mingw64/share/licenses/libpsl \
356+
/mingw64/share/licenses/libtre \
357+
/mingw64/share/licenses/libwinpthread \
358+
/mingw64/share/licenses/openssl \
359+
/mingw64/share/licenses/xz \
360+
/mingw64/share/licenses/zlib \
361+
/mingw64/share/licenses/zstd \
362+
dist-windows/share/licenses/
363+
-cp -r /usr/share/licenses/curl \
364+
dist-windows/share/licenses/
365+
cp LICENSE dist-windows/share/licenses/htslib/
366+
367+
333368
# Target to allow htslib.mk to build all the object files before it
334369
# links the shared and static libraries.
335370
hts-object-files: $(LIBHTS_OBJS)

0 commit comments

Comments
 (0)