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

pkgname=dtc
pkgver=1.7.2
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=('GPL2')
depends=('libyaml')
makedepends=('python-devel' 'swig' 'libyaml-devel' 'gcc' 'python-setuptools-scm' 'pkgconf')
source=("https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/${pkgname}-${pkgver}.tar.gz"
        01-correct-shared-library-extension.patch
        02-pyext-install.patch)
sha256sums=('8f1486962f093f28a2f79f01c1fd82f144ef640ceabe555536d43362212ceb7c'
            'ac65df904e09681cd5a4c12a063a91ce7055fdd24748fde6519c433ced480861'
            '0135724ce6f5a30a381d2097bc6afa561168bdc16c42608fcc34c3990fa5b990')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  sed -i 's/python\b/python3/' tests/run_tests.sh

  # to make check work
  sed -i 's/__attribute__((weak))//' tests/testutils.c

  patch -p1 -i "${srcdir}/01-correct-shared-library-extension.patch"
  patch -p1 -i "${srcdir}/02-pyext-install.patch"
}

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

  export SETUPTOOLS_SCM_PRETEND_VERSION="${pkgver}"
  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  $ PATH=$PWD/libfdt:$PATH/pylibfdt:$PATH make check || true
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -j1 PREFIX=/usr DESTDIR="${pkgdir}" install

  # license
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/README.license ${pkgdir}/usr/share/licenses/${pkgname}/README.license
}

