1{ stdenv, fetchurl, static ? false }:
2
3let version = "1.2.8"; in
4
5stdenv.mkDerivation (rec {
6 name = "zlib-${version}";
7
8 src = fetchurl {
9 urls =
10 [ "http://www.zlib.net/${name}.tar.gz" # old versions vanish from here
11 "mirror://sourceforge/libpng/zlib/${version}/${name}.tar.gz"
12 ];
13 sha256 = "039agw5rqvqny92cpkrfn243x2gd4xn13hs3xi6isk55d2vqqr9n";
14 };
15
16 postPatch = stdenv.lib.optionalString stdenv.isDarwin ''
17 substituteInPlace configure \
18 --replace '/usr/bin/libtool' 'ar' \
19 --replace 'AR="libtool"' 'AR="ar"' \
20 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
21 '';
22
23 configureFlags = if static then "" else "--shared";
24
25 preConfigure = ''
26 if test -n "$crossConfig"; then
27 export CC=$crossConfig-gcc
28 configureFlags=${if static then "" else "--shared"}
29 fi
30 '';
31
32 # As zlib takes part in the stdenv building, we don't want references
33 # to the bootstrap-tools libgcc (as uses to happen on arm/mips)
34 NIX_CFLAGS_COMPILE = stdenv.lib.optionalString (!stdenv.isDarwin) "-static-libgcc";
35
36 crossAttrs = {
37 dontStrip = static;
38 } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
39 configurePhase=''
40 installFlags="BINARY_PATH=$out/bin INCLUDE_PATH=$out/include LIBRARY_PATH=$out/lib"
41 '';
42 makeFlags = [
43 "-f" "win32/Makefile.gcc"
44 "PREFIX=${stdenv.cross.config}-"
45 ] ++ (if static then [] else [ "SHARED_MODE=1" ]);
46 } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "libSystem") {
47 makeFlags = [ "RANLIB=${stdenv.cross.config}-ranlib" ];
48 };
49
50 # CYGXXX: This is not needed anymore and non-functional, but left not to trigger rebuilds
51 cygwinConfigureEnableShared = if (!stdenv.isCygwin) then true else null;
52
53 passthru.version = version;
54
55 meta = with stdenv.lib; {
56 description = "Lossless data-compression library";
57 license = licenses.zlib;
58 platforms = platforms.all;
59 };
60} // (if stdenv.isDarwin then {
61 postInstall = ''
62 # jww (2015-01-06): Sometimes this library install as a .so, even on
63 # Darwin; others time it installs as a .dylib. I haven't yet figured out
64 # what causes this difference.
65 for file in $out/lib/*.so* $out/lib/*.dylib* ; do
66 install_name_tool -id "$file" $file
67 done
68 '';
69} else {}))