nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 19.03 90 lines 3.0 kB view raw
1{ stdenv 2, fetchurl 3, static ? true 4, shared ? true 5}: 6 7stdenv.mkDerivation (rec { 8 name = "zlib-${version}"; 9 version = "1.2.11"; 10 11 src = fetchurl { 12 urls = 13 [ "https://www.zlib.net/fossils/${name}.tar.gz" # stable archive path 14 "mirror://sourceforge/libpng/zlib/${version}/${name}.tar.gz" 15 ]; 16 sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"; 17 }; 18 19 patches = stdenv.lib.optional stdenv.hostPlatform.isCygwin ./disable-cygwin-widechar.patch; 20 21 postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isDarwin '' 22 substituteInPlace configure \ 23 --replace '/usr/bin/libtool' 'ar' \ 24 --replace 'AR="libtool"' 'AR="ar"' \ 25 --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"' 26 ''; 27 28 outputs = [ "out" "dev" ] 29 ++ stdenv.lib.optional (shared && static) "static"; 30 setOutputFlags = false; 31 outputDoc = "dev"; # single tiny man3 page 32 33 configureFlags = stdenv.lib.optional shared "--shared" 34 ++ stdenv.lib.optional (static && !shared) "--static"; 35 36 postInstall = stdenv.lib.optionalString (shared && static) '' 37 moveToOutput lib/libz.a "$static" 38 '' 39 # jww (2015-01-06): Sometimes this library install as a .so, even on 40 # Darwin; others time it installs as a .dylib. I haven't yet figured out 41 # what causes this difference. 42 + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin '' 43 for file in $out/lib/*.so* $out/lib/*.dylib* ; do 44 ${stdenv.cc.bintools.targetPrefix}install_name_tool -id "$file" $file 45 done 46 '' 47 # Non-typical naming confuses libtool which then refuses to use zlib's DLL 48 # in some cases, e.g. when compiling libpng. 49 + stdenv.lib.optionalString (stdenv.hostPlatform.libc == "msvcrt") '' 50 ln -s zlib1.dll $out/bin/libz.dll 51 ''; 52 53 # As zlib takes part in the stdenv building, we don't want references 54 # to the bootstrap-tools libgcc (as uses to happen on arm/mips) 55 NIX_CFLAGS_COMPILE = stdenv.lib.optionalString (!stdenv.hostPlatform.isDarwin) "-static-libgcc"; 56 57 dontStrip = stdenv.hostPlatform != stdenv.buildPlatform && static; 58 configurePlatforms = []; 59 60 installFlags = stdenv.lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ 61 "BINARY_PATH=$(out)/bin" 62 "INCLUDE_PATH=$(dev)/include" 63 "LIBRARY_PATH=$(out)/lib" 64 ]; 65 66 makeFlags = [ 67 "PREFIX=${stdenv.cc.targetPrefix}" 68 ] ++ stdenv.lib.optionals (stdenv.hostPlatform.libc == "msvcrt") [ 69 "-f" "win32/Makefile.gcc" 70 ] ++ stdenv.lib.optionals shared [ 71 "SHARED_MODE=1" 72 ]; 73 74 passthru = { 75 inherit version; 76 }; 77 78 meta = with stdenv.lib; { 79 homepage = https://zlib.net; 80 description = "Lossless data-compression library"; 81 license = licenses.zlib; 82 platforms = platforms.all; 83 }; 84} // stdenv.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform) { 85 preConfigure = '' 86 export CHOST=${stdenv.hostPlatform.config} 87 ''; 88} // stdenv.lib.optionalAttrs (stdenv.hostPlatform.libc == "msvcrt") { 89 configurePhase = ":"; 90})