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

pkgname=dtc
pkgver=1.6.1
pkgrel=1
pkgdesc="Device Tree Compiler"
arch=('i686' 'x86_64')
url="https://git.kernel.org/pub/scm/utils/dtc/dtc/git"
license=('GPL2')
depends=('libyaml')
makedepends=('python-devel' 'swig' 'libyaml-devel')
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=('6401c9a0f577a270df4632bf0f3e5454ccc7a5ca3caefa67a3e1c29c9c6b8c60'
            'c0dd05748bac0d5fd859c9684da58b44acdbc2ac359642c630c75bcec8cbb84d'
            '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}"
  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
}

