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

_realname=libmikmod
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.13
pkgrel=1
pkgdesc="A portable sound library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://mikmod.sourceforge.io/"
msys2_references=(
  "cpe: cpe:/a:igno_saitz:libmikmod"
  "cpe: cpe:/a:raphael_assenat:libmikmod"
)
license=("GPL" "LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
source=(https://downloads.sourceforge.net/mikmod/${_realname}-${pkgver}.tar.gz)
sha256sums=('9fc1799f7ea6a95c7c5882de98be85fc7d20ba0a4a6fcacae11c8c6b382bb207')

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

  export lt_cv_deplibs_check_method='pass_all'

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-sdl \
    --disable-xaudio2 \
    --disable-openal

  make
}

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

  # Install license
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.LIB "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.LESSER "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LESSER
  
  local PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i "${pkgdir}"${MINGW_PREFIX}/bin/libmikmod-config
}
