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

_realname=collada-dom
pkgbase=mingw-w64-${_realname}-svn
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
_base_ver=2.4.1
pkgver=2.4.1.r889
pkgrel=7
pkgdesc="API that provides a C++ object representation of a COLLADA XML instance document (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://sourceforge.net/projects/collada-dom/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-cmake" "subversion")
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-zlib")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('staticlibs' 'strip' 'buildflags')
source=("${_realname}"::"svn+https://svn.code.sf.net/p/collada-dom/code/trunk#revision=889"
        001-collada-2.4.0-mingw-w64-fix.patch
        002-fix-pkg-config.patch
        003-fix-warnings.patch)
sha256sums=('SKIP'
            'a415b4615c46317683d4eade3c650e39fcfcfb2f2484293ba8a1e4173a53f29a'
            '543376c86d137c45c41f1c659f4b86ff9f73824ece606a20a44915ae9fe18ecb'
            '1d9548f849e17a60fa6de60c1b2872ca5e80ea6c8695cb6fae47418b48a09e46')

pkgver() {
  cd "${srcdir}/${_realname}"
  local ver="$(svnversion)"
  printf "%s.r%s" "${_base_ver}" "${ver//[[:alpha:]]}"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -p1 -i ${srcdir}/001-collada-2.4.0-mingw-w64-fix.patch
  patch -p1 -i ${srcdir}/002-fix-pkg-config.patch
  patch -p1 -i ${srcdir}/003-fix-warnings.patch

  #sed -i "s|#include <unzip.h>|#include <minizip/unzip.h>|g" dom/include/dae/daeZAEUncompressHandler.h
}

build() {
  mkdir -p build-${MINGW_CHOST}

  CPPFLAGS+="  -I ${MINGW_PREFIX}/include/minizip"

  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DOPT_COLLADA14=ON \
    -DOPT_COLLADA15=ON \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DBOOST_ROOT=${MINGW_PREFIX} \
    ../${_realname}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} -j1 install
  #cp dom/src/1.4/*.a ${pkgdir}${MINGW_PREFIX}/lib/
  #mv ${pkgdir}${MINGW_PREFIX}/lib/cmake/collada_dom-2.4/collada_dom-config.cmake ${pkgdir}${MINGW_PREFIX}/lib/cmake/collada_dom-2.4/collada_dom14-config.cmake

  #cd "${srcdir}/build15"
  #make -j1 install
  #cp dom/src/1.5/*.a ${pkgdir}${MINGW_PREFIX}/lib/
  #mv ${pkgdir}${MINGW_PREFIX}/lib/cmake/collada_dom-2.4/collada_dom-config.cmake ${pkgdir}${MINGW_PREFIX}/lib/cmake/collada_dom-2.4/collada_dom15-config.cmake

  mkdir -p ${pkgdir}${MINGW_PREFIX}/bin
  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  #rm ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/collada-dom.pc
}
