lol
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 ''
58 sed -i -e "s|/bin/sh|${stdenv.shell}|" configure
59
60 # $(includedir) is different from $(prefix)/include due to multiple outputs
61 sed -i -e 's|^\(CPPFLAGS = .*\) -I\$(prefix)/include|\1 -I$(includedir)|' config/Makefile.inc.in
62 ''
63 + lib.optionalString stdenv.hostPlatform.isAarch32 ''
64 # From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch
65 sed -e 's/LDFLAGSICUDT=-nodefaultlibs -nostdlib/LDFLAGSICUDT=/' -i config/mh-linux
66 '';
67
68 dontDisableStatic = withStatic;
69
70 configureFlags =
71 [ "--disable-debug" ]
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 ] ++ lib.optional withStatic "static";
100 outputBin = "dev";
101
102 nativeBuildInputs =
103 [ updateAutotoolsGnuConfigScriptsHook ]
104 ++
105 # FIXME: This fixes dylib references in the dylibs themselves, but
106 # not in the programs in $out/bin.
107 lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames;
108
109 # remove dependency on bootstrap-tools in early stdenv build
110 postInstall =
111 lib.optionalString withStatic ''
112 mkdir -p $static/lib
113 mv -v lib/*.a $static/lib
114 ''
115 + lib.optionalString stdenv.hostPlatform.isDarwin ''
116 sed -i 's/INSTALL_CMD=.*install/INSTALL_CMD=install/' $out/lib/icu/${lib.versions.majorMinor version}/pkgdata.inc
117 ''
118 + (
119 let
120 replacements = [
121 {
122 from = "\${prefix}/include";
123 to = "${placeholder "dev"}/include";
124 } # --cppflags-searchpath
125 {
126 from = "\${pkglibdir}/Makefile.inc";
127 to = "${placeholder "dev"}/lib/icu/Makefile.inc";
128 } # --incfile
129 {
130 from = "\${pkglibdir}/pkgdata.inc";
131 to = "${placeholder "dev"}/lib/icu/pkgdata.inc";
132 } # --incpkgdatafile
133 ];
134 in
135 ''
136 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
137
138 substituteInPlace "$dev/bin/icu-config" \
139 ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements}
140 ''
141 );
142
143 postFixup = ''moveToOutput lib/icu "$dev" '';
144 };
145
146 buildRootOnlyAttrs = baseAttrs // {
147 pname = pname + "-build-root";
148 inherit version;
149
150 preConfigure =
151 baseAttrs.preConfigure
152 + ''
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