#!/bin/sh
# Build script for xkeyboard-config (Meson, Template B variant, DATA-only port).
#
# No shared library ships from this port - it's the keymap XML/rules
# database the XLibre server (and xkbcomp) load/compile at runtime under
# $PREFIX/share/X11/xkb (legacy path) and $PREFIX/share/xkeyboard-config-2/
# (canonical path, meson.build's dir_xkb_base).
#
# gettext/NLS decision (Task 7a, 2026-07-22): meson.build's po/meson.build
# only runs i18n.gettext() when -Dnls is true (default true). alpha9's
# /usr/bin/msgfmt is illumos-native SVR4 msgfmt, NOT GNU-gettext compatible
# (same finding as Task 6's glib2 -Dnls=disabled decision - see memory
# glib2 gettext prereq). Pass -Dnls=false explicitly so meson's i18n
# module never invokes msgfmt/xgettext; this only disables translated
# rules/model descriptions, not keymap functionality itself.
#
# xsltproc (man page generation) is absent on alpha9; meson.build's
# find_program('xsltproc', required: false) already makes that optional,
# so no flag needed - the man page subdir is silently skipped.
#
# rules/meson.build requires python3 >= 3.11 (alpha9 has 3.13.2, built
# Task 2/M0) to run `python3 -m rules.generator` for the base/evdev rules
# files, plus the in-tree rules/xml2lst.pl perl script (perl present in
# base) - both resolved automatically by meson's find_program/pymod.
set -e
cd "$SRCDIR"

export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
export CFLAGS="${CFLAGS} -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS"
export LDFLAGS="${LDFLAGS} -L$PREFIX/lib -Wl,-R,$PREFIX/lib"

meson setup build \
    --prefix="$PREFIX" \
    --libdir=lib \
    --buildtype=release \
    -Dcompat-rules=true \
    -Dnls=false

ninja -C build -j${JOBS:-1}
DESTDIR="$PKGDIR" ninja -C build install
