abinfo "Creating directory for shadow build ..."
mkdir -pv "$SRCDIR"/abbuild{5,6}

abinfo "Patching to add Qt 6 support ..."
cd "$SRCDIR"
for i in "$SRCDIR"/autobuild/patches/*.patch.deferred; do
    if [[ -e $i ]]; then
        abinfo "Applying patch $i ..."
        patch -Np1 -t -i "$i"
    fi
done

abinfo "Building binaries with Qt 5 support ..."
cd "$SRCDIR"/abbuild5
cmake "$SRCDIR" "${CMAKE_DEF[@]}" \
    -DBUILD_TESTING=OFF \
    -DUSE_QT5=ON \
    -DQT_QMAKE_EXECUTABLE=/usr/bin/qmake-qt5

cmake --build .
abinfo "Installing binaries with Qt 5 support ..."
DESTDIR="$PKGDIR" cmake --install .

abinfo "Building binaries with Qt 6 support ..."
cd "$SRCDIR"/abbuild6
cmake "$SRCDIR" "${CMAKE_DEF[@]}" \
    -DBUILD_TESTING=OFF \
    -DUSE_QT6=ON \
    -DQT_QMAKE_EXECUTABLE=/usr/lib/qt6/bin/qmake6

cmake --build .
abinfo "Installing binaries with Qt 6 support ..."
DESTDIR="$PKGDIR" cmake --install .
