#!/bin/sh
# Build script for xrdb (autotools, Template A + runtime cpp pin).
set -e
cd "$SRCDIR"

# MANDATORY libtool fix (Task 4a, 2026-07-22): see libXau/build.sh for the
# full explanation. Piggyback hammerhead onto the kopensolaris arm.
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/local/lib/pkgconfig:$PKG_CONFIG_PATH"
export CFLAGS="${CFLAGS} -I$PREFIX/include -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS"
export LDFLAGS="${LDFLAGS} -L$PREFIX/lib -R$PREFIX/lib"

# xrdb pipes resource files through cpp at RUNTIME, not just build time.
# configure's AC_PATH_PROG probe would find Hammerhead's /usr/bin/cpp via
# PATH anyway, but pin it explicitly so the result doesn't depend on PATH
# search order across build hosts.
./configure \
    --prefix="$PREFIX" \
    --build="$BUILD_TRIPLE" \
    --host="$BUILD_TRIPLE" \
    --sysconfdir="$SYSCONFDIR" \
    --disable-static \
    --with-cpp=/usr/bin/cpp

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