It seems that the best way is to go behind libtool's back. Here are some extracts from my Makefile.am.
Conditionally include the dlfcn.c source. You'll also have to update include path, and possibly place some extern "C" guards in the header file.
if HOST_MINGW32
bali_phy_SOURCES += dlfcn-win32/dlfcn.c
endif
You'll need to adjust the LDFLAGS of the main application so that an import library is generated as a by-product of compilation:
if HOST_LINUX
bali_phy_LDFLAGS = -rdynamic
else
if HOST_MINGW32
bali_phy_LDFLAGS = -Wl,--export-all-symbols,--out-implib=libbali-phy.dll.a
else
bali_phy_LDFLAGS =
endif
endif
To compile the plugin, pass flags directly to the linker in order to avoid explaining the import library to libtool. You'll also have to add the directory containing your main application (here its $(top_builddir)) to the linker search path.
if HOST_MINGW32
EXTRADEPENDENCIES = bali-phy.exe
EXTRALDFLAGS = -L$(top_builddir) -Wl,libbali-phy.dll.a
else
EXTRADEPENDENCIES =
EXTRALDFLAGS =
endif
mod_la_SOURCES = computation/builtins/mod.C
mod_la_LDFLAGS = -module -shared -avoid-version -export-dynamic -no-undefined -enable-runtime-pseudo-reloc $(EXTRALDFLAGS)
mod_la_DEPENDENCIES = $(EXTRADEPENDENCIES)
The _DEPENDENCIES line makes the module depend on the main application, so that the main application and its import library are built first.