# Maintainer: Martchus <martchus@gmx.net>

# All my PKGBUILDs are managed at https://github.com/Martchus/PKGBUILDs where
# you also find the URL of a binary repository.

# This file is created from PKGBUILD.sh.ep contained by the mentioned repository.
# Do not edit it manually! See README.md in the repository's root directory
# for more information.

# All patches are managed at https://github.com/Martchus/qtbase

pkgname=static-compat-qt6-base
_qtver=6.3.0
pkgver=${_qtver/-/}
pkgrel=3
arch=(x86_64)
url='https://www.qt.io'
license=(GPL3 LGPL3 FDL custom)
pkgdesc='A cross-platform application and UI framework'
depends=(shared-mime-info
         static-compat-brotli static-compat-dbus static-compat-double-conversion
         static-compat-fontconfig static-compat-libb2 static-compat-libglvnd
         static-compat-libice static-compat-libinput static-compat-libjpeg-turbo
         static-compat-libxdamage static-compat-libxkbcommon static-compat-libxmu
         static-compat-libxxf86vm static-compat-md4c static-compat-pcre2
         static-compat-sqlite static-compat-xcb-util-image static-compat-xcb-util-keysyms
         static-compat-xcb-util-renderutil static-compat-vulkan-headers
         static-compat-xcb-util-wm static-compat-xorgproto static-compat-xtrans)
makedepends=(static-compat-cmake xdg-utils ninja)
options=('!strip' '!buildflags' 'staticlibs' '!emptydirs')
_pkgfqn="qtbase-everywhere-src-${_qtver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/${_qtver}/submodules/${_pkgfqn}.tar.xz"
        '0001-Use-CMake-s-default-import-library-suffix.patch'
        '0002-Fix-finding-D-Bus.patch'
        '0003-Fix-using-static-PCRE2-and-DBus-1.patch'
        '0004-Fix-transitive-dependencies-of-static-libraries.patch'
        '0005-Fix-libjpeg-workaround-for-conflict-with-rpcndr.h.patch'
        '0006-Support-finding-static-MariaDB-client-library.patch'
        '0007-Allow-overriding-CMAKE_FIND_LIBRARY_SUFFIXES-to-pref.patch'
        '0008-Fix-crashes-in-rasterization-code-using-setjmp.patch'
        '0009-Find-fontconfig-via-pkg-config-for-correct-handling-.patch'
        '0010-Fix-dependency-of-xcb-image-on-xcb-util.patch'
        '0011-Allow-using-properties-of-PkgConfig-targets-for-glib.patch'
        '0012-Allow-using-properties-of-PkgConfig-targets-for-Wayl.patch')
sha256sums=('b865aae43357f792b3b0a162899d9bf6a1393a55c4e5e4ede5316b157b1a0f99'
            '3bd925d113a0ae1d3db5e6e001fb745ec0625d3212686aeaf9a0b121a48afc51'
            'f68fa8937d59579ef60d769f7ca0b308216ab360552aae6fd63e86d6140ff04f'
            'c0ce8ffcbc56e502604346d71b81d5fc8bdf625525b6330ba9ab64e10f2d7d5a'
            '4af1a6c2f75cd979ff9ed07c4e78da638668523a54370884978934ac1bbaffd7'
            '44dd65f1fac710cfa1e3fc36606026b8f2d5513ec346fc177231ab98a1cc06fa'
            '393bc8ad824198a9f94d46bb4553f1f4b644ff156da522d1be387518dcf69f8b'
            '0fc110150906fc6af37ad9549e92258923f0c6922dc3fca163fb200eb54df940'
            '5a88e320849fe4625687a8e3e2239f59635b02852d2e0c42f7f532a7cb459889'
            '85495ac317f403f8b406e5d85afd106cacc855190b351f6ee97a14598024c9d1'
            '179d7e3bf2c25a5f098a9fb5ed22f659dd094588a5a418989e11a2afb165428b'
            '80a5839cc2b60d3cd68e6abb365997c70770b8aa19fbbc8b80f82bac562e2c11'
            'ce926322642daaae84094801da24b10fb832d5b9ac46c3fc1d591d2a111bcc36')

prepare () {
  cd $_pkgfqn

  # apply patches; further descriptions can be found in patch files itself
  for patch in "$srcdir/"*.patch; do
    msg2 "Applying patch $patch"
    patch -p1 -i "$patch"
  done
}

build() {
  check_buildoption ccache y && ccache_args='
    -DCMAKE_C_COMPILER_LAUNCHER=ccache
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache'
  source static-compat-environment
  export PATH=$PWD:$PATH
  printf '#!/usr/bin/bash\nexec /usr/bin/pkg-config --static "$@"\n' > pkg-config
  chmod +x pkg-config
  static-compat-cmake -G Ninja -B build -S $_pkgfqn \
    $ccache_args \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
    -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 \
    -DINPUT_openssl=linked \
    -DQT_FEATURE_openssl_linked=ON \
    -DQT_FEATURE_static_runtime=ON \
    -DQT_FEATURE_system_sqlite=ON \
    -DQT_FEATURE_system_xcb_xinput=ON \
    -DQT_FEATURE_xcb=ON \
    -DQT_FEATURE_xcb_sm=ON \
    -DQT_FEATURE_icu=OFF \
    -DQT_FEATURE_kms=OFF \
    -DQT_FEATURE_eglfs=OFF \
    -DQT_FEATURE_gbm=OFF \
    -DQT_FEATURE_linuxfb=OFF \
    -DQT_FEATURE_gssapi=OFF \
    -DQT_FEATURE_fontconfig=ON \
    -DQT_FEATURE_dynamicgl=OFF \
    -DQT_FEATURE_opengl_dynamic=OFF \
    -DGLIB2_USE_PKG_CONFIG=ON \
    -DWAYLAND_USE_PKG_CONFIG=ON \
    -DCMAKE_DISABLE_FIND_PACKAGE_harfbuzz=TRUE \
    -DCMAKE_INSTALL_OLDINCLUDEDIR=$static_compat_prefix/include \
    -DGSSAPI_INCLUDE_DIRS=$static_compat_prefix/include \
    -DICU_INCLUDE_DIR=$static_compat_prefix/include \
    -DLibdrm_INCLUDE_DIR=$static_compat_prefix/include \
    -Dgbm_INCLUDE_DIR=$static_compat_prefix/include
  VERBOSE=1 cmake --build build
}

package() {
  source static-compat-environment
  DESTDIR="$pkgdir" cmake --install build

  install -Dm644 $_pkgfqn/LICENSE* -t "$pkgdir"/usr/share/licenses/$pkgname

  # Drop QMAKE_PRL_BUILD_DIR because reference the build dir
  find "$pkgdir" -type f -name '*.prl' \
    -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' {} \;

  rm -r "$pkgdir/$static_compat_prefix"/share/doc
}
