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

pkgname=grep
pkgver=3.6
pkgrel=1
pkgdesc="A string search utility"
arch=('i686' 'x86_64')
license=('GPL3')
url="https://www.gnu.org/software/grep/"
groups=('base-devel')
depends=('libiconv' 'libintl' 'libpcre' 'sh')
makedepends=('texinfo' 'gettext-devel' 'libiconv-devel' 'pcre-devel')
install=${pkgname}.install
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        grep-2.23-msys2.patch
        grep-3.0-2.src.patch)
sha256sums=('667e15e8afe189e93f9f21a7cd3a7b3f776202f417330b248c2ad4f997d9373e'
            'SKIP'
            '2a4b61a5240e839b4a3b83eb9c4a7c73d384085366405ddef371dfcc30381aa3'
            '0b2e7e54eb4d5b13257c1b4b43bcb234be02ded8fd04dfbbb73a92346e8b2db2')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE')  # Jim Meyering

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

  patch -p1 -i ${srcdir}/grep-2.23-msys2.patch
  # Once this will be commit upstream we need revert it
  #patch -p2 -R -i ${srcdir}/grep-3.0-2.src.patch

  #make test cases work
  sed -i "s|case \$perms in drwx--\[-S\]---\*|case \$perms in drwx\*|" tests/init.sh

  autoreconf -fi
}

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

  echo ${CHOST}
  ./configure \
      --build=${CHOST} \
      --host=${CHOST} \
      --target=${CHOST} \
      --prefix=/usr \
      --without-libiconv-prefix \
      --without-libintl-prefix
  make
}

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

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