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

pkgname=("libtre" "libtre-devel")
pkgver=0.9.0
pkgrel=1
epoch=
pkgdesc="The free and portable approximate regex matching library (libraries)"
arch=("i686" "x86_64")
url="https://laurikari.net/tre/"
msys2_repository_url="https://github.com/laurikari/tre"
license=('BSD')
groups=('libraries')
depends=("gettext" "libiconv" "libintl")
makedepends=("gettext-devel" "libiconv-devel" "gcc" "git" 'autotools')
source=("${pkgname}"::"git+https://github.com/laurikari/tre#tag=v${pkgver}")
sha256sums=('81ac859d391cfd1a240a23ac1b7bda51cee7b75103cf03015cea9ea0b3492c3d')
msys2_references=(
  'archlinux: tre'
)

prepare() {
  cd "${srcdir}/${pkgname}"
  mv -f ChangeLog.old  ChangeLog
  autoreconf -ivf
}

build() {
  cd "${srcdir}/${pkgname}"
  ./configure --prefix=/usr
  make
  make DESTDIR="$srcdir/dest" install
  install -Dm644 ./LICENSE $srcdir/dest/usr/share/licenses/libtre/LICENSE
}

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

package_libtre() {
  depends=("gettext" "libiconv" "libintl")
  provides=("libtre-git=${pkgver}")
  conflicts=("libtre-git")
  replaces=("libtre-git")

  mkdir -p $pkgdir/usr/bin
  cp -rf $srcdir/dest/usr/bin $pkgdir/usr/

  mkdir -p $pkgdir/usr/share
  cp -rf $srcdir/dest/usr/share $pkgdir/usr/
}

package_libtre-devel() {
  pkgdesc="Libtre headers and libraries (development)"
  groups=('development')
  depends=("libtre=${pkgver}" "gettext-devel" "libiconv-devel")
  provides=("libtre-devel-git=${pkgver}")
  conflicts=("libtre-devel-git")
  replaces=("libtre-devel-git")

  mkdir -p $pkgdir/usr
  cp -rf $srcdir/dest/usr/include $pkgdir/usr/
  cp -rf $srcdir/dest/usr/lib $pkgdir/usr/
}
