# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=wt
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.5.0
pkgrel=1
pkgdesc="A C++ library and application server for developing and deploying web applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.webtoolkit.eu/"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
#         "${MINGW_PACKAGE_PREFIX}-mesa"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-libharu"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-graphicsmagick"
         "${MINGW_PACKAGE_PREFIX}-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-asciidoc"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-pygments"
#             "${MINGW_PACKAGE_PREFIX}-mesa"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-sqlite3")
optdepends=("${MINGW_PACKAGE_PREFIX}-openssl: for SSL support in built-in webserver"
#            "${MINGW_PACKAGE_PREFIX}-fcgi: for FastCGI support"
#            "${MINGW_PACKAGE_PREFIX}-mysql++: for the hangman example"
            "${MINGW_PACKAGE_PREFIX}-postgresql: for PostgreSQL Dbo support"
            "${MINGW_PACKAGE_PREFIX}-libmariadbclient: for MySQL Dbo support"
            "${MINGW_PACKAGE_PREFIX}-sqlite3: for Sqlite Dbo support")
#backup=("${MINGW_PREFIX}/etc/wt/wt_config.xml")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/emweb/wt/archive/${pkgver}.tar.gz"
         '001-wt-4.4.0-fix-find-gm.patch'
         '002-wt-4.4.0-skip-some-examples.patch'
         '003-wt-4.4.0-disable-win32-configdir.patch'
         '004-wt-4.4.0-disable-win32-examples-bat.patch')
sha512sums=('4cb8d822c4be4f120c1718410d1f493c9a81f8356eaa1b8dd5aea5095b7258bb950706c7871a2be89b1068ad34fe4153c02fb5ca6d5cc5870cb34107bfc5fcc9'
            'a585ca7c80ec4b05e88622fe98f97c3ee249dbe8a93bca611656d6a07fb36734c27691ebf5578b8adfa71b128466efc7f43513e265feab2b1942e80185555deb'
            '1c03f218678286007b60b041381406187c81f6169e27777312ee92db5537847c975bec4739a01deffbdac7012e5fee764e3636a06fb68870aaa925849ea12568'
            '82a0129dc7dfb103e61ae268572f5e4630fd2469f6a40778290dee0f3db65e50887b91ed9d7db8a6e50d6e162b3ed7ee286492952cd54d2518d344267bddcce7'
            '6ee021f3f9fa207269bee69e06050ff93574e623c4d18521c876e175ad6bd122ff69863d34e89c96d2c07ed59907af3d2dfbcbb7c4c675157cf5a305b5d3e9b6')

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

  patch -p1 -i "${srcdir}/001-wt-4.4.0-fix-find-gm.patch"
  patch -p1 -i "${srcdir}/002-wt-4.4.0-skip-some-examples.patch"
  patch -p1 -i "${srcdir}/003-wt-4.4.0-disable-win32-configdir.patch"
  patch -p1 -i "${srcdir}/004-wt-4.4.0-disable-win32-examples-bat.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 \
    -DCONNECTOR_HTTP=ON \
    -DWT_WRASTERIMAGE_IMPLEMENTATION=GraphicsMagick \
    -DGM_PREFIX=${MINGW_PREFIX} \
    -DWEBUSER=http \
    -DWEBGROUP=http \
    -DUSE_SYSTEM_SQLITE3=ON \
    -DBUILD_EXAMPLES=ON \
    -DINSTALL_EXAMPLES=ON \
    -DINSTALL_DOCUMENTATION=ON \
    ../${_realname}-${pkgver}

  make
}

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

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
