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

pkgname=tzcode
pkgver=2021a
pkgrel=1
pkgdesc="Sources for time zone and daylight saving time data"
arch=('i686' 'x86_64')
url="https://www.iana.org/time-zones"
license=('GPL')
options=('!emptydirs')
depends=('coreutils' 'gawk' 'sed')
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=('39e7d2ba08c68cbaefc8de3227aab0dec2521be8042cf56855f7dc3a9fb14e08'
            'SKIP'
            'eb46bfa124b5b6bd13d61a609bfde8351bd192894708d33aa06e5c1e255802d0'
            'SKIP'
            'f5ba93ebce547b14c44e55f94986046af6ed1c8befad296e4846412d053c4470'
            'faf73eb5f07c56b019b540005f4262f33927a4ff2acf3752a055e8530decd749')
validpgpkeys=('7E3792A9D8ACF7D633BC1588ED97E90E62AA7E34')

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"
}

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 -m444 -t ${pkgdir}/usr/share/zoneinfo iso3166.tab zone.tab
}
