pkgname=(qubes-vm-gui qubes-vm-pulseaudio)
pkgver=`cat version`
pkgrel=10
epoch=
pkgdesc="The Qubes GUI Agent for AppVMs"
arch=("x86_64")
url="http://qubes-os.org/"
license=('GPL')
groups=()
makedepends=(pkg-config make gcc patch git automake autoconf libtool
			pulseaudio
			xorg-server-devel xorg-util-macros libxcomposite libxt pixman
			qubes-vm-gui-common qubes-libvchan-xen qubes-db-vm
			)
checkdepends=()
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
changelog=

source=(PKGBUILD-z-qubes-session.sh)

noextract=()
md5sums=() #generate with 'makepkg -g'
pa_ver=`(pkg-config --modversion libpulse 2>/dev/null || echo 0.0) | cut -f 1 -d "-"`

build() {

for source in Makefile appvm-scripts gui-common include pulse gui-agent common xf86-input-mfndev xf86-video-dummy window-icon-updater ; do
  (ln -s $srcdir/../$source $srcdir/$source)
done

pa_ver=`(pkg-config --modversion libpulse 2>/dev/null || echo 0.0) | cut -f 1 -d "-"`

rm -f pulse/pulsecore
ln -s pulsecore-$pa_ver pulse/pulsecore

# Bug fixes : /var/run/console depends on pam_console, which is fedora specific
# As a consequece, /var/run/console does not exists and qubes-gui-agent will always fail
sed 's:ExecStartPre=/bin/touch:#ExecStartPre=/bin/touch:' -i appvm-scripts/qubes-gui-agent.service
# Ensure that qubes-gui-agent starts after user autologin
sed 's/After=\(.*\)qubes-misc-post.service/After=\1qubes-misc-post.service getty.target/' -i appvm-scripts/qubes-gui-agent.service

make appvm

}

package_qubes-vm-gui() {

depends=('xorg-xinit' 'libxcomposite' 'zenity' 'qubes-libvchan-xen' 'python-xcffib'
			# Xorg dependencies are on specific ABI versions: https://www.x.org/wiki/XorgModuleABIVersions/
			# These can also be verified with pacman -Qi xorg-server (Provides)
			# There is however a discrepency if verifying via pkg-config --variable abi_videodrv xorg-server
			'X-ABI-VIDEODRV_VERSION=24.0' 'X-ABI-XINPUT_VERSION=24.1' 'X-ABI-EXTENSION_VERSION=10.0'
			)
install=PKGBUILD.install

make install-rh-agent DESTDIR=$pkgdir LIBDIR=/usr/lib USRLIBDIR=/usr/lib SYSLIBDIR=/usr/lib

# Specific to archlinux: qubes session needs to be the last started script when Xorg starts.
# For Fedora Qubes devs team choosed to populate it in /etc/sysconfig/desktop, but this is not supported by Archlinux
# Using z-qubes-session allows it to be the last started script in xinitrc.d...
mkdir -p $pkgdir/etc/X11/xinit/xinitrc.d/
install -D $srcdir/PKGBUILD-z-qubes-session.sh $pkgdir/etc/X11/xinit/xinitrc.d/z-qubes-session.sh

}

package_qubes-vm-pulseaudio() {

pkgdesc="Pulseaudio support for Qubes VM"
depends=('alsa-lib' 'alsa-utils' 'pulseaudio-alsa' 'pulseaudio<14.1')
install=PKGBUILD-pulseaudio.install
pa_ver=`(pkg-config --modversion libpulse 2>/dev/null || echo 0.0) | cut -f 1 -d "-"`

make install-pulseaudio DESTDIR=$pkgdir PA_VER=$pa_ver LIBDIR=/usr/lib USRLIBDIR=/usr/lib SYSLIBDIR=/usr/lib

}

# vim:set ts=2 sw=2 et:
