diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index c0aafbb9fbc1a..db94bcd422b0b 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -43,6 +43,8 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-mpOyt9/ax3zrpaVYpYDnRmfdb+3kWFuR7vtg8Dty3yM="; }; + patches = lib.optional stdenv.hostPlatform.isMinGW ./mingw-shared.patch; + postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' substituteInPlace configure \ --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ @@ -59,8 +61,6 @@ stdenv.mkDerivation (finalAttrs: { setOutputFlags = false; outputDoc = "dev"; # single tiny man3 page - dontConfigure = stdenv.hostPlatform.isMinGW; - preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' export CHOST=${stdenv.hostPlatform.config} ''; @@ -105,7 +105,8 @@ stdenv.mkDerivation (finalAttrs: { # Non-typical naming confuses libtool which then refuses to use zlib's DLL # in some cases, e.g. when compiling libpng. + lib.optionalString (stdenv.hostPlatform.isMinGW && shared) '' - ln -s zlib1.dll $out/bin/libz.dll + mkdir -p $out/bin + mv $out/lib/*.dll* $out/bin ''; env = @@ -114,7 +115,7 @@ stdenv.mkDerivation (finalAttrs: { # to the bootstrap-tools libgcc (as uses to happen on arm/mips) NIX_CFLAGS_COMPILE = "-static-libgcc"; } - // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld") { + // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld" && !stdenv.hostPlatform.isWindows) { # lld 16 enables --no-undefined-version by default # This makes configure think it can't build dynamic libraries # this may be removed when a version is packaged with https://github.com/madler/zlib/issues/960 fixed @@ -138,10 +139,6 @@ stdenv.mkDerivation (finalAttrs: { makeFlags = [ "PREFIX=${stdenv.cc.targetPrefix}" ] - ++ lib.optionals stdenv.hostPlatform.isMinGW [ - "-f" - "win32/Makefile.gcc" - ] ++ lib.optionals shared [ # Note that as of writing (zlib 1.2.11), this flag only has an effect # for Windows as it is specific to `win32/Makefile.gcc`. diff --git a/pkgs/development/libraries/zlib/mingw-shared.patch b/pkgs/development/libraries/zlib/mingw-shared.patch new file mode 100644 index 0000000000000..9f08476a3a263 --- /dev/null +++ b/pkgs/development/libraries/zlib/mingw-shared.patch @@ -0,0 +1,13 @@ +diff --git a/configure b/configure +index c55098a..07f7c08 100755 +--- a/configure ++++ b/configure +@@ -243,6 +243,8 @@ if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then + echo "If this doesn't work for you, try win32/Makefile.gcc." | tee -a configure.log + LDSHARED=${LDSHARED-"$cc -shared"} + LDSHAREDLIBC="" ++ shared_ext='.dll' ++ SHAREDLIB='libz.dll' + EXE='.exe' ;; + QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 + # (alain.bonnefoy@icbt.com)