# This is an example PKGBUILD file. Use this as a start to creating your own,
# and remove these comments. For more information, see 'man PKGBUILD'.
# NOTE: Please fill out the license field for your package! If it is unknown,
# then please put 'unknown'.

# Maintainer: Olivier Medoc <o_medoc@yahoo.fr>
pkgname=qubes-vm-gui
pkgver=`cat version`
pkgrel=5
epoch=
pkgdesc="The Qubes GUI Agent for AppVMs"
arch=("x86_64")
url="http://qubes-os.org/"
license=('GPL')
groups=()
depends=(pulseaudio qubes-vm-core xorg-xinit alsa-lib alsa-utils pulseaudio-alsa libxcomposite zenity)
makedepends=(pkg-config make gcc patch git automake autoconf libtool xorg-server-devel xorg-util-macros qubes-vm-gui-common pulseaudio xf86dgaproto)
checkdepends=()
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=PKGBUILD.install
changelog=

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

noextract=()
md5sums=() #generate with 'makepkg -g'
pa_ver=`pkg-config --modversion libpulse | cut -f 1 -d "-"`

build() {

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

# 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

# Fix for building with python2
export PYTHON=python2
sed 's:!/usr/bin/python:!/usr/bin/python2:' -i appvm-scripts/usrbin/qubes-change-keyboard-layout

pa_ver=`pkg-config --modversion libpulse | cut -f 1 -d "-"`
rm -f pulse/pulsecore
ln -s pulsecore-$pa_ver pulse/pulsecore

make appvm

}

package() {

make install DESTDIR=$pkgdir PA_VER=$pa_ver SYSLIBDIR=/usr/lib LIBDIR=/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

}


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

