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

_realname=libopenmpt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.4
pkgrel=1
pkgdesc="A cross-platform C++ and C library to decode tracked music files (modules) into a raw PCM audio stream (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://lib.openmpt.org/libopenmpt/'
msys2_repository_url='https://github.com/OpenMPT/openmpt'
msys2_references=(
  "cpe: cpe:/a:openmpt:libopenmpt"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-zlib"
          "${MINGW_PACKAGE_PREFIX}-mpg123"
          "${MINGW_PACKAGE_PREFIX}-libogg"
          "${MINGW_PACKAGE_PREFIX}-libvorbis"
          "${MINGW_PACKAGE_PREFIX}-portaudio"
          "${MINGW_PACKAGE_PREFIX}-libsndfile"
          "${MINGW_PACKAGE_PREFIX}-flac")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://lib.openmpt.org/files/${_realname}/src/${_realname}-${pkgver}+release.autotools.tar.gz")
sha256sums=('627f9bf11aacae615a1f2c982c7e88cb21f11b2d6f0267946f7c82c5eae4943b')

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

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

  CPPFLAGS+=" -DMPT_CHECK_CXX_IGNORE_WARNING_O2" \
  ../${_realname}-${pkgver}+release.autotools/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-examples

  make
}

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

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}+release.autotools/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
