#!/bin/sh
# Build script for picom (Meson, Template B). RISKY per task brief.
#
# xrender backend ONLY: -Dopengl=false (no Mesa/GL on Hammerhead) skips the
# epoxy dependency entirely (src/meson.build only calls
# `dependency('epoxy')` inside `if get_option('opengl')`). -Ddbus=false
# skips dbus-1 (not needed for a plain compositor).
#
# picom's src/meson.build unconditionally requires several xcb-util family
# pkg-config modules that were NOT yet in zports: xcb-image, xcb-renderutil,
# xcb-util (base). Added as base/xcb-util, base/xcb-util-image,
# base/xcb-util-renderutil (small fd.o autotools ports, built first).
# It also does `cc.has_header('uthash.h')` - not shipped anywhere in the
# tree, so added base/uthash (header-only, build-dep only).
set -e
cd "$SRCDIR"

export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
export CFLAGS="${CFLAGS} -I$PREFIX/include -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 \
    -Ddefault_library=shared \
    -Dopengl=false \
    -Ddbus=false \
    -Dwith_docs=false \
    -Dunittest=false

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