# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=flac
pkgname=('flac' 'flac-doc')
pkgver=1.4.3
pkgrel=2
pkgdesc='Free Lossless Audio Codec'
url='https://xiph.org/flac/'
arch=('x86_64')
license=('BSD' 'GPL')
depends=('gcc-libs' 'libogg')
makedepends=('nasm' 'cmake' 'ninja' 'doxygen')
source=(https://github.com/xiph/flac/releases/download/${pkgver}/flac-${pkgver}.tar.xz)
b2sums=('c4f441aeaa0493433347b8a110ca01865fd40d5b21150174372af2fee4fa5c3397a67add31138e92999eab9d9abe6c46a5ac29e13cbac60093fbff6d7a672ad3')

# https://github.com/xiph/flac/releases
sha256sums=('6c58e69cd22348f441b861092b825e591d0b822e106de6eb0ee4d05d27205b70')

prepare() {
  cd flac-${pkgver}

  # Shorten tests
  sed -i 's/FLAC__TEST_LEVEL=1/FLAC__TEST_LEVEL=0/' test/CMakeLists.txt
}

build() {
  cmake -S flac-${pkgver} -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=ON \
    -DINSTALL_MANPAGES=ON \
    -DWITH_STACK_PROTECTOR=OFF \
    -DNDEBUG=ON
  cmake --build build

  # Build docs and place them where install expects them
  cmake --build build --target FLAC-doxygen
  mv build/doc/doxytmp/html flac-${pkgver}/doc/api
}

check() {
  cd build
  ctest --output-on-failure --stop-on-failure -j1
}

package_flac() {
  provides=('libFLAC.so' 'libFLAC++.so')

  DESTDIR="${pkgdir}" cmake --install build

  install -Dm 644 flac-${pkgver}/src/*/*.m4 -t "${pkgdir}/usr/share/aclocal"

  mkdir -p doc/usr/share
  mv {"${pkgdir}",doc}/usr/share/doc

  install -Dm 644 flac-${pkgver}/COPYING.Xiph -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

package_flac-doc() {
  pkgdesc+=' documentation'
  depends=()

  mv doc/* "$pkgdir"

  install -Dm 644 flac-${pkgver}/COPYING.Xiph -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim:set sw=2 sts=-1 et:
