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

_realname=libmpcdec
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.1+r475
pkgrel=1
epoch=1
_rel=475
pkgdesc="MusePack commandline utilities and decoder library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://musepack.net/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-libreplaygain"
          "${MINGW_PACKAGE_PREFIX}-libcue")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=("http://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)
md5sums=('754d67be67f713e54baf70fcfdb2817e'
         '6da8b85474fe2fcf55d4a3cfa68ddd8e'
         '57f9c8f1858008ac14b0d3cf2b7cf2dc'
         'efbb0b619bf94450adb3bc8961c4258e'
         'b1e5b6f8cb3c5b77e4438971c7a20797'
         '661783cf9ad4fed435d1c055b74b680b'
         'ae4d2ef72dcd9a71fec6ad6d0d424c2a'
         'dc3e62894bf81dabd4451646b183a2e4')

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
  mv configure.in configure.ac
  autoreconf -fi
}

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  ../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-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
