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

_realname=vala
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.52.4
pkgrel=1
pkgdesc="Compiler for the GObject type system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://wiki.gnome.org/Projects/Vala"
license=("LGPL")
makedepends=("help2man"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
              $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || \
              echo "${MINGW_PACKAGE_PREFIX}-vala")) # Remove this workaround after vala available
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
          $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] || \
            echo "${MINGW_PACKAGE_PREFIX}-graphviz")) # Remove this workaround afer graphviz available
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-change-pkg-config-invocations.mingw.patch
        002-use_time_s_functions_on_windows.mingw.patch)
sha256sums=('ecde520e5160e659ee699f8b1cdc96065edbd44bbd08eb48ef5f2506751fdf31'
            'c588a3a69097aae30ada1d543001d5029865b1dd1f46132d9e60d12e1833b325'
            '1309ae50867b81ea5d170487b36443a41c8dfee202213198c980a133300d6f9a')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-change-pkg-config-invocations.mingw.patch
  patch -p1 -i ${srcdir}/002-use_time_s_functions_on_windows.mingw.patch
  autoreconf -ivf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    $([[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]] && \
      echo "--disable-valadoc" || true) # Remove this workaround afer graphviz available
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install
  
  # Move libvalaccodegen.dll to correct directory
  mv "${pkgdir}${MINGW_PREFIX}"/lib/bin/libvalaccodegen.dll "${pkgdir}${MINGW_PREFIX}"/bin/libvalaccodegen.dll
  rm -rf "${pkgdir}${MINGW_PREFIX}"/lib/bin

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

