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

_realname=libmpcdec
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.1+r475
pkgrel=2
epoch=1
_rel=475
pkgdesc="MusePack commandline utilities and decoder library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://musepack.net/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-libreplaygain"
          "${MINGW_PACKAGE_PREFIX}-libcue")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://files.musepack.net/source/musepack_src_r${_rel}.tar.gz"
         01_am-maintainer-mode.patch
         02_link-libm.patch
         03_mpcchap.patch
         04_link-order.patch
         05_visibility.patch
         1001_missing_extern_kw.patch
         add_subdir-objects.patch
         06_do-not-use-x87-asm-on-arm.patch)
sha256sums=('a4b1742f997f83e1056142d556a8c20845ba764b70365ff9ccf2e3f81c427b2b'
            '76b5b7295f5e0be5de7edeb2ef481fe912cef349be5bd26f8b0870572a1ed5ee'
            'cf7ded3474ecefbe877a672539996b99dd6d62be546b74b70c4d56a7b943952d'
            '77b19a6424a9b5b8a06cd637463bcea6d57867ff4f91353694f39acc550270d9'
            'b184df85c164cb6f37e077b5511bee994e767f25f641d5a44ad3877db0e7eba1'
            'db78faeb4944ab443c89a1da058693e419a8eef1ca4859550afcc6232ec407fb'
            '0315d9d02c8b56f7f2a86b15201d237fd2564e599a99e1876079aecfab65b78a'
            '88e2d7df269c8f19daccb98bd9d1a2bdc9002c7ea03ca093e2dc68b0fb04e636'
            'cfc63d58b20310fef638cb4dd539c1a9d667c882be6f1d8fda2fc51bd587aaf4')

prepare() {
  cd musepack_src_r${_rel}
  patch -Np1 -i ../01_am-maintainer-mode.patch
  patch -Np1 -i ../02_link-libm.patch
  patch -Np1 -i ../03_mpcchap.patch
  patch -Np1 -i ../04_link-order.patch
  patch -Np1 -i ../05_visibility.patch
  patch -Np1 -i ../1001_missing_extern_kw.patch
  patch -Np1 -i ../add_subdir-objects.patch
  patch -Np1 -i ../06_do-not-use-x87-asm-on-arm.patch
  mv configure.in configure.ac
  autoreconf -fi
}

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

  ../musepack_src_r${_rel}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --enable-mpcchap

  make
}

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