# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgbase=qt6-doc
pkgname=(qt6-doc qt6-examples)
_pkgver=6.8.0
pkgver=6.8.0
# Account for Qt special naming of -rc1 tarballs
_pkgver=6.8.0
pkgrel=1
arch=(any)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
makedepends=(alsa-lib
             clang
             cmake
             cups
             freetds
             gperf
             gst-plugins-base-libs
             gtk3
             libpulse
             libxkbfile
             llvm
             mariadb-libs
             ninja
             nodejs
             openxr
             postgresql
             python
             python-html5lib
             unixodbc
             vulkan-headers)
groups=(qt6)
_pkgfn=qt-everywhere-src-$_pkgver
source=(https://download.qt.io/official_releases/qt/${_pkgver%.*}/${_pkgver}/single/$_pkgfn.tar.xz)
sha256sums=('70f1a87c6ecc6c108dec6e9389e564f8798bd48bec4c596f28d0564c1dbbc2c6')

build() {
  case "${CARCH}" in
    x86_64) ;;
    *) _cmake_options=(-DBUILD_qtwebengine=OFF) ;;
  esac

  cmake -B build -S $_pkgfn -G Ninja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DINSTALL_BINDIR=lib/qt6/bin \
    -DINSTALL_DOCDIR=share/doc/qt6 \
    -DINSTALL_ARCHDATADIR=lib/qt6 \
    -DINSTALL_DATADIR=share/qt6 \
    -DINSTALL_INCLUDEDIR=include/qt6 \
    -DINSTALL_MKSPECSDIR=lib/qt6/mkspecs \
    -DINSTALL_EXAMPLESDIR=share/doc/qt6/examples \
    -DQT_FEATURE_journald=ON \
    -DQT_FEATURE_openssl_linked=ON \
    -DCMAKE_MESSAGE_LOG_LEVEL=STATUS ${_cmake_options[@]}
  cmake --build build --target docs
}

package_qt6-doc() {
  pkgdesc='A cross-platform application and UI framework (Documentation)'
  DESTDIR="$pkgdir" cmake --build build --target install_docs

  install -Dm644 $_pkgfn/LICENSES/* -t "$pkgdir"/usr/share/licenses/$pkgbase
}

package_qt6-examples() {
  pkgdesc='Examples and demos from qt6 documentation'
  depends=(qt6-doc)

  _base="$pkgdir"/usr/share/doc/qt6/examples

  # The various example dirs have conflicting .pro files, but
  # QtCreator requires them to be in the same top-level directory.
  # Matching the Qt installer, only the qtbase project is kept.
  mkdir -p $_base
  cp ${_pkgfn}/qtbase/examples/examples.pro $_base

  _fdirs=$(find "$_pkgfn" -maxdepth 2 -type d -name examples)
  for _dir in $_fdirs; do
    rm -f $_dir/{examples.pro,CMakeLists.txt,README}
    cp -rn $_dir/* $_base
  done
}
