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

_realname=quazip
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.1
pkgrel=1
pkgdesc="C++ wrapper for the Gilles Vollant's ZIP/UNZIP C package (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://sourceforge.net/projects/quazip/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("dos2unix"
            "${MINGW_PACKAGE_PREFIX}-cmake"
            "${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/stachenov/${_realname}/archive/v${pkgver}.tar.gz"
        mingw-build.patch)
sha256sums=('5d36b745cb94da440432690050e6db45b99b477cfe9bc3b82fd1a9d36fff95f5'
            '9a486f86cbf7a2c1acefe8f9ae9e3ad9d55ffad3705833180ffc44cd0d8d8deb')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/mingw-build.patch
}

build() {
  msg "Build shared version..."
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${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=Release \
    -DBUILD_WITH_QT4=OFF \
    ../${_realname}-${pkgver}
  make
}

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