5 updateAutotoolsGnuConfigScriptsHook,
6 enableStatic ? stdenv.hostPlatform.isStatic,
7 enableShared ? !stdenv.hostPlatform.isStatic,
8 enableDarwinABICompat ? false,
11 # assert !stdenv.hostPlatform.isLinux || stdenv.hostPlatform != stdenv.buildPlatform; # TODO: improve on cross
13 stdenv.mkDerivation rec {
18 url = "mirror://gnu/libiconv/${pname}-${version}.tar.gz";
19 sha256 = "sha256-j3QhO1YjjIWlClMp934GGYdx5w3Zpzl3n0wC9l2XExM=";
22 enableParallelBuilding = true;
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 ];
28 # https://github.com/NixOS/nixpkgs/pull/192630#discussion_r978985593
29 hardeningDisable = lib.optional (stdenv.hostPlatform.libc == "bionic") "fortify";
32 ../../../build-support/setup-hooks/role.bash
39 (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isMinGW) || stdenv.cc.nativeLibc
42 sed '/^_GL_WARN_ON_USE (gets/d' -i srclib/stdio.in.h
44 + lib.optionalString (!enableShared) ''
45 sed -i -e '/preload/d' Makefile.in
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" ""
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.
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 ''
72 NIX_CFLAGS_COMPILE+=" -Wl,-reexport-lcharset -L. " make -C lib -j$NIX_BUILD_CORES SHELL=$SHELL
76 (lib.enableFeature enableStatic "static")
77 (lib.enableFeature enableShared "shared")
78 ] ++ lib.optional stdenv.hostPlatform.isFreeBSD "--with-pic";
80 passthru = { inherit setupHooks; };
83 description = "Iconv(3) implementation";
86 Some programs, like mailers and web browsers, must be able to convert
87 between a given text encoding and the user's encoding. Other programs
88 internally store strings in Unicode, to facilitate internal processing,
89 and need to convert between internal string representation (Unicode)
90 and external string representation (a traditional encoding) when they
91 are doing I/O. GNU libiconv is a conversion library for both kinds of
95 homepage = "https://www.gnu.org/software/libiconv/";
96 license = lib.licenses.lgpl2Plus;
99 mainProgram = "iconv";
101 # This library is not needed on GNU platforms.
102 hydraPlatforms = with lib.platforms; cygwin ++ darwin ++ freebsd;