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

pkgname=tzcode
pkgver=2025c
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=('4aa79e4effee53fc4029ffe5f6ebe97937282ebcdf386d5d2da91ce84142f957'
            'SKIP'
            '697ebe6625444aef5080f58e49d03424bbb52e08bf483d3ddb5acf10cbd15740'
            '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 -DHAVE_MEMPCPY=1 -DHAVE_ISSETUGID=1"
}

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
}
