# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Alex Filgueira <alexfilgueira (at antergos.com)>
# Contributor: Nate Simon <aurpkg (at natesimon.net)>

pkgname=xapp
pkgver=2.2.3
pkgrel=1
pkgdesc="Common library for X-Apps project"
arch=('x86_64')
url="https://github.com/linuxmint/${pkgname}"
license=('GPL')
depends=('libdbusmenu-gtk3' 'libgnomekbd')
optdepends=('python: for mate-desktop status applet')
makedepends=('meson' 'samurai' 'gobject-introspection' 'python-gobject' 'vala')
provides=('xapps')
conflicts=('xapps')
replaces=('xapps')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
sha256sums=('c74ed143a75c07c4c856f3c2425d04a3ae785ea83a00908fc681d408f2b7c0bb')
b2sums=('dba7f77eea7314fe978a1ba2b691f5c2d7e5d88f499d2f8533c8b1141262ce981cc395f8d6a0b1feaba715c63034e8dfe887e4183b5e119a0947b1ad85d99bbd')

build() {
    mkdir -p "${srcdir}"/${pkgname}-${pkgver}/build
    cd "${srcdir}"/${pkgname}-${pkgver}/build

    meson --prefix=/usr \
          --libexecdir=lib \
          --buildtype=plain \
          ..
    samu
}

package(){
    cd "${srcdir}"/${pkgname}-${pkgver}/build

    DESTDIR="${pkgdir}" samu install

    # rm useless scripts
    rm -r "${pkgdir}"/usr/bin

    # byte-compile python modules since meson does not implement autotools'
    # py-compile.
    # This is kind of ugly but removes traces of the build root.
    while read -rd '' _file; do
        _destdir="$(dirname "${_file#${pkgdir}}")"
        python -m compileall -d "${_destdir}" "${_file}"
        python -O -m compileall -d "${_destdir}" "${_file}"
    done < <(find "${pkgdir}"/usr/lib/python3* -name '*.py' -print0)
}
