# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=tzcode
pkgver=2025b
pkgrel=1
pkgdesc="Sources for time zone and daylight saving time data"
arch=('i686' 'x86_64')
url="https://www.iana.org/time-zones"
msys2_references=(
  "anitya: 16905"
  'archlinux: tzdata'
)
license=('GPL')
options=('!emptydirs')
depends=('coreutils' 'gawk' 'sed')
makedepends=('make' 'gcc')
source=(
        https://www.iana.org/time-zones/repository/releases/tzdata${pkgver}.tar.gz{,.asc}
        https://www.iana.org/time-zones/repository/releases/${pkgname}${pkgver}.tar.gz{,.asc}
        tzcode-makefile.patch
        tzcode-makefile-exe-extensions.patch)
sha256sums=('11810413345fc7805017e27ea9fa4885fd74cd61b2911711ad038f5d28d71474'
            'SKIP'
            '05f8fedb3525ee70d49c87d3fae78a8a0dbae4fe87aa565c65cda9948ae135ec'
            'SKIP'
            '19fbb941fa73ec1bc4f2caa24ac848e9fbf42ac187621bfef40f4a50d5198cdc'
            'faf73eb5f07c56b019b540005f4262f33927a4ff2acf3752a055e8530decd749')
validpgpkeys=('7E3792A9D8ACF7D633BC1588ED97E90E62AA7E34') # Paul Eggert <eggert@cs.ucla.edu>

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

prepare() {
  cd ${srcdir}
  patch -p1 -i ${srcdir}/tzcode-makefile.patch
  patch -p1 -i ${srcdir}/tzcode-makefile-exe-extensions.patch
}

build() {
 cd ${srcdir}
 make CFLAGS="${CFLAGS} -std=gnu99 -DHAVE_GETTEXT=0"
}

package() {
  cd ${srcdir}

  make -j1 DESTDIR=${pkgdir} install
  mv ${pkgdir}/usr/share/zoneinfo-leaps ${pkgdir}/usr/share/zoneinfo/right
  mv ${pkgdir}/usr/share/zoneinfo-posix ${pkgdir}/usr/share/zoneinfo/posix

  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo ${_timezones[@]}
  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo/posix ${_timezones[@]}
  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo/right -L leapseconds ${_timezones[@]}

  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo -p America/New_York
  install -m644 -t ${pkgdir}/usr/share/zoneinfo iso3166.tab leap-seconds.list zone1970.tab zone.tab SECURITY

  install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}
