post_install() {
  local _mingw_variant_c
  local _mingw_variant_cxx
  local _mingw_variant_arch
  local _mingw_variant_bit

  if [ -f "clangarm64/bin/sdktool.exe" ]; then

    cd clangarm64/bin

    if [ -f "/usr/bin/gcc.exe" ]; then
      # Add the MSYS2 toolchain.
      ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MSYS2_x86_64" > /dev/null 2>&1 || true
      ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MSYS2_x86_64_C" > /dev/null 2>&1 || true
      ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MSYS2_x86_64_CXX" > /dev/null 2>&1 || true

      ./sdktool.exe addTC \
        "--id" "ProjectExplorer.ToolChain.Mingw:M2_MSYS2_x86_64_C" \
        "--language" "1" \
        "--name" "MSYS2 x86_64 GCC (MSYS2)" \
        "--path" "/usr/bin/gcc.exe" \
        "--abi" "x86-windows-msys-pe-64bit" \
        "--supportedAbis" "x86-windows-msys-pe-64bit"

      ./sdktool.exe addTC \
        "--id" "ProjectExplorer.ToolChain.Mingw:M2_MSYS2_x86_64_CXX" \
        "--language" "2" \
        "--name" "MSYS2 x86_64 G++ (MSYS2)" \
        "--path" "/usr/bin/g++.exe" \
        "--abi" "x86-windows-msys-pe-64bit" \
        "--supportedAbis" "x86-windows-msys-pe-64bit"
    fi

    _mingw_variant=CLANGARM64
    _mingw_variant_c="clang"
    _mingw_variant_cxx="clang++"
    _mingw_variant_arch="aarch64"
    _mingw_variant_bit="64bit"

    ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}" > /dev/null 2>&1 || true

    ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_C" > /dev/null 2>&1 || true
    ./sdktool.exe addTC \
      "--id" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_C" \
      "--language" "1" \
      "--name" "MinGW-w64 ${_mingw_variant} C (MSYS2)" \
      "--path" "/${_mingw_variant,,}/bin/${_mingw_variant_c}.exe" \
      "--abi" "${_mingw_variant_arch}-windows-msys-pe-${_mingw_variant_bit}" \
      "--supportedAbis" "${_mingw_variant_arch}-windows-msys-pe-${_mingw_variant_bit}"

    ./sdktool.exe rmTC "--id" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_CXX" > /dev/null 2>&1 || true
    ./sdktool.exe addTC \
      "--id" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_CXX" \
      "--language" "2" \
      "--name" "MinGW-w64 ${_mingw_variant} C++ (MSYS2)" \
      "--path" "/${_mingw_variant,,}/bin/${_mingw_variant_cxx}.exe" \
      "--abi" "${_mingw_variant_arch}-windows-msys-pe-${_mingw_variant_bit}" \
      "--supportedAbis" "${_mingw_variant}-windows-msys-pe-${_mingw_variant_bit}"

    ./sdktool.exe rmDebugger "--id" "MinGW.w64.GDB_${_mingw_variant}" > /dev/null 2>&1 || true
    ./sdktool.exe addDebugger \
      "--id" "MinGW.w64.GDB_${_mingw_variant}" \
      "--name" "MinGW-w64 GDB (${_mingw_variant})" \
      "--engine" "1" \
      "--binary" "/${_mingw_variant,,}/bin/gdb.exe" \
      "--abis" "${_mingw_variant_arch}-windows-msys-pe-${_mingw_variant_bit}"

    ./sdktool.exe rmCMake "--id" "MinGW.w64.CMake_${_mingw_variant}" > /dev/null 2>&1 || true
    ./sdktool.exe addCMake \
      "--id" "MinGW.w64.CMake_${_mingw_variant}" \
      "--name" "MinGW-w64 CMake (${_mingw_variant})" \
      "--path" "/${_mingw_variant,,}/bin/cmake.exe"

    # Add Qt5 shared version
    ./sdktool.exe rmQt "--id" "qt5.shared.M2_MinGW-w64_${_mingw_variant}=" > /dev/null 2>&1 || true
    ./sdktool.exe addQt \
      "--id" "qt5.shared.M2_MinGW-w64_${_mingw_variant}" \
      "--name" "Qt %{Qt:Version} (shared) MinGW-w64 ${_mingw_variant} (MSYS2)" \
      "--type" "Qt4ProjectManager.QtVersion.Desktop" \
      "--qmake" "/${_mingw_variant,,}/bin/qmake-qt5.exe"

    ./sdktool.exe rmKit "--id" "qt5.shared.M2_MinGW-w64_${_mingw_variant}_kit" > /dev/null 2>&1 || true
    ./sdktool.exe addKit \
      "--id" "qt5.shared.M2_MinGW-w64_${_mingw_variant}_kit" \
      "--name" "Desktop Qt %{Qt:Version} (shared) MinGW-w64 ${_mingw_variant} (MSYS2)" \
      "--Ctoolchain" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_C" \
      "--Cxxtoolchain" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_CXX" \
      "--qt" "qt5.shared.M2_MinGW-w64_${_mingw_variant}" \
      "--debuggerid" "MinGW.w64.GDB_${_mingw_variant}" \
      "--cmake" "MinGW.w64.CMake_${_mingw_variant}" \
      "--devicetype" "Desktop"

    # Add Qt6 shared version
    ./sdktool.exe rmQt "--id" "qt6.shared.M2_MinGW-w64_${_mingw_variant}=" > /dev/null 2>&1 || true
    ./sdktool.exe addQt \
      "--id" "qt6.shared.M2_MinGW-w64_${_mingw_variant}" \
      "--name" "Qt %{Qt:Version} (shared) MinGW-w64 ${_mingw_variant} (MSYS2)" \
      "--type" "Qt4ProjectManager.QtVersion.Desktop" \
      "--qmake" "/${_mingw_variant,,}/bin/qmake6.exe"

    ./sdktool.exe rmKit "--id" "qt6.shared.M2_MinGW-w64_${_mingw_variant}_kit" > /dev/null 2>&1 || true
    ./sdktool.exe addKit \
      "--id" "qt6.shared.M2_MinGW-w64_${_mingw_variant}_kit" \
      "--name" "Desktop Qt %{Qt:Version} (shared) MinGW-w64 ${_mingw_variant} (MSYS2)" \
      "--Ctoolchain" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_C" \
      "--Cxxtoolchain" "ProjectExplorer.ToolChain.Mingw:M2_MinGW-w64_${_mingw_variant}_CXX" \
      "--qt" "qt6.shared.M2_MinGW-w64_${_mingw_variant}" \
      "--debuggerid" "MinGW.w64.GDB_${_mingw_variant}" \
      "--cmake" "MinGW.w64.CMake_${_mingw_variant}" \
      "--devicetype" "Desktop"

    cd -
  fi
}

post_upgrade() {
  post_install
}
