|
root / base / glib2 / build.sh
build.sh Bash 104 lines 5.7 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#!/bin/sh
# Build script for glib2 (Meson, Template B).
# Deps: pcre2 (ported, above), libffi + zlib (PRESENT in base, /usr/lib -
# not ported; their .pc files are picked up via the /usr/lib/pkgconfig
# entry below). iconv is provided by illumos libc - meson's builtin
# dependency('iconv') probe finds it there with no extra flag needed.
#
# GOTCHA (Task 6): illumos ships a native Sun/illumos `msgfmt` at
# /usr/bin/msgfmt that is NOT command-line compatible with GNU gettext's
# msgfmt (confirmed on alpha9: `msgfmt --version` errors with "Cannot open
# file --version" - it treats every arg as a filename to open, not an
# option). glib's po/meson.build calls i18n.gettext(), which requires a
# GNU-compatible msgfmt/xgettext. glib's own `nls` option defaults to
# 'auto' and gates the entire po/ subdir behind `find_program('xgettext',
# required: get_option('nls'))`, so passing -Dnls=disabled skips that
# subdir entirely (no msgfmt/xgettext ever invoked) without touching any
# core (non-translation) functionality. No devel/gettext port needed for
# this port.
#
# GOTCHA (Task 6): meson's dtrace/systemtap options default to 'auto' and
# both probe-detect true because /usr/sbin/dtrace exists on Hammerhead
# (illumos DTrace). But glib's meson dtrace codegen step assumes the
# Linux/systemtap-style two-pass workflow (compile objects with probes
# first, THEN `dtrace -G` against those objects); it invokes
# `dtrace -G -s glib_probes.d -o glib_probes.o` with ONLY the .d script
# and no object files, which illumos dtrace rejects: "failed to link
# script ...: No probe sites found for declared provider" - not an
# illumos/dtrace bug, just glib's meson dtrace glue not matching how
# illumos's -G-only invocation needs objects present. Static USDT probes
# are optional instrumentation, not core functionality - disable
# dtrace/systemtap explicitly rather than relying on 'auto' probing.
set -e
cd "$SRCDIR"

# GOTCHA (Task 6): meson's host_machine.system() comes straight from
# Python's platform.system().lower() at configure time, which on
# Hammerhead reports 'hammerhead' (confirmed: `uname -s` => "Hammerhead"
# post-SYSNAME_PLATFORM_RENAME), not 'sunos'. glib's meson.build has
# several `host_system == 'sunos'` branches specifically for illumos/
# Solaris correctness - none of them fire for us. The one that bites at
# build time: "if host_system != 'sunos': functions += ['sysinfo']" -
# meson then probes cc.has_function('sysinfo') (true - illumos HAS a
# sysinfo(), just the unrelated SVR4 systeminfo(2) one, not Linux's
# struct-sysinfo RAM-stats one) and sets HAVE_SYSINFO, so
# gio/gmemorymonitorbase.c compiles the Linux `struct sysinfo`
# code path instead of its already-present Solaris sysconf(_SC_PHYS_PAGES)
# fallback. Patch the guard to also exclude 'hammerhead' rather than
# disabling memory-monitor functionality outright.
if [ -f meson.build ]; then
    sed -i "s/if host_system != 'sunos'/if host_system != 'sunos' and host_system != 'hammerhead'/" meson.build
fi

export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
# GOTCHA (Task 6): illumos libc's iconv(3) takes `const char **` for the
# input-buffer argument (POSIX-conformant), but glib/gconvert.c's g_iconv()
# wrapper takes plain `char **` and passes it straight through (glib has no
# configure-time ICONV_CONST detection - it assumes the glibc signature).
# GCC 14 promoted -Wincompatible-pointer-types from a warning to a hard
# error by default in C mode, so this one call site now fails the build.
# Rather than patching upstream glib source, demote it back to a warning.
# GOTCHA (Task 6): illumos's <pwd.h> (and <grp.h>) gate the POSIX.1c
# 5-arg reentrant getpwnam_r()/getpwuid_r() prototypes (returning int,
# via a 'struct passwd **' result out-param) behind
# `_POSIX_C_SOURCE >= 199506L || defined(_POSIX_PTHREAD_SEMANTICS)`.
# __EXTENSIONS__ alone is NOT enough - without one of those two also
# defined, the header falls back to the legacy SVR4 4-arg form (returning
# 'struct passwd *' directly), which is what glib/gutils.c's
# g_get_user_database_entry() gets miscompiled against ("too many
# arguments to function 'getpwnam_r'"). Define _POSIX_PTHREAD_SEMANTICS
# to select the POSIX form glib expects (also fixes the same class of
# issue for getgrnam_r/getgrgid_r if pango/harfbuzz/cairo ever probe them).
# GOTCHA (Task 6): glib's meson.build has a `host_system == 'sunos'`
# block (unreached here, same host_system-name mismatch as above) that
# probes and sets the highest working `_XOPEN_SOURCE` (800/700/600) plus
# __EXTENSIONS__ specifically so illumos's <sys/socket.h> exposes the
# XPG4v2 struct msghdr fields (msg_control/msg_controllen/msg_flags -
# gated behind `#if defined(_XPG4_2)`, which /usr/include/sys/
# feature_tests.h only #defines once _XOPEN_SOURCE is set to 500+).
# Without it, gio/gsocket.c's msghdr-based recvmsg/sendmsg ancillary-data
# code fails ("struct msghdr has no member named msg_control"). Set
# _XOPEN_SOURCE=700 directly (cascades to _XPG4_2 in feature_tests.h);
# __EXTENSIONS__ is still required alongside it so the XOPEN-strict mode
# doesn't hide the non-standard extensions glib also needs elsewhere.
export CFLAGS="${CFLAGS} -D__EXTENSIONS__ -D_XOPEN_SOURCE=700 -D_POSIX_PTHREAD_SEMANTICS -Wno-error=incompatible-pointer-types"
export LDFLAGS="${LDFLAGS} -Wl,-R,$PREFIX/lib"

meson setup build \
    --prefix="$PREFIX" \
    --libdir=lib \
    --sysconfdir="$SYSCONFDIR" \
    --buildtype=release \
    -Ddefault_library=shared \
    -Dtests=false \
    -Dselinux=disabled \
    -Dxattr=false \
    -Dman-pages=disabled \
    -Dintrospection=disabled \
    -Dnls=disabled \
    -Ddtrace=disabled \
    -Dsystemtap=disabled

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