# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=musepack
pkgname=('musepack-tools' 'libmpcdec')
_revision=475
pkgver=0.1+r$_revision
pkgrel=6
epoch=1
pkgdesc='MusePack commandline utilities and decoder library'
arch=('x86_64')
url='https://musepack.net/'
license=('BSD-3-Clause AND LGPL-2.1-or-later AND GPL-2.0-or-later')
depends=('glibc' 'libcue' 'libreplaygain')
source=("https://files.musepack.net/source/musepack_src_r$_revision.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'
	'musepack-tools-495-incompatible-pointers.patch')
b2sums=('601762738199bd67278d934d927c35d6ba1d286be9fd57ebf2e89dca271f563e85cf023f8860bfd30b501039bba5fd68eaf2d65dce65d0dcf5ce6d75a6e692aa'
        '940b71df9e4d582a0da733174048168aacd1f80c69d9cf2f163545cf1cdd83165eca5c18597c4f271c52f55b8085f69079a9df4e3fee3875d2853062afbbb1cd'
        '65a3b3c2fd6e265d88075834f8d479fc40c0bf11d674c4d2ffce12b595460327bcf33931ae7c16a5b78273de10e962144764e950f2cb0ae74ece01b892526456'
        '7a97fc91ba99f21449cdffcb6137aa253f71ec71e3a80b70df69b7876a28751b834df0e1a5a502d44fec13a5138ae4f425951b28242086821f3992da338c9ecf'
        'a5c96c5a80d76cbbb25a5647c6d754d82203936949f2720772776267f6752811f2c511e8df59a58570bba9ffe3b9482b0294eeed4364e2a4602a15d142759add'
        'e96e7928ad05bc0713ede3fbc8b5053cf1a456067faa481fa17f5156d61f6c1052b47ff27fe0e7e70d4e40fd62fae9cd0c57c5e28b149501a37dc323031a8bb5'
        '5204b8b9596ef5663f7678cdd533a227df9722f3d66f66ea9fe151a76de6070e3801f51be657588cb14839239d6d2ed8c5a5f7e80a61f79a1eda22b72026658a'
        '366e7a668d9c47be947b3ae785db7e0804d3d3537aa5df4c833386e8b04fc98f3c4dc1f32a0beaabf7721deae853ad6bce9acd7bae1ad1621dae1bb908a200c2'
        '72c0ed7dd049ada3169c59be3904cbb0c3a4d8ce68fa4f875a5951e8639a0d39c04b17eca3425da5a149d627f0a248aee9bb4dfae60ff4e98381b6a4c483f294')

prepare() {
  cd musepack_src_r$_revision
  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 ../musepack-tools-495-incompatible-pointers.patch

  autoreconf -fi
}

build() {
  cd musepack_src_r$_revision
  ./configure --prefix=/usr --enable-mpcchap
  make
}

package_libmpcdec() {
  pkgdesc='MusePack decoding library'
  license=('BSD-3-Clause')
  depends=('glibc')

  cd musepack_src_r$_revision
  make -C include DESTDIR="$pkgdir" install
  make -C libmpcdec DESTDIR="$pkgdir" install
  install -Dm644 libmpcdec/COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

package_musepack-tools() {
  pkgdesc='MusePack commandline tools'
  depends+=("libmpcdec>=1:0.1+r$_revision")
  options=('!emptydirs')

  cd musepack_src_r$_revision
  make DESTDIR="$pkgdir" install
  make -C libmpcdec DESTDIR="$pkgdir" uninstall
  make -C include DESTDIR="$pkgdir" uninstall
  install -Dm644 libmpcdec/COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}
