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

pkgname=gawk
pkgver=5.3.2
pkgrel=1
pkgdesc="GNU version of awk"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/gawk/"
msys2_references=(
  "cpe: cpe:/a:gnu:gawk"
)
license=('GPL')
depends=('sh' 'mpfr' 'libintl' 'libreadline')
makedepends=('gettext-devel' 'mpfr-devel' 'libreadline-devel' 'autotools' 'gcc')
provides=('awk')
source=(https://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz{,.sig})
sha256sums=('8639a1a88fb411a1be02663739d03e902a6d313b5c6fe024d0bfeb3341a19a11'
            'SKIP')
validpgpkeys=('D1967C63788713177D861ED7DF597815937EC0D2')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  autoreconf -fiv
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  export gl_cv_have_weak=no
  ./configure --build=${CHOST} \
              --prefix=/usr \
              --libexecdir=/usr/lib \
              --without-libiconv-prefix \
              --without-libintl-prefix

  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # remove unnessary import libraries of modules
  rm -fv "${pkgdir}"/usr/lib/gawk/*.dll.a

  # roll-back the fake CHOST in gawkbug
  sed -E -i '/^(MACHTYPE|OS)=/ s/cygwin/msys/' "${pkgdir}"/usr/bin/gawkbug
}
