# Maintainer: Alexey Pavlov <alexpux@gmail.com>
#
# NOTE: Since grep 3.1 support for handling Windows line endings was removed by: 
# https://git.savannah.gnu.org/cgit/grep.git/commit/?h=v3.1&id=5ac3d87a69122d45a837840914c2f9e66b5bb8d4
# https://git.savannah.gnu.org/cgit/grep.git/commit/?h=v3.1&id=c4485ac49a977d666187db4c5c25045215976577
# Removing it lead for MSYS2 broken configure tests for MINGW packages that use autotools.
# See next issues before do grep update:
# https://github.com/msys2/MSYS2-packages/issues/1353
# https://github.com/msys2/MSYS2-packages/pull/2163
# https://github.com/msys2/MINGW-packages/issues/9771


pkgname=grep
pkgver=3.0
pkgrel=7
epoch=1
pkgdesc="A string search utility"
arch=('i686' 'x86_64')
license=('GPL3')
url="https://www.gnu.org/software/grep/"
msys2_references=(
  "cpe: cpe:/a:gnu:grep"
)
depends=('libiconv' 'libintl' 'libpcre' 'sh')
makedepends=('texinfo' 'gettext-devel' 'libiconv-devel' 'pcre-devel' 'autotools' 'gcc')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        grep-3.0-2.src.patch)
sha256sums=('e2c81db5056e3e8c5995f0bb5d0d0e1cad1f6f45c3b2fc77b6e81435aed48ab5'
            'SKIP'
            '0b2e7e54eb4d5b13257c1b4b43bcb234be02ded8fd04dfbbb73a92346e8b2db2')
validpgpkeys=('155D3FC500C834486D1EEA677FD9FCCB000BEEEE')  # Jim Meyering

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

  # 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}

  export gl_cv_have_weak=no

  export MSYSTEM=CYGWIN
  ./configure \
      --build=${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
}
