# 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.12
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=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.gnu.org/software/grep/'
msys2_references=(
  "cpe: cpe:/a:gnu:grep"
)
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-pcre2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.xz"{,.sig})
sha256sums=('2649b27c0e90e632eadcd757be06c6e9a4f48d941de51e7c0f83ff76408a07b9'
            'SKIP')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE') # Jim Meyering <jim@meyering.net>

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  LDFLAGS+=" -lpthread" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  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
}
