# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=qt6-tools
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
_qtver=6.1.2
pkgver=${_qtver/-/}
pkgrel=1
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='A cross-platform application and UI framework (Development Tools, QtHelp) (mingw-w64)'
depends=("${MINGW_PACKAGE_PREFIX}-qt6-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-clang"
             "${MINGW_PACKAGE_PREFIX}-clang-tools-extra"
             "${MINGW_PACKAGE_PREFIX}-polly"
             "${MINGW_PACKAGE_PREFIX}-qt6-declarative")
groups=(${MINGW_PACKAGE_PREFIX}-qt6)
_pkgfn="${_realname/6-/}-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/$_qtver/submodules/$_pkgfn.tar.xz")
sha256sums=('a0520097ac1f898381c4512fb55ba5aa187d8e4e06ed0dcd2cbe265cd037989b')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DQT_FEATURE_clang=ON \
    -DQT_FEATURE_clangcpp=ON \
    ../${_pkgfn}

  ninja
}

package() {
  DESTDIR=${pkgdir} cmake --install build-${MSYSTEM}

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $_pkgfn/LICENSE* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
