NAME="qt5"
DESC="Cross-platform application framework that is widely used for developing application software with a graphical user interface"
VERSION="5.15.10"
FILES=(
  "https://download.qt.io/archive/qt/${VERSION%.*}/$VERSION/single/qt-everywhere-opensource-src-$VERSION.tar.xz"
  "https://www.linuxfromscratch.org/patches/blfs/12.0/qt-everywhere-opensource-src-$VERSION-kf5-1.patch"
  "assistant-qt5.desktop"
  "designer-qt5.desktop"
  "linguist-qt5.desktop"
  "qdbusviewer-qt5.desktop"
)
HASHES=(
  "fb41d86bea6bc4886030a5092c910b09"
  "39848ffa81817b251db5f122b6942362174274e670ce51443878d4012c7ebf53"
  "162c1b77fa48db234f483148337c57f3850d9749cfdb8660054a8c81a52c1f4b"
  "945d209667d4bdb01ddb9d5ee4968dee55e4386f0927246995de8bda93b0c274"
  "27b1237daf07ac00b9035f607744c42f5824455f20f94e3f1ac9eed64508542c"
  "5ce3d8b7550bdd1423c786b6ef543564aacaec61a62fdee1601bea249ff794cb"
)
DEPENDS=(
  "xorg" "fontconfig" "libinput" "double-conversion"
  "libjpeg-turbo" "libxi" "libxkbcommon"
  "libxrender" "mesa" "shared-mime-info"
  "sqlite" "xcb-util-image" "xcb-util-keysyms"
  "xcb-util-renderutil" "xcb-util-wm" "harfbuzz"
)

PACKAGE() {
  tar xf qt-everywhere-opensource-src-$VERSION.tar.xz
  cd qt-everywhere-src-$VERSION 

  patch -Np1 -i ../qt-everywhere-opensource-src-$VERSION-kf5-1.patch
  mkdir -pv qtbase/.git
  sed -e "/pragma once/a#include <cstdint>"                                    \
    -i qtlocation/src/3rdparty/mapbox-gl-native/include/mbgl/util/geometry.hpp \
       qtlocation/src/3rdparty/mapbox-gl-native/include/mbgl/util/string.hpp   \
       qtlocation/src/3rdparty/mapbox-gl-native/src/mbgl/gl/stencil_mode.hpp

  ./configure -prefix /usr                              \
            -sysconfdir /etc/xdg                        \
            -confirm-license                            \
            -opensource                                 \
            -dbus-linked                                \
            -openssl-linked                             \
            -system-harfbuzz                            \
            -system-sqlite                              \
            -nomake examples                            \
            -no-rpath                                   \
            -journald                                   \
            -skip qtwebengine                           \
            -archdatadir    /usr/lib/qt5                \
            -bindir         /usr/bin                    \
            -plugindir      /usr/lib/qt5/plugins        \
            -importdir      /usr/lib/qt5/imports        \
            -headerdir      /usr/include/qt5            \
            -datadir        /usr/share/qt5              \
            -docdir         /usr/share/doc/qt5          \
            -translationdir /usr/share/qt5/translations \
            -examplesdir    /usr/share/doc/qt5/examples
  make && echo "Make completed, running the install"
  make INSTALL_ROOT="$ROOTDIR" install
  find "$ROOTDIR/usr/lib" -name \*.prl \
   -exec sed -i -e '/^QMAKE_PRL_BUILD_DIR/d' {} \;
  
  install -v -dm755 "$ROOTDIR/usr/share/pixmaps/"
  install -v -Dm644 qttools/src/assistant/assistant/images/assistant-128.png \
                  "$ROOTDIR/usr/share/pixmaps/assistant-qt5.png"
  install -v -Dm644 qttools/src/designer/src/designer/images/designer.png \
                  "$ROOTDIR/usr/share/pixmaps/designer-qt5.png" 
  install -v -Dm644 qttools/src/linguist/linguist/images/icons/linguist-128-32.png \
                  "$ROOTDIR/usr/share/pixmaps/linguist-qt5.png"
  install -v -Dm644 qttools/src/qdbus/qdbusviewer/images/qdbusviewer-128.png \
                  "$ROOTDIR/usr/share/pixmaps/qdbusviewer-qt5.png"

  install -dm755 "$ROOTDIR/usr/share/applications"
  cp "$ROOTDIR/assistant-qt5.desktop"   "$ROOTDIR/usr/share/applications/"
  cp "$ROOTDIR/designer-qt5.desktop"    "$ROOTDIR/usr/share/applications/"
  cp "$ROOTDIR/linguist-qt5.desktop"    "$ROOTDIR/usr/share/applications/"
  cp "$ROOTDIR/qdbusviewer-qt5.desktop" "$ROOTDIR/usr/share/applications/"

  for file in moc uic rcc qmake lconvert lrelease lupdate; do
    ln -sfrvn "$ROOTDIR/usr/bin/$file" "$ROOTDIR/usr/bin/$file-qt5"
  done

  cd .. && rm -r qt-everywhere-src-$VERSION
}
