# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>
# Contributor: Mario Emmenlauer <memmenlauer@biodataanalysis.de>

_realname=libtre
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.0
pkgrel=2
pkgdesc="The approximate regex matching library and agrep command line tool (mingw-w64)"
url="https://github.com/laurikari/tre"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "git")
source=("${_realname}"::"git+https://github.com/laurikari/tre.git#tag=v${pkgver}"
        001-autotools.patch
        002-pointer-cast.patch)
sha256sums=('81ac859d391cfd1a240a23ac1b7bda51cee7b75103cf03015cea9ea0b3492c3d'
            '0fca8835867ccd669aa572d3fe25db8e45f33d93c17ee9c00e50cfab23e78dd1'
            '72c87b956eade17ed5444c3c6eae7be09b93d145573f20017ec590d9c2516c52')

prepare() {
  cd "${_realname}"
  patch -p1 -i "${srcdir}/001-autotools.patch"
  patch -p1 -i "${srcdir}/002-pointer-cast.patch"
  mv ChangeLog{.old,}
  autoreconf -fiv
}

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

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --without-libintl-prefix

  make
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}"/${_realname}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
