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

_realname=libgnurx

pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.1
pkgrel=3
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc="libgnurx (mingw-w64)"
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
license=('LGPL')
url="https://mingw.sourceforge.io/"
source=("https://downloads.sourceforge.net/mingw/Other/UserContributed/regex/mingw-regex-${pkgver}/mingw-libgnurx-${pkgver}-src.tar.gz"
        "mingw-w64-libgnurx-honor-destdir.patch"
        "mingw32-libgnurx-Makefile.am"
        "mingw32-libgnurx-configure.ac")
sha256sums=('7147b7f806ec3d007843b38e19f42a5b7c65894a57ffc297a76b0dcd5f675d76'
            '7db74e71a2612e1720f68acea7c9bc24873be1d533c1eed4db58c4fd923e1ec1'
            '4215ca6e8c7a88484fcf90437958359e916be5a59c36147ac34cd20892a91512'
            'fdc7b7ccb0ca8ad87822e64c144b74fe8f289edf2a8406700ba85cf26725e260')

prepare() {
  cd "$srcdir/mingw-libgnurx-${pkgver}"
  patch -Np0 -i $srcdir/mingw-w64-libgnurx-honor-destdir.patch

  cp $srcdir/mingw32-libgnurx-configure.ac configure.ac
  cp $srcdir/mingw32-libgnurx-Makefile.am Makefile.am
  touch NEWS
  touch AUTHORS
  libtoolize --copy
  aclocal
  autoconf
  automake --add-missing
}

build()
{
  mkdir -p $srcdir/build-${MSYSTEM} && cd $srcdir/build-${MSYSTEM}
  ../mingw-libgnurx-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --host=${MINGW_CHOST}
  make
}

package()
{
  cd "$srcdir/build-${MSYSTEM}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/include
  make install DESTDIR="$pkgdir"
  cp -f "${pkgdir}"${MINGW_PREFIX}/lib/libgnurx.dll.a "${pkgdir}"${MINGW_PREFIX}/lib/libregex.dll.a
  cp -f "${pkgdir}"${MINGW_PREFIX}/lib/libgnurx.a "${pkgdir}"${MINGW_PREFIX}/lib/libregex.a
}

