1 { version, sha256, patches ? [], patchFlags ? [] }:
2 { stdenv, lib, fetchurl, fixDarwinDylibNames
3 # Cross-compiled icu4c requires a build-root of a native compile
4 , buildRootOnly ? false, nativeBuildRoot
12 url = "https://github.com/unicode-org/icu/releases/download/release-${lib.replaceChars [ "." ] [ "-" ] version}/icu4c-${lib.replaceChars [ "." ] [ "_" ] version}-src.tgz";
17 sourceRoot=''${sourceRoot}/source
18 echo Source root reset to ''${sourceRoot}
21 # https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
22 postPatch = if (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl") && lib.versionOlder version "62.1"
23 then "substituteInPlace i18n/digitlst.cpp --replace '<xlocale.h>' '<locale.h>'"
24 else null; # won't find locale_t on darwin
26 inherit patchFlags patches;
29 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure
31 # $(includedir) is different from $(prefix)/include due to multiple outputs
32 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in
33 '' + lib.optionalString stdenv.isAarch32 ''
34 # From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch
35 sed -e 's/LDFLAGSICUDT=-nodefaultlibs -nostdlib/LDFLAGSICUDT=/' -i config/mh-linux
38 configureFlags = [ "--disable-debug" ]
39 ++ lib.optional (stdenv.isFreeBSD || stdenv.isDarwin) "--enable-rpath"
40 ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "--with-cross-build=${nativeBuildRoot}";
42 enableParallelBuilding = true;
45 description = "Unicode and globalization support library";
46 homepage = "https://icu.unicode.org/";
47 maintainers = with maintainers; [ raskin ];
48 platforms = platforms.all;
52 realAttrs = baseAttrs // {
53 name = pname + "-" + version;
55 outputs = [ "out" "dev" ];
58 # FIXME: This fixes dylib references in the dylibs themselves, but
59 # not in the programs in $out/bin.
60 nativeBuildInputs = lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
62 # remove dependency on bootstrap-tools in early stdenv build
63 postInstall = lib.optionalString stdenv.isDarwin ''
64 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${version}/pkgdata.inc
67 { from = "\${prefix}/include"; to = "${placeholder "dev"}/include"; } # --cppflags-searchpath
68 { from = "\${pkglibdir}/Makefile.inc"; to = "${placeholder "dev"}/lib/icu/Makefile.inc"; } # --incfile
69 { from = "\${pkglibdir}/pkgdata.inc"; to = "${placeholder "dev"}/lib/icu/pkgdata.inc"; } # --incpkgdatafile
72 substituteInPlace "$dev/bin/icu-config" \
73 ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements}
76 postFixup = ''moveToOutput lib/icu "$dev" '';
79 buildRootOnlyAttrs = baseAttrs // {
80 name = pname + "-build-root-" + version;
82 preConfigure = baseAttrs.preConfigure + ''
85 configureScript=../configure
91 echo "Doing build-root only, exiting now" >&2
96 attrs = if buildRootOnly
97 then buildRootOnlyAttrs
100 stdenv.mkDerivation attrs