# Maintainer: David Macek <david.macek.0@gmail.com>

_realname=ntldd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=r19.7fb9365
pkgrel=4
pkgdesc="Tracks dependencides in Windows PE binaries (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: mingw-w64-ntldd-git'
)
url="https://github.com/LRN/ntldd"
license=("spdx:GPL-3.0-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "git")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
_commit="7fb93650c2921b4106be6418cbaf9139125c91ab"
source=("git+https://github.com/LRN/ntldd.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

build() {
  cd "${srcdir}/${_realname}"
  sed -i -e 's/^gcc /$CC /' makeldd.sh
  ./makeldd.sh
}

package() {
  cd "${srcdir}/${_realname}"
  install -Dm755 ntldd.exe "${pkgdir}${MINGW_PREFIX}/bin/ntldd.exe"
  install -Dm644 libntldd.h "${pkgdir}${MINGW_PREFIX}/include/libntldd.h"
  install -Dm644 libntldd.a "${pkgdir}${MINGW_PREFIX}/lib/libntldd.a"
  install -Dm644 README "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README"
}
