# Maintainer (arch): Sébastien "Seblu" Luttringer
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Eric Belanger <eric@archlinux.org>
# Contributor: John Proctor <jproctor@prium.net>
# Maintainer: Luke Shumaker <lukeshu@parabola.nu>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Contributor: bill-auger <bill-auger@programmer.net>

_pkgname=pcre
pkgname=pcre-static
pkgver=8.45
pkgrel=1
pkgrel+=.static1
pkgdesc='A library that implements Perl 5-style regular expressions'
pkgdesc+=' (static libraries)'
arch=('x86_64')
arch+=('armv7h' 'i686')
url='https://www.pcre.org/'
license=('BSD3')
depends=("$_pkgname=$pkgver")
options=('staticlibs')
validpgpkeys=('45F68D54BBE23FB3039B46E59766E084FB0F43D8') # Philip Hazel
source=("https://ftp.pcre.org/pub/pcre/$pkgname-$pkgver.tar.bz2"{,.sig})
# ftp.pcre.org is offline
source=(https://sourceforge.net/projects/pcre/files/pcre/${pkgver}/${_pkgname}-${pkgver}.tar.bz2{,.sig})
sha512sums=('91bff52eed4a2dfc3f3bfdc9c672b88e7e2ffcf3c4b121540af8a4ae8c1ce05178430aa6b8000658b9bb7b4252239357250890e20ceb84b79cdfcde05154061a'
            'SKIP')

prepare() {
  cd $_pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      msg2 "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done
  :
}

build() {
  cd $_pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --enable-unicode-properties \
    --enable-pcre16 \
    --enable-pcre32 \
    --enable-jit \
    --enable-pcregrep-libz \
    --enable-pcregrep-libbz2 \
    --enable-pcretest-libreadline
  make
}

check() {
  cd $_pkgname-$pkgver
  if [[ $CARCH == armv7h ]]; then return 0; fi # qemu: Unsupported syscall: 229
  make -j1 check || : # 'RunTest' test fails in librechroot
}

package() {
  cd $_pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  install -Dm644 LICENCE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # remove conflicting files
  rm -vr -- \
     "$pkgdir"/usr/bin/ \
     "$pkgdir"/usr/include/ \
     "$pkgdir"/usr/lib/pkgconfig/ \
     "$pkgdir"/usr/share/doc/ \
     "$pkgdir"/usr/share/man/
  rm -v -- \
     "${pkgdir}"/usr/lib/lib*.so \
     "${pkgdir}"/usr/lib/lib*.so.*
}

