default_pre_build &&

# Try and use our flags everywhere.
# In the Qt5 tarball, qtbase/src/corelib/Qt5CoreConfigExtras.cmake is this blurb;
# "On x86 and x86-64 systems with ELF binaries (especially Linux), due to
# a new optimization in GCC 5.x in combination with a recent version of
# GNU binutils, compiling Qt applications with -fPIE is no longer
# enough."
# Just to be sure, do it.
sedit 's;QMAKE_CFLAGS_RELEASE       += \$\$QMAKE_CFLAGS_OPTIMIZE;QMAKE_CFLAGS_RELEASE       += \$$CFLAGS -fPIC;' qtbase/mkspecs/common/gcc-base.conf &&
sedit 's;QMAKE_LFLAGS_RELEASE   +=;QMAKE_LFLAGS_RELEASE   += \$$LDFLAGS;' qtbase/mkspecs/common/gcc-base.conf &&
sedit 's:QMAKE_LFLAGS_RELEASE   += -Wl,-O1:QMAKE_LFLAGS_RELEASE   += \$$LDFLAGS:' qtbase/mkspecs/common/g++-unix.conf &&

# Also change threads
sedit 's:-lpthread:-pthread:' qtbase/mkspecs/common/linux.conf &&
sedit 's:-lpthread:-pthread:g' qtbase/src/corelib/configure.json &&

sedit "s:/bin/ls:/usr/bin/ls:" qtbase/src/corelib/global/global.pri &&

# qt5's build breaks with an (incompatible) old version of qt5 installed
# even with the patch in PRE_BUILD due to old headers being pulled in.
# this is troublesome, but until someone fixes the includes, we'll have to
# remove to old version before building the new one...
if module_installed $MODULE; then
  lrm --upgrade $MODULE
fi &&

# libxkbcommon-1.6.0 package removes some definitions that are not used.
sed -i '276,283d' qtbase/src/platformsupport/input/xkbcommon/qxkbcommon.cpp &&

# gcc-13.x issue
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 &&

#Needed to accomodate the kf5 patch
mkdir -pv qtbase/.git
