_realname=treedec
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.3
pkgrel=2
pkgdesc='Algorithms for computing tree decompositions of graphs'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/freetdi/tdlib/'
msys2_repository_url='https://gitlab.com/freetdi/treedec'
msys2_references=(
  'archlinux: treedec'
)
license=('spdx:GPL-2.0-or-later AND GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "git")
conflicts=("${MINGW_PACKAGE_PREFIX}-tdlib")
provides=("${MINGW_PACKAGE_PREFIX}-tdlib")
replaces=("${MINGW_PACKAGE_PREFIX}-tdlib")
source=(git+https://gitlab.com/freetdi/treedec#tag=$pkgver
        no-stderr.patch)
sha256sums=('3e7d781d4922d7b15d34e5c0f8e108fe68f085e476d521260191a98d979c16ba'
            '361471a81d187978a8a1a86c2893f3db3706c17ca9fb50eac8e6f22296626737')

prepare() {
  cd ${_realname}
  patch -p1 -i ../no-stderr.patch # Remove debug output
  ./bootstrap
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX}
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="$pkgdir"

  install -Dm644 "${srcdir}/${_realname}/COPYING" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 "${srcdir}/${_realname}/GPL-2" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL-2"
  install -Dm644 "${srcdir}/${_realname}/GPL-3" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL-3"
}
