#!/bin/sh
# Build script for pcre2 (autotools, Template A). No deps (zlib/bz2 not
# needed - pcre2grep's compressed-file support is optional and skipped).
set -e
cd "$SRCDIR"

# Mandatory libtool hammerhead* dynamic-linker fix (see libXrender/Task 4a
# gotcha): unmatched host_os falls through to "dynamic_linker=no", forcing
# static-only output without this.
if [ -f configure ]; then
    sed -i -E 's/(kopensolaris\*-gnu)([^)]*\))/\1 | hammerhead*\2/' configure
fi

export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
export CFLAGS="${CFLAGS} -I$PREFIX/include -D__EXTENSIONS__"
export LDFLAGS="${LDFLAGS} -L$PREFIX/lib -R$PREFIX/lib"

./configure \
    --prefix="$PREFIX" \
    --build="$BUILD_TRIPLE" \
    --host="$BUILD_TRIPLE" \
    --sysconfdir="$SYSCONFDIR" \
    --disable-static \
    --enable-pcre2-16 \
    --enable-pcre2-32

gmake -j${JOBS:-1}
gmake install DESTDIR="$PKGDIR"
