Skip to content

Commit 70e4b18

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 #533).
1 parent ac22d4d commit 70e4b18

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-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 mingw-w64-x86_64-llvm\""
3131

3232
build_script:
3333
- set HOME=.

INSTALL

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,24 @@ 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 mingw-w64-x86_64-llvm
287+
288+
(Those last two install gendef and llvm-dlltool and are only needed
289+
for building libraries compatible with MSVC.)
290+
291+
A working binary distribution may then be made using "./configure &&
292+
make win-dist". Building without autoconf is not supported on Windows.

Makefile

Lines changed: 36 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).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).lib
289289
else
290290
SHLIB_FLAVOUR = so
291291
lib-shared: libhts.so
@@ -330,6 +330,40 @@ 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+
llvm-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.
341+
#
342+
# NOTE: only tested on the supported MSYS2/MINGW64 environment.
343+
dist-windows: DESTDIR=
344+
dist-windows: prefix=dist-windows
345+
dist-windows: install
346+
cp hts-$(LIBHTS_SOVERSION).def hts-$(LIBHTS_SOVERSION).lib dist-windows/lib
347+
cp `ldd hts-$(LIBHTS_SOVERSION).dll| awk '/mingw64/ {print $$3}'` dist-windows/bin
348+
mkdir -p dist-windows/share/licenses/htslib
349+
cp -r /mingw64/share/licenses/mingw-w64-libraries \
350+
/mingw64/share/licenses/brotli \
351+
/mingw64/share/licenses/bzip2 \
352+
/mingw64/share/licenses/gcc-libs \
353+
/mingw64/share/licenses/libdeflate \
354+
/mingw64/share/licenses/libpsl \
355+
/mingw64/share/licenses/libtre \
356+
/mingw64/share/licenses/libwinpthread \
357+
/mingw64/share/licenses/openssl \
358+
/mingw64/share/licenses/xz \
359+
/mingw64/share/licenses/zlib \
360+
/mingw64/share/licenses/zstd \
361+
dist-windows/share/licenses/
362+
cp -r /usr/share/licenses/curl \
363+
dist-windows/share/licenses/
364+
cp LICENSE dist-windows/share/licenses/htslib/
365+
366+
333367
# Target to allow htslib.mk to build all the object files before it
334368
# links the shared and static libraries.
335369
hts-object-files: $(LIBHTS_OBJS)

0 commit comments

Comments
 (0)