# Maintainer (Arch): Andreas Radke <andyrtr@archlinux.org>
# Maintainer (Arch): Jan de Groot <jgc@archlinux.org>
# Maintainer: André Silva <emulatorman@hyperbola.info>
# Contributor: Tobias Dausend <throgh@hyperbola.info>

pkgname=xdg-utils
pkgver=1.1.3
_debver=$pkgver
_debrel=4.1
pkgrel=4
pkgdesc="Command line tools that assist applications with a variety of desktop integration tasks"
arch=('any')
url="https://www.freedesktop.org/wiki/Software/xdg-utils/"
license=('Expat')
depends=('sh' 'xenocara-xset')
makedepends=('docbook-xsl' 'lynx' 'xmlto' 'git-legacy' 'quilt')
optdepends=('xenocara-xprop: for Xfce support in xdg-open'
            'perl-file-mimeinfo: for generic support in xdg-open'
            'perl-x11-protocol: Perl X11 protocol support')
source=(https://portland.freedesktop.org/download/$pkgname-$pkgver.tar.gz
        https://deb.debian.org/debian/pool/main/x/xdg-utils/xdg-utils_$_debver-$_debrel.debian.tar.xz
        libre.patch)
sha512sums=('d1f819a211eb4104a90dfdc6fedcb640fd46b15ccfc8762266f8f538c49d74cb00027b8c1af991fb2a200acb4379986ae375700e06a2aa08fb41a38f883acb3e'
            '31c30c802b41eaaa67909af309d16469acb2f3793b28b7a6867a63b1e9433fa052677ee7fa0d9eb50f6f7397c6dc692dd23bdadbe2bfce89e8b9f51466f3de6f'
            '6eb62010b0a076ac4e029ad74fed2cc1cd1671caabc470375f35079bcceb29901b470b6dddcce4d3a6996cf6966cf4923d266420a811aa9e65d6b9d3759de641')

prepare() {
  cd $pkgname-$pkgver

  if [[ ${pkgver%.*} = ${_debver%.*} ]]; then
    # Debian patches
    export QUILT_PATCHES=debian/patches
    export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
    export QUILT_DIFF_ARGS='--no-timestamps'

    mv "$srcdir"/debian .

    quilt push -av
  fi

  # remove non-free references
  patch -Np1 -i $srcdir/libre.patch
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --mandir=/usr/share/man
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="${pkgdir}" install
  install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  # install empty directory to prevent xdg-desktop-menu install *.desktop to fail, see FS#33316
  install -dm755 $pkgdir/usr/share/desktop-directories
}
