# Maintainer: David P. <megver83@parabola.nu>
# Maintainer (Artix): artoo <artoo@artixlinux.org>

_pkgname=elogind
pkgname=lib32-elogind
pkgver=246.10
pkgrel=1
pkgdesc="The systemd project's logind, extracted to a standalone package (32-bit)"
arch=('x86_64')
url="https://github.com/elogind/elogind"
license=('GPL' 'LGPL2.1')
provides=('lib32-systemd')
depends=('lib32-gcc-libs' 'lib32-acl' 'lib32-libcap' 'lib32-libgcrypt' 'lib32-libxcrypt'
         'lib32-eudev' 'elogind')
makedepends=('git' 'gperf' 'intltool' 'lib32-bzip2'
             'lib32-curl' 'lib32-dbus' 'lib32-gcc-libs' 'lib32-glib2'
             'lib32-gnutls' 'lib32-libelf' 'lib32-libidn2' 'lib32-pcre2'
             'libxslt' 'meson')
conflicts=('lib32-systemd')
options=('!libtool')
source=("${_pkgname}-${pkgver}.tar.gz::https://github.com/elogind/elogind/archive/v${pkgver}.tar.gz")
sha256sums=('c490dc158c8f5bca8d00ecfcc7ad5af24d1c7b9e59990a0b3b1323996221a922')

prepare() {
    cd ${_pkgname}-${pkgver}
}

build() {
    export CC="gcc -m32"
    export CXX="g++ -m32"
    export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"

    local meson_options=(
        --libexecdir /usr/lib32
        --libdir /usr/lib32
        -Daudit=false
        -Ddbuspolicydir=/usr/share/dbus-1/system.d
        -Ddocdir=/usr/share/doc/elogind
        -Ddefault-hierarchy=hybrid
        -Dlibcryptsetup=false
        -Ddefault-kill-user-processes=false
    )

    arch-meson "${_pkgname}-${pkgver}" build "${meson_options[@]}"

    ninja -C build
}

check(){
    meson test -C build --print-errorlogs
}

package() {
    DESTDIR="$pkgdir" ninja -C build install

    ln -sfv libelogind.pc "${pkgdir}"/usr/lib32/pkgconfig/libsystemd.pc

    rm -rf "${pkgdir}"/{etc,var}
    rm -rf "${pkgdir}"/usr/{bin,include,lib,share}
}
