pkgname=pcre2
pkgver=10.45
pkgdesc='A library that implements Perl 5-style regular expressions. 2nd version'
arch=(x86_64)
url='https://github.com/PCRE2Project/pcre2'
license=(
  BSD-2-Clause
  'BSD-3-Clause WITH PCRE2-exception'
)
depends=(
  bzip2
  glibc
  readline
  zlib
)
sources=("${pkgname}-${pkgver}.tar.bz2")
urls=("https://github.com/PCRE2Project/pcre2/releases/download/${pkgname}-${pkgver}/${sources[0]}")
md5sums=("f71abbe1b5adf25cd9af5d26ef223b66")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  CFLAGS+=" -ffat-lto-objects"
  CXXFLAGS+=" -ffat-lto-objects"

  ./configure --prefix=/usr                       \
              --docdir=/usr/share/doc/pcre2-${pkgver} \
              --enable-unicode                    \
              --enable-jit                        \
              --enable-pcre2-16                   \
              --enable-pcre2-32                   \
              --enable-pcre2grep-libz             \
              --enable-pcre2grep-libbz2           \
              --enable-pcre2test-libreadline      \
              --disable-static                    &&
  make
}

src_check() {
  make -j1 check
}

src_install() {
  make DESTDIR="$pkgdir" install

  install -Dm644 ./*.txt -t "$pkgdir/usr/share/licenses/$pkgname/"
}
