# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
#----------------
# Pkgbuild Src  : https://git.obarun.org/pkg/obcore/dbus
#--------------------------------------------------------------------------------
# DESCRIPTION ]

pkgbase=dbus
pkgver=1.12.20
pkgrel=2
pkgdesc="Freedesktop.org message bus system"
url='https://wiki.freedesktop.org/www/Software/dbus/'

pkgname=(
    'dbus'
    'dbus-docs'
)

track="tag"
target="$pkgbase-$pkgver"
source=(
    "git+https://gitlab.freedesktop.org/dbus/dbus.git?signed#${track}=${target}"
    dbus.tmpfiles
    no-fatal-warnings.diff
)
    
#----------------------
# BUILD CONFIGURATION ]

makedepends=(
    'xmlto' 
    'docbook-xsl' 
    'python' 
    'yelp-tools' 
    'doxygen' 
    'git'
    'autoconf-archive'
)

#------------------------
# INSTALL CONFIGURATION ]

depends=(
    'expat'
    'audit'
)

conflicts=(
    'dbus-eudev'
)

install=dbus.install

#----------------
# BUILD PREPARE ]

prepare() {
    ## Allow us to enable checks without them being fatal
    patch -d "$pkgbase" -p1 -i ../no-fatal-warnings.diff

    cd $pkgbase
    NOCONFIGURE=1 ./autogen.sh
}

#----------------
# BUILD CONTROL ]

_flags=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --libexecdir=/usr/lib/dbus-1.0
    runstatedir=/run
    --with-system-pid-file=/run/dbus/pid
    --with-system-socket=/run/dbus/system_bus_socket
    --with-dbus-session-bus-listen-address=unix:runtime=yes
    --with-dbus-session-bus-connect-address=autolaunch:
    --with-dbus-user=dbus
    --with-console-auth-dir=/run/console/
    --without-systemdsystemunitdir
    --without-x
    --enable-inotify
    --disable-static
    --disable-verbose-mode
    --disable-asserts
    --disable-systemd
    --disable-user-session
    --disable-x11-autolaunch
    --disable-checks
    --enable-libaudit
)

#--------
# BUILD ]

build() {
    cd $pkgbase

    ./configure "${_flags[@]}"
    make
}

#--------
# CHECK ]

check() {
    make -C "$pkgbase" check
}

#----------
# PACKAGE ]

package_dbus(){
    depends+=(
        'libaudit.so'
    )
    provides=(
        'libdbus'
        'libdbus-1.so'
    )
    conflicts=(
        'libdbus'
    )
    replaces=(
        'libdbus'
    )
    
    DESTDIR="$pkgdir" make -C dbus install

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

    ## systemd-sysusers
    #install -D -m0644 "$srcdir/dbus.sysusers" "$pkgdir/usr/lib/sysusers.d/dbus.conf"

    ## systemd-tmpfiles
    install -D -m0644 "$srcdir"/dbus.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/dbus.conf

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

    ## Split docs
    mv "$pkgdir"/usr/share/doc "$srcdir"
}

package_dbus-docs(){
    pkgdesc+=" (documentation)"
    depends=()
    
    install -Dt "$pkgdir"/usr/share/licenses/"$pkgname" -m644 dbus/COPYING
    
    mv doc "$pkgdir"/usr/share
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(GPL custom)

validpgpkeys=(
    'DA98F25C0871C49A59EAFF2C4DE8FF2A63C7CC90'  # Simon McVittie <simon.mcvittie@collabora.co.uk>
    '3C8672A0F49637FE064AC30F52A43A1E4B77B059'  # Simon McVittie <simon.mcvittie@collabora.co.uk>
)

sha512sums=('')
