#!/usr/bin/env bash

if [[ "$1" == "shared" ]]; then
  echo "Building shared"
elif [[ "$1" == "static" ]]; then
  echo "Building static"
else
  echo "${0} :: Error :: Please pass static or shared"
  exit 1
fi

THISDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Listed in tier-order
declare -a pkgs=(
extra-cmake-modules 
ki18n-qt5 
karchive-qt5
kdoctools-qt5 
kcoreaddons-qt5
kauth-qt5 
kcodecs-qt5 
kconfig-qt5 
kwidgetsaddons-qt5 
kcompletion-qt5 
kguiaddons-qt5
kconfigwidgets-qt5 
kwindowsystem-qt5 
kcrash-qt5 
kdbusaddons-qt5 
kservice-qt5 
kglobalaccel-qt5 
kitemviews-qt5 
kiconthemes-qt5 
sonnet-qt5 
ktextwidgets-qt5
attica-qt5
kxmlgui-qt5 
kbookmarks-qt5 
solid-qt5 
kjobwidgets-qt5 
snorenotify
phonon-qt5
knotifications-qt5 
kwallet-qt5
kio-qt5
kinit-qt5 
kpackage-qt5 
kdeclarative-qt5 
kparts-qt5 
kplotting-qt5 
kunitconversion-qt5
threadweaver-qt5
kcmutils-qt5 
kactivities-qt5 
kirigami2-qt5
plasma-framework-qt5
kjs-qt5 
kfilemetadata-qt5 
kidletime-qt5 
syntax-highlighting-qt5 
syndication-qt5 
knewstuff-qt5 
kdnssd-qt5 
kholidays-qt5 
kimageformats-qt5 
kitemmodels-qt5 
ktexteditor-qt5 
breeze-icons-qt5 
kdewebkit-qt5
kate
)

for pkg in "${pkgs[@]}"; do
  pushd ${THISDIR}/../mingw-w64-${pkg}
  export KF5_VARIANT=$1
  rm -rf *pkg*xz src pkg
  makepkg-mingw -siLf --noconfirm || exit 1
  popd
done
