# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Paul Moore <p.f.moore@gmail.com>

_realname=grep
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.6
pkgrel=1
pkgdesc="Grep searches one or more input files for lines containing a match to a specified pattern (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.gnu.org/software/grep/'
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-pcre")
makedepends=("${MINGW_PACKAGE_PREFIX}-winpthreads")
options=('strip' '!libtool' 'staticlibs')
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "0001-tests-link-with-winpthread.patch")
sha256sums=('667e15e8afe189e93f9f21a7cd3a7b3f776202f417330b248c2ad4f997d9373e'
            'SKIP'
            'c773acf35ed5470e8b2d19b618364e0a50546e325f18c2cc75a36d63ce1d0380')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE') # Jim Meyering <jim@meyering.net>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-tests-link-with-winpthread.patch"
  autoreconf -fiv
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
