# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=lib32-pcre2
_name="${pkgname#lib32-}"
pkgver=10.47
pkgrel=1.1 # Rebuild for Holo
pkgdesc='A library that implements Perl 5-style regular expressions. 2nd version (32-bit)'
arch=(x86_64)
url='https://github.com/PCRE2Project/pcre2'
license=(
  BSD-2-Clause
  'BSD-3-Clause WITH PCRE2-exception'
)
makedepends=(
  git
  lib32-bzip2
  lib32-readline
  lib32-zlib
)
provides=(libpcre2-{8,16,32,posix}.so)
source=(
  $_name::git+$url?signed#tag=$_name-$pkgver
  sljit::git+https://github.com/zherczeg/sljit.git
)
sha512sums=('5410982555171a3ab0713d04e0cac56f4d45c28cf7b89b4a39dd81ce6b3a19c665b1f0e63ea27deb89f2b9b85e0b959727a048958ba49d98c2b8d4d736578340'
            'SKIP')
b2sums=('ef02f212fe31db86dd8868a3bfc2957ef9af561b561d54c02b421ba9bf9439d9db0d9878cd829a1fcd4d483901c32e15d453d5576014c6e39a5971ffa56a6faf'
        'SKIP')
validpgpkeys=(
  45F68D54BBE23FB3039B46E59766E084FB0F43D8  # Philip Hazel <ph10@hermes.cam.ac.uk>
  A95536204A3BB489715231282A98E77EB6F24CA8  # Nicholas Wilson <nicholas@nicholaswilson.me.uk>
)

prepare() {
  cd $_name

  git submodule init
  git config submodule."deps/sljit".url ../sljit
  git -c protocol.file.allow=always submodule update

  ./autogen.sh

  # extract licenses
  cp -v deps/sljit/LICENSE ../BSD-2-Clause.txt
  sed -n '70,94p' LICENCE.md > ../BSD-3-Clause.txt
  sed -n '100,104p' LICENCE.md > ../PCRE2-exception.txt
}

build() {
  local configure_options=(
    --enable-jit
    --enable-pcre2-16
    --enable-pcre2-32
    --enable-pcre2grep-libbz2
    --enable-pcre2grep-libz
    --enable-pcre2test-libreadline
    --libdir=/usr/lib32
    --prefix=/usr
  )

  cd $_name

  export CFLAGS+=" -m32"
  export CXXFLAGS+=" -m32"
  export LDFLAGS+=" -m32"
  export PKG_CONFIG_PATH='/usr/lib32/pkgconfig'

  ./configure "${configure_options[@]}"
  make
}

check() {
  make -j1 check -C $_name
}

package() {
  # Holo: we have the 'depends' list here so it is ignored at build time.
  # Requiring pcre2=$pkgver only at runtime allow us to build both 32
  # and 64 bit versions of this package in parallel.
  depends=(
    lib32-glibc
    "$_name=$pkgver"
  )
  make DESTDIR="$pkgdir" install -C $_name

  rm -rv "$pkgdir"/usr/{bin,share,include}

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

# vim:set sw=2 sts=-1 et:
