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

_realname=opencsg
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.1
pkgrel=1
pkgdesc="Library for image-based CSG rendering using OpenGL (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=("GPL2")
url="http://www.opencsg.org"
depends=("${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         # "${MINGW_PACKAGE_PREFIX}-freeglut" # need for building example
         )
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip !buildflags)
source=("http://www.opencsg.org/OpenCSG-${pkgver}.tar.gz"
        01-makefile-mingw.patch
        02-qmake-mingw.patch)
sha256sums=('7adb7ec7650d803d9cb54d06572fb5ba5aca8f23e6ccb75b73c17756a9ab46e3'
            '29e504d0fe2d8576202f92149688fc9eeecafee135463943aca13b786e2ac4e5'
            '87be0437e05a346e0bc082ad405c9ec9081f51bba03df8ec6c65ade7e934f99f')

prepare() {
  cd "${srcdir}/OpenCSG-${pkgver}"
  patch -p1 -i "${srcdir}"/01-makefile-mingw.patch
  patch -p1 -i "${srcdir}"/02-qmake-mingw.patch
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -r "${srcdir}/OpenCSG-${pkgver}" "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  #rm -f example/Makefile src/Makefile
  #${MINGW_PREFIX}/bin/qmake -recursive opencsg.pro
  #make

  make CC=${CC} CXX=${CXX} LINK=${MINGW_PREFIX}/bin/c++.exe all staticlib -C src
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make LINK=${MINGW_PREFIX}/bin/c++.exe prefix=${MINGW_PREFIX} INSTALL_ROOT="${pkgdir}" install -C src
  #install -D lib/libopencsg.so.$pkgver "${pkgdir}${MINGW_PREFIX}/lib/libopencsg.so.$pkgver"
  #install -D include/opencsg.h "${pkgdir}${MINGW_PREFIX}/include/opencsg.h"
}
