#!/bin/sh -e

patch -p1 < no-fribidi.patch

# GTK+3 on Wayland requires gsettings-desktop-schemas
# for gsettings to work correctly. Under X11 it made
# use of xsettings but this is no longer the case.
(
    cd schemas

    meson \
        --prefix=/usr \
        -Dintrospection=false \
        . output

    ninja -C output
    ninja -C output install
)

# Remove configure check for atk-bridge and fribidi.
sed -e 's/\(ATK_PACKAGES="atk\) atk-bridge-2.0"/\1"/' \
    -e 's/fribidi >= 0\.19\.7//g' \
    configure > _
mv -f _ configure

# Remove atk-bridge code.
sed '/<atk-bridge.h>/d;/atk_bridge_adaptor_init/d' \
    gtk/a11y/gtkaccessibility.c > _
mv -f _ gtk/a11y/gtkaccessibility.c

# Don't build GTK examples/demos/testsuite.
sed 's/demos tests testsuite examples//;s/docs \(m4macros\)/\1/' Makefile.in > _
mv -f _ Makefile.in

sh ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --enable-wayland-backend \
    --disable-x11-backend \
    --disable-schemas-compile \
    --disable-cups \
    --disable-papi \
    --disable-cloudprint \
    --disable-glibtest \
    --disable-nls \
    --disable-installed-tests \
    --enable-introspection=no \
    --enable-colord=no \
    --enable-gtk-doc-html=no

make
make install

# We don't compile with librsvg which leads to this
# utility solely causing compiler errors for some
# packages. It has no use at all.
rm -f "$1/usr/bin/gtk-encode-symbolic-svg"