# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>

pkgname=qt6-tools
_pkgver=6.10.0
pkgver=${_pkgver/-/}
pkgrel=2
arch=(x86_64 aarch64)
url='https://www.qt.io'
license=(GPL-3.0-only
         LGPL-3.0-only
         LicenseRef-Qt-Commercial
         Qt-GPL-exception-1.0)
pkgdesc='A cross-platform application and UI framework (Development Tools, QtHelp)'
depends=(gcc-libs
         glibc
         qt6-base
         zstd)
makedepends=(clang
             cmake
             git
             litehtml
             llvm
             ninja
             qt6-declarative
             vulkan-headers)
optdepends=('clang: for qdoc and lupdate'
            'litehtml: for assistant'
            'qt6-declarative: for qdistancefieldgenerator, qdoc and lupdate')
groups=(qt6)
_pkgfn=${pkgname/6-/}
source=(git+https://github.com/qt/$_pkgfn#tag=v$_pkgver
        git+https://invent.kde.org/qt/playground/qlitehtml)
sha256sums=('b800f879b6dec5099e266bf7366bc736dc67e67e6727daf5a98725980b9aab06'
            'SKIP')

prepare() {
  cd $_pkgfn
  git submodule init
  git submodule set-url src/assistant/qlitehtml "$srcdir"/qlitehtml
  git -c protocol.file.allow=always submodule update
}

build() {
  cmake -B build -S $_pkgfn -G Ninja \
    -DQT_INSTALL_XDG_DESKTOP_ENTRIES=ON \
    -DQLITEHTML_USE_SYSTEM_LITEHTML=ON \
    -DCMAKE_MESSAGE_LOG_LEVEL=STATUS
  cmake --build build
}

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

# Install symlinks for user-facing tools
  cd "$pkgdir"
  mkdir usr/bin
  while read _line; do
    ln -s $_line
  done < "$srcdir"/build/user_facing_tool_links.txt

  install -d "$pkgdir"/usr/share/licenses
  ln -s /usr/share/licenses/qt6-base "$pkgdir"/usr/share/licenses/$pkgname
}
