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

_realname=taglib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.12
pkgrel=1
pkgdesc="A Library for reading and editing the meta-data of several popular audio formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://taglib.github.com"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=(https://taglib.github.io/releases/${_realname}-${pkgver}.tar.gz
        fix-finding-cppunit.patch)
sha256sums=('7fccd07669a523b07a15bd24c8da1bbb92206cb19e9366c3692af3d79253b703'
            '460e2dd83e6233145e4980a4c63a400e9e8297980e3cfae910dadefa2475e7d0')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/fix-finding-cppunit.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_BINDINGS=ON \
    -DWITH_ASF=ON \
    -DWITH_MP4=ON \
    ../${_realname}-${pkgver}

  make

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DBUILD_TESTS=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_BINDINGS=ON \
    -DWITH_ASF=ON \
    -DWITH_MP4=ON \
    ../${_realname}-${pkgver}

  make
}

check() {
    cd "${srcdir}/build-static-${MINGW_CHOST}"

    make check
}

package() {
  cd "${srcdir}/build-static-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
