1 { stdenv, lib, buildPackages, fetchurl, fixDarwinDylibNames, testers, updateAutotoolsGnuConfigScriptsHook }:
3 { version, hash, patches ? [], patchFlags ? [], withStatic ? stdenv.hostPlatform.isStatic }:
6 # Cross-compiled icu4c requires a build-root of a native compile
7 nativeBuildRoot = buildPackages."icu${lib.versions.major version}".buildRootOnly;
11 release = lib.replaceStrings [ "." ] [ "-" ] version;
12 # To test rc versions of ICU replace the line above with the line below.
13 #release = lib.replaceStrings [ "." ] [ "-" ] (if lib.hasSuffix "rc" version then lib.replaceStrings [ "1" ] [ "" ] version else version);
17 url = "https://github.com/unicode-org/icu/releases/download/release-${release}/icu4c-${lib.replaceStrings [ "." ] [ "_" ] version}-src.tgz";
22 sourceRoot=''${sourceRoot}/source
23 echo Source root reset to ''${sourceRoot}
26 # https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
27 postPatch = if (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl") && lib.versionOlder version "62.1"
28 then "substituteInPlace i18n/digitlst.cpp --replace '<xlocale.h>' '<locale.h>'"
29 else null; # won't find locale_t on darwin
31 inherit patchFlags patches;
34 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure
36 # $(includedir) is different from $(prefix)/include due to multiple outputs
37 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in
38 '' + lib.optionalString stdenv.hostPlatform.isAarch32 ''
39 # From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch
40 sed -e 's/LDFLAGSICUDT=-nodefaultlibs -nostdlib/LDFLAGSICUDT=/' -i config/mh-linux
43 dontDisableStatic = withStatic;
45 configureFlags = [ "--disable-debug" ]
46 ++ lib.optional (stdenv.hostPlatform.isFreeBSD || stdenv.hostPlatform.isDarwin) "--enable-rpath"
47 ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "--with-cross-build=${nativeBuildRoot}"
48 ++ lib.optional withStatic "--enable-static";
50 enableParallelBuilding = true;
53 description = "Unicode and globalization support library";
54 homepage = "https://icu.unicode.org/";
55 maintainers = with maintainers; [ raskin ];
61 platforms = platforms.all;
65 realAttrs = baseAttrs // {
66 inherit pname version;
68 outputs = [ "out" "dev" ] ++ lib.optional withStatic "static";
71 nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ] ++
72 # FIXME: This fixes dylib references in the dylibs themselves, but
73 # not in the programs in $out/bin.
74 lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
77 # remove dependency on bootstrap-tools in early stdenv build
78 postInstall = lib.optionalString withStatic ''
80 mv -v lib/*.a $static/lib
81 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
82 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${lib.versions.majorMinor version}/pkgdata.inc
85 { from = "\${prefix}/include"; to = "${placeholder "dev"}/include"; } # --cppflags-searchpath
86 { from = "\${pkglibdir}/Makefile.inc"; to = "${placeholder "dev"}/lib/icu/Makefile.inc"; } # --incfile
87 { from = "\${pkglibdir}/pkgdata.inc"; to = "${placeholder "dev"}/lib/icu/pkgdata.inc"; } # --incpkgdatafile
90 rm $out/share/icu/${lib.versions.majorMinor version}/install-sh $out/share/icu/${lib.versions.majorMinor version}/mkinstalldirs # Avoid having a runtime dependency on bash
92 substituteInPlace "$dev/bin/icu-config" \
93 ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements}
96 postFixup = ''moveToOutput lib/icu "$dev" '';
99 buildRootOnlyAttrs = baseAttrs // {
100 pname = pname + "-build-root";
103 preConfigure = baseAttrs.preConfigure + ''
106 configureScript=../configure
112 echo "Doing build-root only, exiting now" >&2
117 mkWithAttrs = attrs: stdenv.mkDerivation (finalAttrs: attrs // {
118 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
119 passthru.buildRootOnly = mkWithAttrs buildRootOnlyAttrs;
122 mkWithAttrs realAttrs