# Maintainer: Andrew Sun <adsun701@gmail.com>

pkgname=nawk
pkgver=20180827
pkgrel=1
pkgdesc="The one, true implementation of AWK"
url="https://www.cs.princeton.edu/~bwk/btl.mirror/"
license=('MIT')
arch=('i686' 'x86_64')
options=('!makeflags')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/onetrueawk/awk/archive/${pkgver}.tar.gz"
        'manpage-naming.patch')
md5sums=('043b9b9e8d197929ca9f4f35943c0c67'
         'c708123a6dfeda611be6f63a45f50e4f')

prepare() {
  cd awk-${pkgver}
  # awk -> nawk
  patch -Np1 <"${srcdir}"/manpage-naming.patch

  # create license
  sed -n '/Copyright/,/THIS SOFTWARE\./p' README > LICENSE

  # fix build
  sed -i '/YACC = yacc -d -S/ s|^|#|' makefile
}

build() {
  cd awk-${pkgver}
  make "CPPFLAGS=-DHAS_ISBLANK ${CPPFLAGS}" \
    "LDFLAGS=${LDFLAGS}" \
    "CFLAGS=${CFLAGS}"
}

package() {
  cd awk-${pkgver}
  install -Dm755 a.exe "${pkgdir}/usr/bin/nawk.exe"
  install -Dm644 awk.1 "${pkgdir}/usr/share/man/man1/nawk.1"
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/nawk/LICENSE"
}
