# Maintainer: Nazar Mishturak <nazar m x at gmail dot com>

_realname=globjects
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/cginternals/globjects'
pkgdesc="Cross-platform C++ wrapper for OpenGL API objects. (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glbinding"
         "${MINGW_PACKAGE_PREFIX}-glm")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
license=('MIT')
options=('strip' 'staticlibs' 'docs')

source=(${_realname}-${pkgver}.tar.gz::"https://github.com/cginternals/globjects/archive/v${pkgver}.tar.gz"
        'mingw-unix-layout.patch'
        'config-export-location.patch')
sha256sums=('68fa218c1478c09b555e44f2209a066b28be025312e0bab6e3a0b142a01ebbc6'
            '193434a6351f71926998813afa1830812f666eff6f749e6e640fa3f4ce0d6d28'
            'b1d176d7788d973fe19a13f1d6524b75058fa8cdd66b4a65c4811feef5978ac9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  # sed -i 's/$/\r/' "${srcdir}/mingw-unix-layout.patch"
  patch -p1 -i "${srcdir}/mingw-unix-layout.patch"
  patch -p1 -i "${srcdir}/config-export-location.patch"
}

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

  local BUILD_TYPE="Release"
  if check_option "debug" "y"; then
    BUILD_TYPE="Debug"
  fi

  # Build shared libs
  [[ -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_BUILD_TYPE=${BUILD_TYPE} \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_C_COMPILER=${MINGW_CHOST}-gcc \
    -DCMAKE_CXX_COMPILER=${MINGW_CHOST}-g++ \
    -DOPTION_BUILD_EXAMPLES=OFF \
    -DOPTION_BUILD_TESTS=OFF \
    -DSYSTEM_DIR_INSTALL=ON \
    -DBUILD_SHARED_LIBS=ON \
    -DOPTION_BUILD_DOCS=ON \
    ../${_realname}-${pkgver}
  make
}

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