[Zlib-devel] [Patch] support for building DLL for cygwin, mingw
Charles Wilson
cygwin at cwilson.fastmail.fm
Sat Jul 31 22:44:58 EDT 2010
I'm the maintainer of the cygwin zlib package and the cygwin
'mingw-zlib' package (a cross-compiled "mingw" zlib packaged for use on
cygwin). As part of that effort, I've long maintained the attached
patches out of tree, but I finally felt I should send them upstream.
These patches allow to build static and shared (DLL) versions of zlib
for both cygwin and mingw using the "configure and make" paradigm rather
than the win32/Makefile.gcc.
The result has been tested using:
linux native build (e.g. verified that it didn't break!)
linux->mingw cross
cygwin native build
cygwin->mingw cross
mingw native (e.g. "MSYS" hosted)
The DLLs created this way are named:
cygwin:
cygz.dll For historical reasons on cygwin, the zlib DLL doesn't
have a version number. After the next ABI change, then
it will.
mingw:
libz-1.dll Note that it is NOT named zlib1.dll. This is because
the "official" zlib1.dll is, apparently, built using
MSVC6.0, and should never have extra dependencies like
libgcc_s_dw2-1.dll. Depending on how your mingw gcc
is configured, or which LDFLAGS you use, you could in
fact end up with such "extra" dependencies. To avoid
any confusion with the "real" zlib1.dll, the configure/
make build uses a different name. (FWIW, this is the
name used by the mingw.org version of zlib).
The key distinction between most other platforms and cygwin/mingw in
these patches (when building shared) is that the former will define
SHAREDLIBV and SHAREDLIBM, and SHAREDTARGET will be defined as $SHAREDLIBV.
However, on cygwin/mingw, SHAREDLIBV and SHAREDLIBM are empty, but
instead IMPORTLIB is defined, and SHAREDTARGET is set to $SHAREDLIB.
All the rules are changed to depend on $SHAREDTARGET.
The "create symbolic links for $SHAREDLIB and $SHAREDLIBM" step is moved
to a variable set by configure, "SHAREDLIBPOST". Most targets define it as
'(rm -f $(SHAREDLIB) $(SHAREDLIBM); ln -s $@ $(SHAREDLIB) ; ln -s $@
$(SHAREDLIBM) )'
However, cygwin/mingw simply define it as "/bin/true".
The install and uninstall rules are modified to be sensitive to whether
$SHAREDLIBV is empty. If so (and +shared), then the "DLL installation
rules" are employed. Otherwise, the original rules appropriate for ELF
.so's are used. (There's a pre-existing bug in the uninstall rule
related to ELF .so's; I didn't fix that).
Finally, two new variables are added to compile and link rules:
EXTRA_CFLAGS and EXTRA_LDFLAGS. These are used so that the user can pass
additional values without clobbering the ones computed by configure.
So, for cygwin (native):
./configure --sharedlibdir='${exec_prefix}/bin'
make
make install DESTDIR=/foo
...and package from /foo...
For mingw (on MSYS; e.g. "native")
./configure --prefix=`cd /mingw && pwd -W` \
--sharedlibdir='${exec_prefix}/bin'
make EXTRA_CFLAGS="-mms-bitfields -D__USE_MINGW_ANSI_STDIO" \
EXTRA_LDFLAGS="-shared-libgcc"
make install prefix=/foo/mingw [*]
...and package from /foo...
[*] DESTDIR is fundamentally broken (this is not a zlib specific
problem) on mingw; when prefix is X:/bar, you can't prepend DESTDIR=/foo
because that gives /fooX:/bar, which is just so wrong...
For cygwin->mingw cross:
./configure --build=i686-pc-cygwin --host=i686-pc-mingw32 \
--prefix=/mingw --sharedlibdir='${exec_prefix}/bin'
make EXTRA_CFLAGS="-mms-bitfields -D__USE_MINGW_ANSI_STDIO" \
EXTRA_LDFLAGS="-shared-libgcc"
make install DESTDIR=/foo/`i686-pc-mingw32-gcc -print-sysroot`
...and package from /foo...
The reason EXTRA_* flags are used for mingw, instead of hardcoding them
in configure, is because these options change the library's ABI, and
this is the way the mingw and cygwin projects will be building them.
However, it is likely that people building private versions on those
platforms will want to make different choices...
OTOH, for cygwin, -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 ARE
hardcoded in configure, because the supported versions of cygwin have a
64bit off_t type, even though it does expose an off64_t type as well.
--
Chuck
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zlib-1.2.5-2.src.patch
Type: text/x-patch
Size: 8653 bytes
Desc: not available
URL: <http://madler.net/pipermail/zlib-devel_madler.net/attachments/20100731/66cf4b7e/attachment.bin>
More information about the Zlib-devel
mailing list