# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Sui Libin <bygreencn@gmail.com>

_realname=libxlsxwriter
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.0
pkgrel=1
pkgdesc="A C library for creating Excel XLSX files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/jmcnamara/libxlsxwriter"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" 
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-zlib")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         #"${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/jmcnamara/libxlsxwriter/archive/RELEASE_${pkgver}.tar.gz")
sha256sums=('8b353379333c323d14a9d265cd2491d3a6c0032c8d6ec2141f10b82ab66a087c')

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

build() {
  [[ -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.exe -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTS=ON \
    -DBUILD_EXAMPLES=OFF \
    -DUSE_SYSTEM_MINIZIP=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    ../${_realname}-RELEASE_${pkgver}
  make
}

check(){
  cd ${srcdir}/build-${MINGW_CHOST}
  make test
}

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