# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=chromaprint
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=1
pkgdesc="Library that implements a custom algorithm for extracting fingerprints from any audio source (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://acoustid.org/chromaprint"
license=("LGPL")
msys2_references=(
  'anitya: 286'
  'archlinux: chromaprint'
  'gentoo: media-libs/chromaprint'
)
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/acoustid/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9d33482e56a1389a37a0d6742c376139fa43e3b8a63d29003222b93db2cb40da')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

}

build() {
  _common_opts=(
    -G"Ninja"
    -DCMAKE_BUILD_TYPE=Release \
    -DFFT_LIB=kissfft \
    -DAUDIO_PROCESSOR_LIB="dummy" \
    -DBUILD_TESTS=off \
    -DBUILD_TOOLS=off \
  )

  msg "Build static version"
  mkdir -p "${srcdir}/static-${MSYSTEM}" && cd "${srcdir}/static-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=off \
    "${_common_opts[@]}" \
    ../${_realname}-${pkgver}

  cmake --build ./

  msg "Build shared version"
  mkdir -p "${srcdir}/shared-${MSYSTEM}" && cd "${srcdir}/shared-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=on \
    "${_common_opts[@]}" \
    ../${_realname}-${pkgver}

  cmake --build ./
}

package() {
  # static
  cd "${srcdir}/static-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install ./

  # shared
  cd "${srcdir}/shared-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install ./
}
