# Maintainer: AlexWMF <alexxwmf@gmail.com>

_realname=libvmime
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r1183.fe5492ce
pkgrel=2
pkgdesc="An open source solution for working with MIME messages and Internet messaging services like IMAP, POP or SMTP (mingw-w64)"
url="https://www.vmime.org/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('GPL3')
options=('strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "git")
depends=("${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         #"${MINGW_PACKAGE_PREFIX}-openssl"
        )
source=("${_realname}"::"git+https://github.com/kisli/vmime.git"
        cmake_mlang.patch
        libvmime-versioning.patch
        cmake-files-destination.patch)
sha256sums=('SKIP'
            'fb2a968510b950f16840b3a81ca90f7c418683c056194fdf7fcedb254dd65501'
            '9401422619e7c48db31c82215ffd0e2a5587dda0df348575a5d5cd46b58e6434'
            '5a2836b0ee6524514c83500b675ebaa06b3b29a66d51b8b6f8da6b6da2d4dd34')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${_realname}"
  patch -p0 -i ${srcdir}/cmake_mlang.patch
  patch -p1 -i ${srcdir}/libvmime-versioning.patch
  patch -p1 -i ${srcdir}/cmake-files-destination.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DVMIME_HAVE_MESSAGING_PROTO_SENDMAIL=OFF \
    -DVMIME_BUILD_SAMPLES=OFF \
    -DVMIME_TLS_SUPPORT_LIB=gnutls \
    ../${_realname}

  make
}

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