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

pkgname=tzcode
_ver=2018c
# use a pacman compatible version scheme
pkgver=${_ver/[a-z]/.${_ver//[0-9.]/}}
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')
groups=('base')
depends=('coreutils' 'gawk' 'sed')
source=(
        https://www.iana.org/time-zones/repository/releases/tzdata${_ver}.tar.gz{,.asc}
        https://www.iana.org/time-zones/repository/releases/${pkgname}${_ver}.tar.gz{,.asc}
        tzcode-makefile.patch
        tzcode-makefile-exe-extensions.patch
        tzcode-fix-unknown-type-locale_t.patch)
sha256sums=('2825c3e4b7ef520f24d393bcc02942f9762ffd3e7fc9b23850789ed8f22933f6'
            'SKIP'
            '31fa7fc0f94a6ff2d6bc878c0a35e8ab8b5aa0e8b01445a1d4a8f14777d0e665'
            'SKIP'
            '93d047fcf6151a67f676f16888c34f82b5dfabca6a51d90e123dc197ef649003'
            'faf73eb5f07c56b019b540005f4262f33927a4ff2acf3752a055e8530decd749'
            '10abdf8b8a4a50bc6e27b293acb214d5debbab47837768e053eadd590678448d')
validpgpkeys=('7E3792A9D8ACF7D633BC1588ED97E90E62AA7E34')

timezones=('africa' 'antarctica' 'asia' 'australasia'
           'europe' 'northamerica' 'southamerica'
           'pacificnew' 'etcetera' 'backward'
           'systemv' 'factory')

prepare() {
  cd ${srcdir}

  patch -p1 -i ${srcdir}/tzcode-makefile.patch
  patch -p1 -i ${srcdir}/tzcode-makefile-exe-extensions.patch
  patch -p1 -i ${srcdir}/tzcode-fix-unknown-type-locale_t.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
}
