# Template file for 'weston'.
pkgname=weston
version=1.5.0
revision=5
build_style=gnu-configure
# XXX enable rdp compositor if freerdp is updated to >=1.1.
configure_args="--enable-libinput-backend
 --enable-colord --enable-x11-compositor --enable-xwayland"
short_desc="Reference implementation of a Wayland compositor"
maintainer="Juan RP <xtraeme@gmail.com>"
homepage="http://wayland.freedesktop.org/"
license="MIT"
distfiles="http://wayland.freedesktop.org/releases/${pkgname}-${version}.tar.xz"
checksum=06388ba04ac79aa72d685cc1a8e646ddb2b8cfe11fcc742294f9addac48b7684

hostmakedepends="pkg-config wayland-devel>=${version} autoconf automake libtool"
makedepends="libpng-devel>=1.6 wayland-devel>=${version} libxkbcommon-devel
 pixman-devel pango-devel cairo-devel>=1.12.14_5 mtdev-devel libwebp-devel>=0.4.0
 poppler-glib-devel pam-devel lcms2-devel libudev-devel libdrm-devel
 libinput-devel>=0.5.0_1 libxcb-devel libXcursor-devel colord-devel"

# cairo built with gles2 option.
depends="cairo>=1.12.14_5"
lib32disabled=yes

# Package build options
build_options="backtrace dbus systemd vaapi"
build_options_default="backtrace dbus"

if [ "$XBPS_TARGET_MACHINE" = "i686" -o "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
	build_options_default+=" vaapi"
fi

if [ "$build_option_backtrace" ]; then
	configure_args+=" --enable-libunwind"
	makedepends+=" libunwind-devel"
else
	configure_args+=" --disable-libunwind"
fi

if [ "$build_option_dbus" ]; then
	configure_args+=" --enable-dbus"
	makedepends+=" dbus-devel"
else
	configure_args+=" --disable-dbus"
fi

if [ "$build_option_systemd" ]; then
	makedepends+=" systemd-devel"
fi

if [ "$build_option_vaapi" ]; then
	configure_args+=" --enable-vaapi-recorder"
	makedepends+=" libva-devel"
else
	configure_args+=" --disable-vaapi-recorder"
fi

case "$XBPS_TARGET_MACHINE" in
armv6l) # Assume RPi for now.
	CFLAGS="-I${XBPS_CROSS_BASE}/opt/vc/include"
	LDFLAGS="-Wl,-R/opt/vc/lib"
	makedepends+=" rpi-firmware rpi-firmware-pcfiles"
	# Just enable the RPi compositor.
	configure_args+=" --disable-drm-compositor
		--disable-wayland-compositor --disable-simple-egl-clients
		--disable-fbdev-compositor --disable-egl
		--disable-setuid-install --disable-resize-optimization
		--enable-weston-launch WESTON_NATIVE_BACKEND=rpi-backend.so"
	;;
x86_64|i686)
	makedepends+=" glu-devel libva-devel"
	configure_args+=" --enable-vaapi-recorder --with-cairo-glesv2"
	;;
esac

pre_configure() {
	autoreconf -fi
}

post_install() {
	vinstall COPYING 644 usr/share/license/$pkgname
	# Remove development files.
	rm -rf ${DESTDIR}/usr/include
	rm -rf ${DESTDIR}/usr/lib/pkgconfig
}

weston-colord_package() {
	short_desc+=" - colord plugin"
	pkg_install() {
		vmove /usr/lib/weston/cms-colord.so
	}
}

weston-x11_package() {
	short_desc+=" - x11 backend"
	pkg_install() {
		vmove /usr/lib/weston/x11-backend.so
	}
}

weston-xwayland_package() {
	short_desc+=" - xwayland backend"
	pkg_install() {
		vmove /usr/lib/weston/xwayland.so
	}
}
