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

_realname=libmangle
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=13.0.0.r388.gbb8673e5f
pkgrel=1
_commit='bb8673e5f137300b018d1dcdeab1c28c1d292e97'
pkgdesc="MinGW-w64 libmangle (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.mingw-w64.org/"
msys2_repository_url="https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-libraries/libmangle/"
license=('spdx:MIT')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}-git=${pkgver}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-crt"
             "${MINGW_PACKAGE_PREFIX}-headers"
             "git")
options=('!emptydirs')
source=("mingw-w64"::"git+https://git.code.sf.net/p/mingw-w64/mingw-w64#commit=$_commit")
sha256sums=('8668e7f398b98b493e131fee57500466ab334c3fff0e6cf754e49aee5f223b44')

pkgver() {
  cd "${srcdir}/mingw-w64"
  git describe --long ${_commit} | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//g'
}

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

  "${srcdir}"/mingw-w64/mingw-w64-libraries/libmangle/configure \
    --prefix=${MINGW_PREFIX}

  make
}

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