Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 fetchurl, 3 stdenv, 4 lib, 5 updateAutotoolsGnuConfigScriptsHook, 6 enableStatic ? stdenv.hostPlatform.isStatic, 7 enableShared ? !stdenv.hostPlatform.isStatic, 8 enableDarwinABICompat ? false, 9}: 10 11# assert !stdenv.hostPlatform.isLinux || stdenv.hostPlatform != stdenv.buildPlatform; # TODO: improve on cross 12 13stdenv.mkDerivation rec { 14 pname = "libiconv"; 15 version = "1.17"; 16 17 src = fetchurl { 18 url = "mirror://gnu/libiconv/${pname}-${version}.tar.gz"; 19 sha256 = "sha256-j3QhO1YjjIWlClMp934GGYdx5w3Zpzl3n0wC9l2XExM="; 20 }; 21 22 enableParallelBuilding = true; 23 24 # necessary to build on FreeBSD native pending inclusion of 25 # https://git.savannah.gnu.org/cgit/config.git/commit/?id=e4786449e1c26716e3f9ea182caf472e4dbc96e0 26 nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ]; 27 28 # https://github.com/NixOS/nixpkgs/pull/192630#discussion_r978985593 29 hardeningDisable = lib.optional (stdenv.hostPlatform.libc == "bionic") "fortify"; 30 31 setupHooks = [ 32 ../../../build-support/setup-hooks/role.bash 33 ./setup-hook.sh 34 ]; 35 36 postPatch = 37 lib.optionalString 38 ( 39 (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isMinGW) || stdenv.cc.nativeLibc 40 ) 41 '' 42 sed '/^_GL_WARN_ON_USE (gets/d' -i srclib/stdio.in.h 43 '' 44 + lib.optionalString (!enableShared) '' 45 sed -i -e '/preload/d' Makefile.in 46 '' 47 # The system libiconv is based on libiconv 1.11 with some ABI differences. The following changes 48 # build a compatible libiconv on Darwin, allowing it to be sustituted in place of the system one 49 # using `install_name_tool`. This removes the need to for a separate, Darwin-specific libiconv 50 # derivation and allows Darwin to benefit from upstream updates and fixes. 51 + lib.optionalString enableDarwinABICompat '' 52 for iconv_h_in in iconv.h.in iconv.h.build.in; do 53 substituteInPlace "include/$iconv_h_in" \ 54 --replace-fail "#define iconv libiconv" "" \ 55 --replace-fail "#define iconv_close libiconv_close" "" \ 56 --replace-fail "#define iconv_open libiconv_open" "" \ 57 --replace-fail "#define iconv_open_into libiconv_open_into" "" \ 58 --replace-fail "#define iconvctl libiconvctl" "" \ 59 --replace-fail "#define iconvlist libiconvlist" "" 60 done 61 ''; 62 63 # This is hacky, but `libiconv.dylib` needs to reexport `libcharset.dylib` to match the behavior 64 # of the system libiconv on Darwin. Trying to do this by modifying the `Makefile` results in an 65 # error linking `iconv` because `libcharset.dylib` is not at its final path yet. Avoid the error 66 # by building without the reexport then clean and rebuild `libiconv.dylib` with the reexport. 67 # 68 # For an explanation why `libcharset.dylib` is reexported, see: 69 # https://github.com/apple-oss-distributions/libiconv/blob/a167071feb7a83a01b27ec8d238590c14eb6faff/xcodeconfig/libiconv.xcconfig 70 postBuild = lib.optionalString enableDarwinABICompat '' 71 make clean -C lib 72 NIX_CFLAGS_COMPILE+=" -Wl,-reexport-lcharset -L. " make -C lib -j$NIX_BUILD_CORES SHELL=$SHELL 73 ''; 74 75 configureFlags = [ 76 (lib.enableFeature enableStatic "static") 77 (lib.enableFeature enableShared "shared") 78 ] 79 ++ lib.optional stdenv.hostPlatform.isFreeBSD "--with-pic"; 80 81 passthru = { inherit setupHooks; }; 82 83 meta = { 84 description = "Iconv(3) implementation"; 85 86 longDescription = '' 87 Some programs, like mailers and web browsers, must be able to convert 88 between a given text encoding and the user's encoding. Other programs 89 internally store strings in Unicode, to facilitate internal processing, 90 and need to convert between internal string representation (Unicode) 91 and external string representation (a traditional encoding) when they 92 are doing I/O. GNU libiconv is a conversion library for both kinds of 93 applications. 94 ''; 95 96 homepage = "https://www.gnu.org/software/libiconv/"; 97 license = lib.licenses.lgpl2Plus; 98 99 maintainers = [ ]; 100 mainProgram = "iconv"; 101 102 # This library is not needed on GNU platforms. 103 hydraPlatforms = with lib.platforms; cygwin ++ darwin ++ freebsd; 104 }; 105}