1{
2 stdenv,
3 lib,
4 buildPackages,
5 fetchurl,
6 fixDarwinDylibNames,
7 testers,
8 updateAutotoolsGnuConfigScriptsHook,
9}:
10
11{
12 version,
13 hash,
14 patches ? [ ],
15 patchFlags ? [ ],
16 withStatic ? stdenv.hostPlatform.isStatic,
17}:
18
19let
20 # Cross-compiled icu4c requires a build-root of a native compile
21 nativeBuildRoot = buildPackages."icu${lib.versions.major version}".buildRootOnly;
22
23 pname = "icu4c";
24
25 release = lib.replaceStrings [ "." ] [ "-" ] version;
26 # To test rc versions of ICU replace the line above with the line below.
27 #release = lib.replaceStrings [ "." ] [ "-" ] (
28 # if lib.hasSuffix "rc" version then lib.replaceStrings [ "1" ] [ "" ] version else version
29 #);
30
31 baseAttrs = {
32 src = fetchurl {
33 url = "https://github.com/unicode-org/icu/releases/download/release-${release}/icu4c-${
34 lib.replaceStrings [ "." ] [ "_" ] version
35 }-src.tgz";
36 inherit hash;
37 };
38
39 postUnpack = ''
40 sourceRoot=''${sourceRoot}/source
41 echo Source root reset to ''${sourceRoot}
42 '';
43
44 # https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
45 postPatch =
46 if
47 (stdenv.hostPlatform.libc == "glibc" || stdenv.hostPlatform.libc == "musl")
48 && lib.versionOlder version "62.1"
49 then
50 "substituteInPlace i18n/digitlst.cpp --replace '<xlocale.h>' '<locale.h>'"
51 else
52 null; # won't find locale_t on darwin
53
54 inherit patchFlags patches;
55
56 preConfigure = ''
57 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure
58
59 # $(includedir) is different from $(prefix)/include due to multiple outputs
60 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in
61 ''
62 + lib.optionalString stdenv.hostPlatform.isAarch32 ''
63 # From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch
64 sed -e 's/LDFLAGSICUDT=-nodefaultlibs -nostdlib/LDFLAGSICUDT=/' -i config/mh-linux
65 '';
66
67 dontDisableStatic = withStatic;
68
69 configureFlags = [
70 "--disable-debug"
71 ]
72 ++ lib.optional (stdenv.hostPlatform.isFreeBSD || stdenv.hostPlatform.isDarwin) "--enable-rpath"
73 ++ lib.optional (
74 stdenv.buildPlatform != stdenv.hostPlatform
75 ) "--with-cross-build=${nativeBuildRoot}"
76 ++ lib.optional withStatic "--enable-static";
77
78 enableParallelBuilding = true;
79
80 meta = with lib; {
81 description = "Unicode and globalization support library";
82 homepage = "https://icu.unicode.org/";
83 maintainers = with maintainers; [ raskin ];
84 pkgConfigModules = [
85 "icu-i18n"
86 "icu-io"
87 "icu-uc"
88 ];
89 platforms = platforms.all;
90 };
91 };
92
93 realAttrs = baseAttrs // {
94 inherit pname version;
95
96 outputs = [
97 "out"
98 "dev"
99 ]
100 ++ lib.optional withStatic "static";
101 outputBin = "dev";
102
103 nativeBuildInputs = [
104 updateAutotoolsGnuConfigScriptsHook
105 ]
106 ++
107 # FIXME: This fixes dylib references in the dylibs themselves, but
108 # not in the programs in $out/bin.
109 lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
110
111 # remove dependency on bootstrap-tools in early stdenv build
112 postInstall =
113 lib.optionalString withStatic ''
114 mkdir -p $static/lib
115 mv -v lib/*.a $static/lib
116 ''
117 + lib.optionalString stdenv.hostPlatform.isDarwin ''
118 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${lib.versions.majorMinor version}/pkgdata.inc
119 ''
120 + (
121 let
122 replacements = [
123 {
124 from = "\${prefix}/include";
125 to = "${placeholder "dev"}/include";
126 } # --cppflags-searchpath
127 {
128 from = "\${pkglibdir}/Makefile.inc";
129 to = "${placeholder "dev"}/lib/icu/Makefile.inc";
130 } # --incfile
131 {
132 from = "\${pkglibdir}/pkgdata.inc";
133 to = "${placeholder "dev"}/lib/icu/pkgdata.inc";
134 } # --incpkgdatafile
135 ];
136 in
137 ''
138 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
139
140 substituteInPlace "$dev/bin/icu-config" \
141 ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements}
142 ''
143 );
144
145 postFixup = ''moveToOutput lib/icu "$dev" '';
146 };
147
148 buildRootOnlyAttrs = baseAttrs // {
149 pname = pname + "-build-root";
150 inherit version;
151
152 preConfigure = baseAttrs.preConfigure + ''
153 mkdir build
154 cd build
155 configureScript=../configure
156 '';
157
158 postBuild = ''
159 cd ..
160 mv build $out
161 echo "Doing build-root only, exiting now" >&2
162 exit 0
163 '';
164 };
165
166 mkWithAttrs =
167 attrs:
168 stdenv.mkDerivation (
169 finalAttrs:
170 attrs
171 // {
172 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
173 passthru.buildRootOnly = mkWithAttrs buildRootOnlyAttrs;
174 }
175 );
176in
177mkWithAttrs realAttrs