2024-07-27 06:49:29 +00:00
{ stdenv , lib , buildPackages , fetchurl , fixDarwinDylibNames , testers , updateAutotoolsGnuConfigScriptsHook }:
2024-02-29 20:09:43 +00:00
2024-05-15 15:35:15 +00:00
{ version , hash , patches ? [ ] , patchFlags ? [ ] , withStatic ? stdenv . hostPlatform . isStatic }:
2020-04-24 23:36:52 +00:00
let
2024-02-29 20:09:43 +00:00
# Cross-compiled icu4c requires a build-root of a native compile
nativeBuildRoot = buildPackages . " i c u ${ lib . versions . major version } " . buildRootOnly ;
2020-04-24 23:36:52 +00:00
pname = " i c u 4 c " ;
2024-10-23 06:41:50 +00:00
#release = lib.replaceStrings [ "." ] [ "-" ] version;
# To test rc versions of ICU replace the line above with the line below.
release = lib . replaceStrings [ " . " ] [ " - " ] ( if lib . hasSuffix " r c " version then lib . replaceStrings [ " 1 " ] [ " " ] version else version ) ;
2020-04-24 23:36:52 +00:00
baseAttrs = {
src = fetchurl {
2024-10-23 06:41:50 +00:00
url = " h t t p s : / / g i t h u b . c o m / u n i c o d e - o r g / i c u / r e l e a s e s / d o w n l o a d / r e l e a s e - ${ release } / i c u 4 c - ${ lib . replaceStrings [ " . " ] [ " _ " ] version } - s r c . t g z " ;
2024-02-29 20:09:43 +00:00
inherit hash ;
2020-04-24 23:36:52 +00:00
} ;
postUnpack = ''
sourceRoot = '' ${ sourceRoot } / s o u r c e
echo Source root reset to '' ${ sourceRoot }
'' ;
# https://sourceware.org/glibc/wiki/Release/2.26#Removal_of_.27xlocale.h.27
postPatch = if ( stdenv . hostPlatform . libc == " g l i b c " || stdenv . hostPlatform . libc == " m u s l " ) && lib . versionOlder version " 6 2 . 1 "
then " s u b s t i t u t e I n P l a c e i 1 8 n / d i g i t l s t . c p p - - r e p l a c e ' < x l o c a l e . h > ' ' < l o c a l e . h > ' "
else null ; # won't find locale_t on darwin
inherit patchFlags patches ;
preConfigure = ''
sed - i - e " s | / b i n / s h | ${ stdenv . shell } | " configure
# $(includedir) is different from $(prefix)/include due to multiple outputs
sed - i - e ' s | ^ \ ( CPPFLAGS = . * \ ) - I \ $ ( prefix ) /include | \ 1 - I $ ( includedir ) | ' config/Makefile.inc.in
2024-09-26 11:04:55 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . h o s t P l a t f o r m . i s A a r c h 3 2 ''
2020-04-24 23:36:52 +00:00
# From https://archlinuxarm.org/packages/armv7h/icu/files/icudata-stdlibs.patch
sed - e ' s/LDFLAGSICUDT = - nodefaultlibs -nostdlib/LDFLAGSICUDT = / ' - i config/mh-linux
'' ;
2024-05-15 15:35:15 +00:00
dontDisableStatic = withStatic ;
2020-04-24 23:36:52 +00:00
configureFlags = [ " - - d i s a b l e - d e b u g " ]
2024-09-26 11:04:55 +00:00
++ lib . optional ( stdenv . hostPlatform . isFreeBSD || stdenv . hostPlatform . isDarwin ) " - - e n a b l e - r p a t h "
2024-05-15 15:35:15 +00:00
++ lib . optional ( stdenv . buildPlatform != stdenv . hostPlatform ) " - - w i t h - c r o s s - b u i l d = ${ nativeBuildRoot } "
++ lib . optional withStatic " - - e n a b l e - s t a t i c " ;
2020-04-24 23:36:52 +00:00
enableParallelBuilding = true ;
2021-02-05 17:12:51 +00:00
meta = with lib ; {
2020-04-24 23:36:52 +00:00
description = " U n i c o d e a n d g l o b a l i z a t i o n s u p p o r t l i b r a r y " ;
2021-12-06 16:07:01 +00:00
homepage = " h t t p s : / / i c u . u n i c o d e . o r g / " ;
2020-04-24 23:36:52 +00:00
maintainers = with maintainers ; [ raskin ] ;
2023-02-16 17:41:37 +00:00
pkgConfigModules = [
" i c u - i 1 8 n "
" i c u - i o "
" i c u - u c "
] ;
2020-04-24 23:36:52 +00:00
platforms = platforms . all ;
} ;
} ;
realAttrs = baseAttrs // {
2024-10-11 05:15:48 +00:00
inherit pname version ;
2020-04-24 23:36:52 +00:00
2024-05-15 15:35:15 +00:00
outputs = [ " o u t " " d e v " ] ++ lib . optional withStatic " s t a t i c " ;
2020-04-24 23:36:52 +00:00
outputBin = " d e v " ;
2024-07-27 06:49:29 +00:00
nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ] ++
# FIXME: This fixes dylib references in the dylibs themselves, but
# not in the programs in $out/bin.
lib . optional stdenv . hostPlatform . isDarwin fixDarwinDylibNames ;
2020-04-24 23:36:52 +00:00
# remove dependency on bootstrap-tools in early stdenv build
2024-05-15 15:35:15 +00:00
postInstall = lib . optionalString withStatic ''
mkdir - p $ static/lib
mv - v lib /* . a $ s t a t i c / l i b
2024-09-26 11:04:55 +00:00
'' + l i b . o p t i o n a l S t r i n g s t d e n v . h o s t P l a t f o r m . i s D a r w i n ''
2024-10-23 06:41:50 +00:00
sed - i ' s/INSTALL_CMD = . * install/INSTALL_CMD = install / ' $ out/lib/icu / $ { lib . versions . majorMinor version } /pkgdata.inc
2020-04-24 23:36:52 +00:00
'' + ( l e t
replacements = [
{ from = " \$ { p r e f i x } / i n c l u d e " ; to = " ${ placeholder " d e v " } / i n c l u d e " ; } # --cppflags-searchpath
{ from = " \$ { p k g l i b d i r } / M a k e f i l e . i n c " ; to = " ${ placeholder " d e v " } / l i b / i c u / M a k e f i l e . i n c " ; } # --incfile
{ from = " \$ { p k g l i b d i r } / p k g d a t a . i n c " ; to = " ${ placeholder " d e v " } / l i b / i c u / p k g d a t a . i n c " ; } # --incpkgdatafile
] ;
in ''
2024-10-23 06:41:50 +00:00
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
2024-05-15 15:35:15 +00:00
2020-04-24 23:36:52 +00:00
substituteInPlace " $ d e v / b i n / i c u - c o n f i g " \
$ { lib . concatMapStringsSep " " ( r : " - - r e p l a c e ' ${ r . from } ' ' ${ r . to } ' " ) replacements }
'' ) ;
postFixup = '' m o v e T o O u t p u t l i b / i c u " $d e v " '' ;
} ;
buildRootOnlyAttrs = baseAttrs // {
2024-10-11 05:15:48 +00:00
pname = pname + " - b u i l d - r o o t " ;
inherit version ;
2020-04-24 23:36:52 +00:00
preConfigure = baseAttrs . preConfigure + ''
mkdir build
cd build
configureScript = ../configure
'' ;
postBuild = ''
cd . .
mv build $ out
echo " D o i n g b u i l d - r o o t o n l y , e x i t i n g n o w " > & 2
exit 0
'' ;
} ;
2024-02-29 20:09:43 +00:00
mkWithAttrs = attrs : stdenv . mkDerivation ( finalAttrs : attrs // {
passthru . tests . pkg-config = testers . testMetaPkgConfig finalAttrs . finalPackage ;
passthru . buildRootOnly = mkWithAttrs buildRootOnlyAttrs ;
} ) ;
2020-04-24 23:36:52 +00:00
in
2024-02-29 20:09:43 +00:00
mkWithAttrs realAttrs