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

_realname=libmikmod
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.11.1
pkgrel=1
pkgdesc="A portable sound library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://mikmod.sourceforge.io/"
license=("GPL" "LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             #"${MINGW_PACKAGE_PREFIX}-SDL"
             #"${MINGW_PACKAGE_PREFIX}-SDL2"
             )
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-openal")
options=('strip' 'staticlibs')
source=(https://downloads.sourceforge.net/mikmod/${_realname}-${pkgver}.tar.gz)
sha256sums=('ad9d64dfc8f83684876419ea7cd4ff4a41d8bcd8c23ef37ecb3a200a16b46d19')

build() {
  export lt_cv_deplibs_check_method='pass_all'
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-sdl \
    --disable-sdl2 \
    --enable-openal

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  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
}
