# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=libsbml
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.19.0
pkgrel=2
pkgdesc="A file format for exchanging computational models in systems biology (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=("custom")
url="http://sbml.org/Software/libSBML/"
source=("http://sourceforge.net/projects/sbml/files/libsbml/${pkgver}/stable/libSBML-${pkgver}-core-plus-packages-src.tar.gz"
        02-install-layout.patch)
sha256sums=('a7f0e18be78ff0e064e4cdb1cd86634d08bc33be5250db4a1878bd81eeb8b547'
            'c007b7fec2d95a76600aa34eb62aec9bc44bdbeb228818d6d3f3e789a2cd8a9f')
depends=("${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-swig")
options=('staticlibs' 'strip')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}-Source"
  patch -p1 -i ${srcdir}/02-install-layout.patch
}

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 \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_SWIG=OFF \
    -DWITH_CPP_NAMESPACE=ON \
    -DLIBSBML_DEPENDENCY_DIR=${MINGW_PREFIX} \
    -DLIBXML_INCLUDE_DIR="${MINGW_PREFIX}/include/libxml2" \
    -DWITH_LIBXML=ON \
    -DWITH_EXPAT=OFF \
    -DWITH_BZIP2=ON \
    -DWITH_ZLIB=ON \
    -DWITH_PYTHON=ON \
    -DENABLE_LAYOUT=ON \
    -DENABLE_RENDER=ON \
    -DENABLE_QUAL=ON \
    -DENABLE_MULTI=ON \
    -DENABLE_COMP=ON \
    -DENABLE_FBC=ON \
    -DENABLE_GROUPS=ON \
    ../${_realname}-${pkgver}-Source

  make
}

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