icu.nix (3219B)
1 # https://gist.github.com/rprospero/dd8e16bad9f842409c85e63ade31c355 2 { lib, stdenv, fetchurl, version, sha256, patches ? [], patchFlags ? [] }: 3 4 let 5 buildRootOnly = false; 6 pname = "icu4c"; 7 8 baseAttrs = { 9 src = fetchurl { 10 url = "https://github.com/unicode-org/icu/releases/download/release-${lib.replaceChars [ "." ] [ "-" ] version}/icu4c-${lib.replaceChars [ "." ] [ "_" ] version}-src.tgz"; 11 inherit sha256; 12 }; 13 14 postUnpack = '' 15 sourceRoot=''${sourceRoot}/source 16 echo Source root reset to ''${sourceRoot} 17 ''; 18 19 # https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27 20 postPatch = if (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl") && lib.versionOlder version "62.1" 21 then "substituteInPlace i18n/digitlst.cpp --replace '<xlocale.h>' '<locale.h>'" 22 else null; # won't find locale_t on darwin 23 24 inherit patchFlags patches; 25 26 preConfigure = '' 27 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure 28 29 # $(includedir) is different from $(prefix)/include due to multiple outputs 30 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in 31 '' + lib.optionalString stdenv.isAarch32 '' 32 # From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch 33 sed -e 's/LDFLAGSICUDT=-nodefaultlibs -nostdlib/LDFLAGSICUDT=/' -i config/mh-linux 34 ''; 35 36 configureFlags = [ "--disable-debug" ] 37 ++ lib.optional (stdenv.isFreeBSD || stdenv.isDarwin) "--enable-rpath"; 38 39 enableParallelBuilding = true; 40 41 meta = with lib; { 42 description = "Unicode and globalization support library"; 43 homepage = "http://site.icu-project.org/"; 44 maintainers = [ maintainers.sikmir ]; 45 platforms = platforms.all; 46 skip.ci = true; 47 }; 48 }; 49 50 realAttrs = baseAttrs // { 51 name = pname + "-" + version; 52 53 outputs = [ "out" "dev" ]; 54 outputBin = "dev"; 55 56 # remove dependency on bootstrap-tools in early stdenv build 57 postInstall = lib.optionalString stdenv.isDarwin '' 58 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${version}/pkgdata.inc 59 '' + (let 60 replacements = [ 61 { from = "\${prefix}/include"; to = "${placeholder "dev"}/include"; } # --cppflags-searchpath 62 { from = "\${pkglibdir}/Makefile.inc"; to = "${placeholder "dev"}/lib/icu/Makefile.inc"; } # --incfile 63 { from = "\${pkglibdir}/pkgdata.inc"; to = "${placeholder "dev"}/lib/icu/pkgdata.inc"; } # --incpkgdatafile 64 ]; 65 in '' 66 substituteInPlace "$dev/bin/icu-config" \ 67 ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements} 68 ''); 69 70 postFixup = ''moveToOutput lib/icu "$dev" ''; 71 }; 72 73 buildRootOnlyAttrs = baseAttrs // { 74 name = pname + "-build-root-" + version; 75 76 preConfigure = baseAttrs.preConfigure + '' 77 mkdir build 78 cd build 79 configureScript=../configure 80 ''; 81 82 postBuild = '' 83 cd .. 84 mv build $out 85 echo "Doing build-root only, exiting now" >&2 86 exit 0 87 ''; 88 }; 89 90 attrs = if buildRootOnly 91 then buildRootOnlyAttrs 92 else realAttrs; 93 in 94 stdenv.mkDerivation attrs