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

_realname=libopenmpt-modplug
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.9.0
pkgrel=2
pkgdesc="A compat layer/bridge from libmodplug to libopenmpt (mingw-w64)"
arch=('any')
url="https://lib.openmpt.org"
license=("BSD")
depends=("${MINGW_PACKAGE_PREFIX}-libopenmpt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
conflicts=("${MINGW_PACKAGE_PREFIX}-libmodplug")
provides=("${MINGW_PACKAGE_PREFIX}-libmodplug")
options=('staticlibs' 'strip')
source=("https://lib.openmpt.org/files/${_realname}/${_realname}-${pkgver}-openmpt1.tar.gz")
sha256sums=('ecce1a0eecfdb0b5824cab89c270dce59596295a2c17c2b043215ecf4d7c4ff7')

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"
  ../${_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-${CARCH}"
  make check || true
}

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

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