# Maintainer (arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: Link Dupont <link@subpop.net>
# Contributor: bill-auger <bill-auger@programmer.net>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>


# parabola changes and rationale:
# - support non-systemd
# - disable tests by default (some require networking)


pkgbase=dbus
pkgname=(
  dbus
  dbus-docs
)
pkgver=1.14.6
pkgrel=2
pkgrel+=.nonsystemd1
pkgdesc="Freedesktop.org message bus system"
url="https://wiki.freedesktop.org/www/Software/dbus/"
arch=(x86_64)
arch+=(i686 armv7h)
license=(
  GPL
  custom
)
depends=(
  audit
  expat
  systemd-libs
)
depends=( ${depends[*]/systemd-libs/libelogind} )
depends+=(libx11)
makedepends=(
  autoconf-archive
  docbook-xsl
  doxygen
  git
  python
  systemd
  xmlto
  yelp-tools
)
makedepends=( ${makedepends[*]/systemd/elogind} )
source=(
  "git+https://gitlab.freedesktop.org/dbus/dbus.git?signed#tag=dbus-$pkgver"
  dbus-enable-elogind.patch
  no-fatal-warnings.diff
)
b2sums=('SKIP'
        'c9ef41ff7b31af6cbaf28ca16974fb62aa0f2492f1c6970b41216758768d1139d2ce9aabbb3aff952d625b0decd1e8c2b25f79bb0a13c146aa9453dd4f7b5c5a'
        '1f14c134f0511b7bd8e2dc71f665a6e6e23f0addd944888c6f956d4f29c7caa962aa05fdbe9a10d500a28751ba635168248ae7609c269e03e00366b85d5d488f')
validpgpkeys=('DA98F25C0871C49A59EAFF2C4DE8FF2A63C7CC90') # Simon McVittie <simon.mcvittie@collabora.co.uk>


_DISABLE_TESTS=1


prepare() {
  cd dbus

  patch -Np 1 -i ../dbus-enable-elogind.patch

  # Allow us to enable checks without them being fatal
  patch -Np1 -i ../no-fatal-warnings.diff

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --libexecdir=/usr/lib/dbus-1.0
    --runstatedir=/run
    --with-console-auth-dir=/run/console/
    --with-dbus-user=dbus
    --with-system-pid-file=/run/dbus/pid
    --with-system-socket=/run/dbus/system_bus_socket
    --with-systemdsystemunitdir=/usr/lib/systemd/system
    --enable-inotify
    --enable-libaudit
    --enable-systemd
    --enable-user-session
    --enable-xml-docs
    --enable-doxygen-docs
    --enable-ducktype-docs
    --disable-static
    --without-x
  )
  configure_options=( ${configure_options[*]/--with-systemdsystemunitdir=\/usr\/lib\/systemd\/system/--without-systemdsystemunitdir} )
  configure_options=( ${configure_options[*]/--enable-systemd/--disable-systemd} )
  configure_options=( ${configure_options[*]/--enable-user-session/--disable-user-session} )
  configure_options=( ${configure_options[*]/--without-x/--enable-x11-autolaunch} )
  configure_options+=( --enable-elogind )

  cd dbus
  ./configure "${configure_options[@]}"
  make
}

check() {
  (( ! _DISABLE_TESTS )) || ! echo "skipping check()" || return 0

  make -C dbus -j1 check
}

package_dbus() {
  depends+=(
    libaudit.so
    libsystemd.so
  )
  depends=( ${depends[*]/libsystemd.so/libelogind.so} )
  provides=(
    libdbus
    libdbus-1.so
  )
  conflicts=(libdbus)
  replaces=(libdbus)

  DESTDIR="$pkgdir" make -C dbus install

  rm -r "$pkgdir"/{etc,var}

  # We have a pre-assigned uid (81)
  echo 'u dbus 81 "System Message Bus"' |
    install -Dm644 /dev/stdin "$pkgdir/usr/lib/sysusers.d/dbus.conf"

  # TODO: missing hook?

  # Split docs
  mkdir -p doc/usr/share
  mv {"$pkgdir",doc}/usr/share/doc

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 dbus/COPYING
}

package_dbus-docs() {
  pkgdesc+=" - Documentation"
  depends=()

  mv doc/* "$pkgdir"

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 dbus/COPYING
}

