# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=pkgfile
pkgver=26
pkgrel=1
pkgdesc='A pacman .files metadata explorer'
arch=('i686' 'x86_64')
url='https://github.com/falconindy/pkgfile'
msys2_repository_url='https://github.com/falconindy/pkgfile'
msys2_references=(
  'anitya: 137691'
  'archlinux: pkgfile'
)
license=('spdx:MIT')
depends=(
  'curl'
  'libarchive'
  'pacman'
  'pcre'
)
makedepends=(
  'clang'
  'gcc'
  'libarchive-devel'
  'libcurl-devel'
  'meson'
  'pcre-devel'
  'perl'
)
checkdepends=(
  'gtest'
  'python'
)
options=('emptydirs')
install='pkgfile.install'
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/falconindy/${pkgname}/archive/v${pkgver}.tar.gz"
  '001-meson-pkgfiled.patch'
)
sha256sums=('8c6c558ebec32a6d40ba90a18a06328e382c0639879ae02dd83dfa03a5d51988'
            '618f55b39aebf3234941e888bf181aa226fd09e35192344523a32533da2dbe65')

prepare() {
  cd "${pkgname}-${pkgver}"

  # msys cannot use systemd daemons
  patch -Np1 -i "${srcdir}/001-meson-pkgfiled.patch"
}

build() {
  cd "${pkgname}-${pkgver}"

  export CXXFLAGS="${CXXFLAGS} -D_GNU_SOURCE"

  local _meson_options=(
    --prefix=/usr
    -Dsystemd_units=false
  )

  meson setup "build-${CARCH}" "${_meson_options[@]}"
  meson compile -C "build-${CARCH}"
}

check() {
  cd "${pkgname}-${pkgver}"
  
  meson test -C "build-${CARCH}" --print-errorlogs
}

package() {
  cd "${pkgname}-${pkgver}"

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

  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
