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

_realname=liblastfm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.0
pkgrel=1
pkgdesc="A Qt C++ library for the Last.fm webservices https://www.last.fm"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('Boost')
url="https://www.last.fm/download"
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
        "${MINGW_PACKAGE_PREFIX}-fftw"
        "${MINGW_PACKAGE_PREFIX}-libsamplerate")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
options=(!strip staticlibs !buildflags)
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lastfm/liblastfm/archive/${pkgver}.tar.gz"
        versioned-dlls-mingw.patch)
sha256sums=('f61f0daa384e081a8f2bd2f7a2148babff22696e5b72ecdac86940a10100b1c8'
            '32e77ca2e80ce08cb4a8c9d11daf4618ec87177fa8e986737d720eb4feea7485')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}
    patch -p0 -i ${srcdir}/versioned-dlls-mingw.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DBUILD_TESTS=False \
    -Wno-dev \
    ${srcdir}/${_realname}-${pkgver}

  make ${MAKEFLAGS} # VERBOSE=1
}

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