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

_realname=qt6-doc
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
_qtver=6.10.1
pkgver=${_qtver/-/}
pkgrel=1
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qt.io'
msys2_references=(
  "archlinux: qt6-doc"
  "cpe: cpe:/a:qt:qt"
)
license=(spdx:GFDL-1.3-no-invariants-only)
pkgdesc='A cross-platform application and UI framework (Documentation) (mingw-w64)'
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
             "${MINGW_PACKAGE_PREFIX}-qt6-shadertools"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools"
             "${MINGW_PACKAGE_PREFIX}-clang"
             "${MINGW_PACKAGE_PREFIX}-clang-tools-extra"
             "${MINGW_PACKAGE_PREFIX}-llvm"
             "${MINGW_PACKAGE_PREFIX}-vulkan-headers"
             "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-assimp"
             "${MINGW_PACKAGE_PREFIX}-ffmpeg"
             "${MINGW_PACKAGE_PREFIX}-jasper"
             "${MINGW_PACKAGE_PREFIX}-libmng"
             "${MINGW_PACKAGE_PREFIX}-libwebp"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-xmlstarlet")
groups=(${MINGW_PACKAGE_PREFIX}-qt6)
_pkgfn="qt-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/$_qtver/single/$_pkgfn.tar.xz"
        001-fix-qtdocs-helpers-cmake.patch)
sha256sums=('0ed08b079719394303cd2054b66b2dc0c5895ceeb88fb6131c18991c980bf00f'
            '1fdcc019403fabb65d862c7633b26379204459d854cef1c3f8ed89c6ced04e19')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd $srcdir/${_pkgfn}

  cd qtbase
  apply_patch_with_msg \
    001-fix-qtdocs-helpers-cmake.patch
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -Wno-dev \
    --log-level=STATUS \
    -GNinja \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DQT_HOST_PATH=${MINGW_PREFIX} \
    -DINSTALL_INCLUDEDIR=include/qt6 \
    -DINSTALL_ARCHDATADIR=share/qt6 \
    -DINSTALL_DATADIR=share/qt6 \
    -DINSTALL_MKSPECSDIR=share/qt6/mkspecs \
    -DINSTALL_DESCRIPTIONSDIR=share/qt6/modules \
    -DINSTALL_DOCDIR=share/qt6/doc \
    -DPython_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    -DPython3_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    -DFEATURE_gstreamer=OFF \
    -DBUILD_qtwebengine=OFF \
    ../${_pkgfn}

    ${MINGW_PREFIX}/bin/cmake --build . --target docs
}

package() {
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM} --target install_docs

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