# Maintainer: Zoltan Gyarmati <zgyarmati@zgyarmati.de>

_realname=dwarfstack
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.3
pkgrel=1
pkgdesc="Provides stacktrace with source file/line information (mingw-w64)"
arch=('any')
mingw_arch=( 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/ssbssa/dwarfstack"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/ssbssa/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "002-no-int-conversion.patch")
sha256sums=('2c3edcb6b0beb3861f5798a89b26eb53286dc4fc598667dfcca208cc7e6096d3'
            'c8a22b5d7e5e290f745d292518e85d0b2b3b484c4d011aaaf1faf97291b83883')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 --binary -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}-${pkgver}

  apply_patch_with_msg \
    002-no-int-conversion.patch
}

build() {
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  make CC=${CC}
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install PREFIX="${pkgdir}${MINGW_PREFIX}"
  install -D -m644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
