# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=tzdata
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2025b
pkgrel=2
pkgdesc="Sources for time zone and daylight saving time data (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.iana.org/time-zones"
license=('custom: public domain')
makedepends=('tzcode')
options=('!emptydirs')
source=(https://www.iana.org/time-zones/repository/releases/${_realname}${pkgver}.tar.gz{,.asc}
        https://www.iana.org/time-zones/repository/releases/tzcode${pkgver}.tar.gz{,.asc})
sha512sums=('7d83741f3cae81fac8131994b43c55b6da7328df18b706e5ee40e9b3212bc506e6f8fc90988b18da424ed59eff69bce593f2783b7b5f18eb483a17aeb94258d6'
            'SKIP'
            '19826b12968c10fc4db7e4b07ba782bfb8590eeebaec6f719d74b92a2e642ab817bd72bceff0015ce52a838edfdb00753b3cd87dd84b35abf2606e5bee445f76'
            'SKIP')
validpgpkeys=('7E3792A9D8ACF7D633BC1588ED97E90E62AA7E34') # Paul Eggert <eggert@cs.ucla.edu>

_timezones=('africa' 'antarctica' 'asia' 'australasia'
           'europe' 'northamerica' 'southamerica'
           'etcetera' 'backward' 'factory')

build() {
  cd "${srcdir}"

  touch version  # avoid it re-sourcing from git in case anything is patched above
  make tzdata.zi leapseconds
}

package() {
  cd "${srcdir}"

  # install tzdata stuff
  zic -b fat -d "${pkgdir}${MINGW_PREFIX}"/share/zoneinfo ${_timezones[@]}
  zic -b fat -d "${pkgdir}${MINGW_PREFIX}"/share/zoneinfo/posix ${_timezones[@]}
  zic -b fat -d "${pkgdir}${MINGW_PREFIX}"/share/zoneinfo/right -L leapseconds ${_timezones[@]}
  # This creates the posixrules file. We use New York because POSIX requires the daylight savings time rules to be in accordance with US rules.
  zic -b fat -d "${pkgdir}${MINGW_PREFIX}"/share/zoneinfo -p America/New_York
  install -m444 -t "${pkgdir}${MINGW_PREFIX}"/share/zoneinfo iso3166.tab leap-seconds.list leapseconds tzdata.zi zonenow.tab zone1970.tab zone.tab SECURITY # zone.tab is depricated and will go soon

  # install license
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
