% layout 'static-compat-qt6-module', has_binaries => 1;
\
_qtver=6.5.2
pkgver=${_qtver/-/}
pkgrel=1
arch=(x86_64)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='A cross-platform application and UI framework (Development Tools, QtHelp)'
depends=(<%== qt6deps qw(base) %> hicolor-icon-theme)
makedepends=(static-compat-cmake <%== qt6deps qw(declarative) %> static-compat-vulkan-headers llvm clang ninja)
optdepends=('clang: for qdoc and lupdate')
% \
% content_for before_build_config => begin
  # use llvm/clang from regular prefix (by linking into a custom prefix as we must avoid `-isystem /usr/include`)
  # note: Depending on Arch's normal LLVM/Clang is ok here as those tools are only used during build time and not
  #       distributed.
  [[ -e prefix ]] && rm -r prefix
  mkdir -p prefix/bin
  pacman -Ql llvm clang | grep /usr/bin | cut -d ' ' -f 2 | xargs ln -frs --target-directory=prefix/bin
  mkdir -p prefix/include
  ln -frs --target-directory=prefix/include /usr/include/{llvm,clang}{,-c}
  mkdir -p prefix/lib/cmake
  cp -r   --target-directory=prefix/lib/cmake /usr/lib/cmake/llvm
  ln -frs --target-directory=prefix/lib/cmake /usr/lib/cmake/clang
  ln -frs --target-directory=prefix/lib /usr/lib/*LLVM*
  ln -frs --target-directory=prefix/lib /usr/lib/libLTO*
  ln -frs --target-directory=prefix/lib /usr/lib/libRemarks*
  ln -frs --target-directory=prefix/lib /usr/lib/libclang*
  ln -frs --target-directory=prefix/lib /usr/lib/clang
  # ensure targets linking against system LLVM are also linked against system libc/libdl/libm
  echo 'set_target_properties(LLVM PROPERTIES
  INTERFACE_LINK_LIBRARIES "/usr/lib/libpthread.so.0;/usr/lib/libm.so.6;/usr/lib/libmvec.so.1;/usr/lib/libdl.so.2;/usr/lib/libc.so.6;/usr/lib/libc_nonshared.a;/usr/lib/ld-linux-x86-64.so.2")' \\
    >> prefix/lib/cmake/llvm/LLVMExports-release.cmake
% end
% \
% content_for additional_cmake_args => begin
 \\
    -DLLVM_DIR="$PWD/prefix/lib/cmake/llvm" \\
    -DClang_DIR="$PWD/prefix/lib/cmake/clang"
  # ensure system libc/libdl/libm is present on the linker-line before other libs
  sed -i -E 's|(LINK_LIBRARIES = )(.*libLLVM-15.so.*)|\1/usr/lib/libpthread.so.0 /usr/lib/libm.so.6 /usr/lib/libmvec.so.1 /usr/lib/libdl.so.2 /usr/lib/libc.so.6 \2|g' build/build.ninja\
% end
