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

_realname=taglib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.1
pkgrel=1
pkgdesc="A Library for reading and editing the meta-data of several popular audio formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://taglib.org/"
msys2_repository_url="https://github.com/taglib/taglib"
msys2_references=(
  "cpe: cpe:/a:scott_wheeler:taglib"
  "cpe: cpe:/a:taglib:taglib"
)
license=('spdx:LGPL-2.1-or-later' 'spdx:MPL-1.1')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cppunit"
             "${MINGW_PACKAGE_PREFIX}-utf8cpp"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=(https://taglib.github.io/releases/${_realname}-${pkgver}.tar.gz)
sha256sums=('3716d31f7c83cbf17b67c8cf44dd82b2a2f17e6780472287a16823e70305ddba')

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

build() {
  msg "Build shared version"
  mkdir -p "${srcdir}/build-shared-${MSYSTEM}"
  cd "${srcdir}/build-shared-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_BINDINGS=ON \
    -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
    ../${_realname}-${pkgver}

  cmake --build .

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_BINDINGS=ON \
    ../${_realname}-${pkgver}

  cmake --build .
}

check() {
  cd "${srcdir}/build-static-${MSYSTEM}"
  ctest . || warning "Tests failed"
}

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

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