# Maintainer: Leandro Nini <drfiemost@email.it>

_realname=libopenmpt-modplug
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.9.0
pkgrel=3
pkgdesc="A compat layer/bridge from libmodplug to libopenmpt (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://lib.openmpt.org"
msys2_references=(
  "cpe: cpe:/a:openmpt:libopenmpt"
)
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-libopenmpt")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
conflicts=("${MINGW_PACKAGE_PREFIX}-libmodplug")
provides=("${MINGW_PACKAGE_PREFIX}-libmodplug")
source=("https://lib.openmpt.org/files/${_realname}/${_realname}-${pkgver}-openmpt1.tar.gz")
sha256sums=('ecce1a0eecfdb0b5824cab89c270dce59596295a2c17c2b043215ecf4d7c4ff7')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}-openmpt1"
  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

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

  ../${_realname}-${pkgver}-openmpt1/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --enable-libmodplug

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}-openmpt1/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
