#!/bin/sh -e

export DESTDIR="$1"

(
    cd xcvt

    # This is a really small library that is probably only needed by
    # xorg-server. We are going to build it statically.
    clsed 's,shared_library,static_library,;/version/d' lib/meson.build

    cl-meson \
        . output

    ninja -C output
    ninja -C output install
)

patch -p1 < rootless_modesetting.patch

export LIBXCVT_CFLAGS="-I$1/usr/include"
export LIBXCVT_LIBS="-L$1/usr/lib -lxcvt"
export PKG_CONFIG_PATH="$1/usr/lib/pkgconfig"

./configure \
    --prefix=/usr \
    --localstatedir=/var \
    --disable-shared \
    --disable-systemd-logind \
    --disable-unit-tests \
    --enable-glx \
    --enable-dri \
    --enable-dri2 \
    --enable-dri3 \
    --enable-glamor \
    --enable-xorg \
    --with-systemd-daemon=off

make
make DESTDIR="$1" install

rm -f "$1/usr/share/X11/xorg.conf.d/10-evdev.conf"