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

_realname=libsidplayfp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.15.2
pkgrel=1
pkgdesc="A library to play Commodore 64 music (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/libsidplayfp/libsidplayfp"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libftdi"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread"
         "${MINGW_PACKAGE_PREFIX}-omp")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/libsidplayfp/libsidplayfp/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('7c6ab283fda53d34973fa266fc3809e16964dd8ccb7edcc11516ef5e3f66b3cd')

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

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

  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    LDFLAGS+=" -lomp -lpthread"
  fi

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

  make
}

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

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

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/README "${pkgdir}"${MINGW_PREFIX}/share/doc/${_realname}/README
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
