Skip to content

Commit 2cddfb3

Browse files
committed
Build DLL and plugins on Cygwin
The Cygwin convention seems to be to just create cyghts-SOVER.dll without additional symlinks, so we do that. Linking also creates an import library, libhts.dll.a, which plays a similar development role to plain libhts.so; we could make this the true target of the link rule (cf libhts.so), but currently its name will collide with the same name used for a plain Windows import library. NOTE: To use the plugins successfully, there must be only one copy of libhts.a/cyghts*.dll in the complete executable. To ensure this, either make executables use the DLL too (so for htsfile/tabix/etc, apply s/libhts.a/-L. -lhts/ to the recipe; FIXME) or perhaps we can link the plugins themselves with some --allow-undefined option rather than with the import library, as we do on other platforms. Also ignore plain Windows *.dll for good measure.
1 parent 1eec11b commit 2cddfb3

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ config.status
1414
configure
1515

1616
hfile_*.bundle
17+
hfile_*.cygdll
18+
hfile_*.dll
1719
hfile_*.so
1820

21+
cyg*.dll
1922
lib*.a
23+
lib*.dll
2024
lib*.dylib
2125
lib*.so
2226
lib*.so.*

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ print-version:
128128
@echo $(PACKAGE_VERSION)
129129

130130

131-
.SUFFIXES: .bundle .c .o .pico .so
131+
.SUFFIXES: .bundle .c .cygdll .dll .o .pico .so
132132

133133
.c.o:
134134
$(CC) $(CFLAGS) -I. $(CPPFLAGS) -c -o $@ $<
@@ -215,6 +215,9 @@ endif
215215
ifeq "$(PLATFORM)" "Darwin"
216216
SHLIB_FLAVOUR = dylib
217217
lib-shared: libhts.dylib
218+
else ifeq "$(findstring CYGWIN,$(PLATFORM))" "CYGWIN"
219+
SHLIB_FLAVOUR = cygdll
220+
lib-shared: cyghts-$(LIBHTS_SOVERSION).dll
218221
else
219222
SHLIB_FLAVOUR = so
220223
lib-shared: libhts.so
@@ -248,13 +251,19 @@ libhts.dylib: $(LIBHTS_OBJS)
248251
$(CC) -dynamiclib -install_name $(libdir)/libhts.$(LIBHTS_SOVERSION).dylib -current_version $(NUMERIC_VERSION) -compatibility_version $(LIBHTS_SOVERSION) $(LDFLAGS) -o $@ $(LIBHTS_OBJS) -lz $(LIBS)
249252
ln -sf $@ libhts.$(LIBHTS_SOVERSION).dylib
250253

254+
cyghts-$(LIBHTS_SOVERSION).dll: $(LIBHTS_OBJS)
255+
$(CC) -shared -Wl,--out-implib=libhts.dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import -pthread $(LDFLAGS) -o $@ -Wl,--whole-archive $(LIBHTS_OBJS) -Wl,--no-whole-archive -lz -lm $(LIBS)
256+
251257

252258
.pico.so:
253259
$(CC) -shared -Wl,-E -pthread $(LDFLAGS) -o $@ $< $(LIBS)
254260

255261
.o.bundle:
256262
$(CC) -bundle -Wl,-undefined,dynamic_lookup $(LDFLAGS) -o $@ $< $(LIBS)
257263

264+
.o.cygdll:
265+
$(CC) -shared $(LDFLAGS) -o $@ $< libhts.dll.a $(LIBS)
266+
258267

259268
bgzf.o bgzf.pico: bgzf.c config.h $(htslib_hts_h) $(htslib_bgzf_h) $(htslib_hfile_h) $(htslib_khash_h)
260269
errmod.o errmod.pico: errmod.c config.h $(htslib_hts_h) $(htslib_ksort_h)
@@ -373,6 +382,10 @@ install-so: libhts.so installdirs
373382
ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so
374383
ln -sf libhts.so.$(PACKAGE_VERSION) $(DESTDIR)$(libdir)/libhts.so.$(LIBHTS_SOVERSION)
375384

385+
install-cygdll: cyghts-$(LIBHTS_SOVERSION).dll installdirs
386+
$(INSTALL_PROGRAM) cyghts-$(LIBHTS_SOVERSION).dll $(DESTDIR)$(bindir)/cyghts-$(LIBHTS_SOVERSION).dll
387+
$(INSTALL_PROGRAM) libhts.dll.a $(DESTDIR)$(libdir)/libhts.dll.a
388+
376389
install-dylib: libhts.dylib installdirs
377390
$(INSTALL_PROGRAM) libhts.dylib $(DESTDIR)$(libdir)/libhts.$(PACKAGE_VERSION).dylib
378391
ln -sf libhts.$(PACKAGE_VERSION).dylib $(DESTDIR)$(libdir)/libhts.dylib
@@ -406,6 +419,9 @@ distclean maintainer-clean: clean
406419
clean-so:
407420
-rm -f libhts.so libhts.so.*
408421

422+
clean-cygdll:
423+
-rm -f cyghts-*.dll libhts.dll.a
424+
409425
clean-dylib:
410426
-rm -f libhts.dylib libhts.*.dylib
411427

@@ -431,4 +447,5 @@ force:
431447
.PHONY: install install-pkgconfig installdirs lib-shared lib-static
432448
.PHONY: maintainer-clean mostlyclean plugins print-version tags test testclean
433449
.PHONY: clean-so install-so
450+
.PHONY: clean-cygdll install-cygdll
434451
.PHONY: clean-dylib install-dylib

config.mk.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ PLUGIN_OBJS += $(plugin_OBJS)
105105

106106
plugin.o plugin.pico: CPPFLAGS += -DPLUGINPATH=\"$(pluginpath)\"
107107

108+
# Windows DLL plugins depend on the import library, built as a byproduct.
109+
$(plugin_OBJS:.o=.cygdll): cyghts-$(LIBHTS_SOVERSION).dll
110+
108111
else
109112

110113
LIBHTS_OBJS += $(plugin_OBJS)

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ AC_SUBST([pluginpath], $with_plugin_path)
8585
AC_MSG_CHECKING([shared library type])
8686
test -n "$host_alias" || host_alias=unknown-`uname -s`
8787
case $host_alias in
88+
*-cygwin* | *-CYGWIN*)
89+
host_result="Cygwin DLL"
90+
PLATFORM=CYGWIN
91+
PLUGIN_EXT=.cygdll
92+
;;
8893
*-darwin* | *-Darwin*)
8994
host_result="Darwin dylib"
9095
PLATFORM=Darwin

0 commit comments

Comments
 (0)