# Maintainer:  andreas_baumann (https://aur.archlinux.org/account/andreas_baumann)
# Contributor: dreieck (https://aur.archlinux.org/account/dreieck)
# Contributor: Ujhhgtg (https://aur.archlinux.org/account/Ujhhgtg)
 
## Based on `PKGBUILD` for package `icu71`, version 71.1-1, by Ujhhgtg (https://aur.archlinux.org/account/Ujhhgtg).

_pkgname=icu
_pkgmainver=75
_pkgminorver=1
pkgname="${_pkgname}${_pkgmainver}"
pkgver="${_pkgmainver}.${_pkgminorver}"
pkgrel=9
pkgdesc="International Components for Unicode library (legacy version ${_pkgmainver})."
arch=(
  'aarch64'
)
url="http://www.icu-project.org/"
license=('Unicode-3.0')
depends=(
  'gcc-libs'
  'glibc'
)
makedepends=(
  'clang'
  'make'
  'patch'
  'python'
)
provides=(
  # "${_pkgname}=${pkgver}" # Do not provide `icu` itself, since the executable tools are not provided.
  "libicudata.so=${_pkgmainver}"
  "libicui18n.so=${_pkgmainver}"
  "libicuio.so=${_pkgmainver}"
  "libicutest.so=${_pkgmainver}"
  "libicutu.so=${_pkgmainver}"
  "libicuuc.so=${_pkgmainver}"
)
source=(
  "https://github.com/unicode-org/icu/releases/download/release-${pkgver//./-}/icu4c-${pkgver//./_}-src.tgz"
  #"https://github.com/unicode-org/icu/releases/download/release-${pkgver//./-}/icu4c-${pkgver//./_}-src.tgz.asc"
  "ICU-22132.patch"
  "icudata-stdlibs.patch"
  "${pkgname}-LICENSE::https://github.com/unicode-org/icu/raw/main/LICENSE"
)
md5sums=('a83c1499e508f73ddbc60002f84ea42a'
         '7e501a2e7d14ce94b843e6853d96e4c2'
         '4e5202245fce364490334bd66b5edabc'
         'cf57d9459a2c5f88ecd83c75207cc5ff')
sha256sums=('cb968df3e4d2e87e8b11c49a5d01c787bd13b9545280fc6642f826527618caef'
            'f534b472dd7a6961591466eef542e2c3ad698d3008c9b6af813c66cbc0b4dd8e'
            '13444e40ec8da75a3c4140448b25bdf51887a2691c9afdb0c63134ddd33d915b'
            '451167c55c0fa447cc2d5632714f5e3c567fe4f1e1badefab2c1333852198aca')
#validpgpkeys=(
#  '4058F67406EAA6AB'
#)

prepare() {
  cd icu/source
  # Required fix for thunderbird 115 to show Calendar and sidebar properly
  # https://bugzilla.mozilla.org/show_bug.cgi?id=1843007
  # https://unicode-org.atlassian.net/browse/ICU-22132
  patch -Np1 < "../../ICU-22132.patch"
  patch -p2 -i ${srcdir}/icudata-stdlibs.patch
  sed -r -i 's/(for ac_prog in )clang(\+\+)? /\1/g' configure
}


build()
{
  cd "${_pkgname}/source"

  ## `--enable-tools` is needed to build `genrb` binary, which is needed somewhere during the compilation process.
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --mandir=/usr/share/man \
    --sbindir=/usr/bin \
    --disable-icu-config \
    --disable-debug \
    --enable-release \
    --enable-shared \
    --disable-static \
    --disable-auto-cleanup \
    --enable-draft \
    --enable-renaming \
    --disable-tracing \
    --enable-plugins \
    --enable-dyload \
    --enable-rpath \
    --disable-weak-threads \
    --enable-extras \
    --enable-icuio \
    --enable-layoutex \
    --enable-tools \
    --disable-fuzzer \
    --enable-tests \
    --disable-samples \
    --with-data-packaging=library

  make
}

# disabled because Python 3.13 unittest has no attribute makeSuite anymore
check()
{
  cd "${_pkgname}/source"

#  make -k check
}

package()
{
  cd "${_pkgname}/source"

  make DESTDIR="${pkgdir}" install

  ## Remove files that would make this package conflict with the generic `icu` package, and other "garbage" files:
  rm -rf "${pkgdir}"/usr/{bin,include,share,lib/{pkgconfig,*.so,icu/{current,Makefile.inc,pkgdata.inc}}}

  ## Install license
  install -Dvm644 "${srcdir}/${pkgname}-LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
