# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmangle
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=9.0.0.6246.ae63cde27
pkgrel=1
_commit='ae63cde274dc1d25756df7e730eeb3af01cac687'
pkgdesc="MinGW-w64 libmangle"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://mingw-w64.sourceforge.io/"
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain")
makedepends=("git"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-binutils"
             "${MINGW_PACKAGE_PREFIX}-crt-git"
             "${MINGW_PACKAGE_PREFIX}-headers-git")
options=('strip' 'staticlibs' '!emptydirs')
source=("mingw-w64"::"git+https://git.code.sf.net/p/mingw-w64/mingw-w64#commit=$_commit")
sha256sums=('SKIP')

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

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ${srcdir}/mingw-w64/mingw-w64-libraries/libmangle/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/mingw-w64/mingw-w64-libraries/libmangle/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/mingw-w64-libraries/COPYING.${_realname}
}
