# Maintainer: Bruno Pagani <archange@archlinux.org>
# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Maintainer: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Mirco Tischler <mt-ml at gmx dot de>

pkgname=fwupd
pkgver=dummy
pkgrel=1
pkgdesc='A system daemon to allow session software to update firmware'
arch=('i686' 'x86_64')
url='https://github.com/fwupd/fwupd'
license=(LGPL-2.1-or-later)
depends=(
  bash
  curl
  fwupd-efi
  gcc-libs
  glib2
  glibc
  gnutls
  gsettings-desktop-schemas
  hicolor-icon-theme
  libusb
  libmbim
  libmm-glib
  libqmi
  libxmlb
  passim
  polkit
  shared-mime-info
  sqlite
  systemd-libs
  tpm2-tss
  xz
  zlib
)
makedepends=(
  bash-completion
  gi-docgen
  gnu-efi-libs
  gobject-introspection
  libdrm
  meson
  noto-fonts
  noto-fonts-cjk
  python-cairo
  python-dbus
  python-gobject
  vala
  valgrind
)
checkdepends=(umockdev)

pkgver() {
    cd ${pkgname}

    VERSION=$(git describe | sed 's/-/.r/;s/-/./')
    [ -z $VERSION ] && VERSION=$(head meson.build | grep ' version:' | cut -d \' -f2)

    echo $VERSION
}

build() {
  cd ${pkgname}
  if [ -n "$CI" ]; then
    export CI="--wrap-mode=default -Db_coverage=true"
  fi
  arch-meson -D b_lto=false $CI ../build \
    -Ddocs=enabled \
    -Defi_binary=false \
    -Dplugin_uefi_capsule_splash=false \
    -Dbluez=disabled

  XDG_DATA_HOME=/tmp meson compile -C ../build
}

check() {
  CACHE_DIRECTORY=/tmp meson test -C build --print-errorlogs
}

package() {
  depends+=(
    libcurl.so
    libmm-glib.so
    libpassim.so
    libqmi-glib.so
  )
  optdepends=(
    'python-dbus: Firmware packaging tools'
    'python-gobject: Firmware packaging tools'
    'udisks2: UEFI firmware upgrade support'
  )
  provides=(libfwupd.so)
  backup=(
    'etc/fwupd/fwupd.conf'
    'etc/fwupd/remotes.d/lvfs-testing.conf'
    'etc/fwupd/remotes.d/lvfs.conf'
    'etc/fwupd/remotes.d/vendor-directory.conf'
  )

  meson install -C build --destdir "${pkgdir}"
}
