# Maintainer: Andy Gross <andy.gross@linaro.org>

pkgname=dtc
pkgver=1.8.1
pkgrel=1
pkgdesc='Device Tree Compiler'
arch=('i686' 'x86_64')
url='https://git.kernel.org/pub/scm/utils/dtc/dtc.git'
msys2_references=(
  'anitya: 16911'
  'cpe: cpe:2.3:a:dtc_project:dtc'
)
license=('spdx:GPL-2.0-or-later')
depends=(
  'bash'
  'libyaml'
)
makedepends=(
  'gcc'
  'libyaml-devel'
  'meson'
  'pkgconf'
  'python-devel'
  'python-setuptools-scm'
  'swig'
)
source=(
  "https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/${pkgname}-${pkgver}.tar.gz"
  '001-legacy-swig.patch'
)
sha256sums=('74b50bb19134f6562490afea53e59953dd6c4afb17e5ccb60be32221262d3390'
            '35198d278ab70499ed97f3eb9159efc6756cf2fa672563e0ec40d88b5d770ec0')

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

  patch -Np1 -i "${srcdir}/001-legacy-swig.patch"
}

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

  export SETUPTOOLS_SCM_PRETEND_VERSION="${pkgver}"

  local _meson_options=(
    --prefix=/usr
  )

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

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

  meson test -C "build-${CARCH}" --print-errorlogs || true
}

package() {
  cd "${pkgname}-${pkgver}"
  
  meson install -C "build-${CARCH}" --destdir "${pkgdir}"

  install -Dm644 README.license "${pkgdir}/usr/share/licenses/${pkgname}/README.license"
}
