diff --git a/pkgs/development/libraries/zlib/default.nix b/pkgs/development/libraries/zlib/default.nix index c0aafbb9fbc1..66c782e212e0 100644 --- a/pkgs/development/libraries/zlib/default.nix +++ b/pkgs/development/libraries/zlib/default.nix @@ -43,12 +43,17 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-mpOyt9/ax3zrpaVYpYDnRmfdb+3kWFuR7vtg8Dty3yM="; }; - postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace configure \ - --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ - --replace 'AR="libtool"' 'AR="${stdenv.cc.targetPrefix}ar"' \ - --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' - ''; + postPatch = + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace configure \ + --replace '/usr/bin/libtool' '${stdenv.cc.targetPrefix}ar' \ + --replace 'AR="libtool"' 'AR="${stdenv.cc.targetPrefix}ar"' \ + --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' + '' + + lib.optionalString stdenv.hostPlatform.isCygwin '' + substituteInPlace win32/zlib.def \ + --replace-fail 'gzopen_w' "" + ''; strictDeps = true; outputs = [ @@ -59,7 +64,7 @@ stdenv.mkDerivation (finalAttrs: { setOutputFlags = false; outputDoc = "dev"; # single tiny man3 page - dontConfigure = stdenv.hostPlatform.isMinGW; + dontConfigure = (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin); preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' export CHOST=${stdenv.hostPlatform.config} @@ -112,7 +117,9 @@ stdenv.mkDerivation (finalAttrs: { lib.optionalAttrs (!stdenv.hostPlatform.isDarwin) { # As zlib takes part in the stdenv building, we don't want references # to the bootstrap-tools libgcc (as uses to happen on arm/mips) - NIX_CFLAGS_COMPILE = "-static-libgcc"; + NIX_CFLAGS_COMPILE = toString ( + [ "-static-libgcc" ] ++ lib.optional stdenv.hostPlatform.isCygwin "-DHAVE_UNISTD_H" + ); } // lib.optionalAttrs (stdenv.hostPlatform.linker == "lld") { # lld 16 enables --no-undefined-version by default @@ -126,7 +133,7 @@ stdenv.mkDerivation (finalAttrs: { dontStrip = stdenv.hostPlatform != stdenv.buildPlatform && static; configurePlatforms = [ ]; - installFlags = lib.optionals stdenv.hostPlatform.isMinGW [ + installFlags = lib.optionals (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) [ "BINARY_PATH=$(out)/bin" "INCLUDE_PATH=$(dev)/include" "LIBRARY_PATH=$(out)/lib" @@ -138,10 +145,14 @@ stdenv.mkDerivation (finalAttrs: { makeFlags = [ "PREFIX=${stdenv.cc.targetPrefix}" ] - ++ lib.optionals stdenv.hostPlatform.isMinGW [ + ++ lib.optionals (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) [ "-f" "win32/Makefile.gcc" ] + ++ lib.optionals stdenv.hostPlatform.isCygwin [ + "SHAREDLIB=cygz.dll" + "IMPLIB=libz.dll.a" + ] ++ 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`.