# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=installer-framework
pkgbase=mingw-w64-qt-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-qt-${_realname}"
pkgdesc="The Qt Installer Framework used for the Qt SDK installer (mingw-w64)"
pkgver=4.0.1
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.qt.io/developers/'
license=('GPL3' 'LGPL' 'FDL' 'custom')
conflicts=("${MINGW_PACKAGE_PREFIX}-qt-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-qt-${_realname}-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-qt5-static" "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-make" "${MINGW_PACKAGE_PREFIX}-libwebp"
             "${MINGW_PACKAGE_PREFIX}-jasper"
             unzip)
options=('strip' 'staticlibs')
#options=('!strip' 'debug' 'staticlibs')
source=(#${_realname}-${pkgver}.tar.gz::https://github.com/qtproject/installer-framework/archive/${pkgver}.tar.gz
        https://download.qt.io/official_releases/qt-installer-framework/${pkgver}/qt-installer-framework-${pkgver}.zip
        "0002-add-installation-stuff-to-pro-files.patch"
        "0003-add-recursive-option-to-rmdir-operation.patch"
        "0004-add-dirExists-fuction.patch"
        "0005-Fix-RunProgram-variable-substitution.patch"
        "0006-Don-t-remove-files-that-live-outside-of-path.patch"
        "0007-Don-t-prevent-qmake-linking-qmltooling-plugin.patch"
        "0008-Use-QTPLUGIN-qminimal-on-Windows-too.patch"
        "0010-fix-version-pass-to-windres.patch")
sha256sums=('7746a3cdeb55639c0c45bef66d1b636e8d146e4a2921c00fe506ec4165771198'
            '38ff350982e03aff66a70e87b0202eca7dae696d0b5312270204e8cc572e5aa6'
            '4db7a4c3e6ea3a26de6493e4e2b683251060c7c8cefacf6bfa458026e541e906'
            '2aaf51f346edb6db2367262d0d8e1bb77d0afee51fabd5b2766038a97ebf0ca6'
            '2fbd939417da1a2c0166c0ac47307b9c579f07a3e5b37aa73af1629caa38387f'
            '00857e9a654ecaed93ec79898389329799fdc01968b7562ae1889498b12c943d'
            '8e01c201d98e10bb3e8b90d7e731a9fa4640b6784acad763d2f1d6ee689ffa9a'
            'ef94ad9a00aca5ab66937bd3fe4a3c1714ce610bb59dbb338a92bef5d4beaebf'
            'f7293902981c69e642c59276cee2a24c0d0540f8fddfc4ac9f9a6b22cf0151ed')

prepare() {
  cd "${srcdir}"/qt-${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0002-add-installation-stuff-to-pro-files.patch
  patch -p1 -i "${srcdir}"/0003-add-recursive-option-to-rmdir-operation.patch
  patch -p1 -i "${srcdir}"/0004-add-dirExists-fuction.patch
  # Apply patch from https://bugreports.qt.io/browse/QTIFW-397
  patch -p1 -i "${srcdir}"/0005-Fix-RunProgram-variable-substitution.patch
  # This requires ../mingw-w64-qt5-static/0044-qt-5.4.1-Revert-Revert-fix-NTFS-mount-points.patch
  # to fix the problem for junction points. Together they fix:
  # https://github.com/msys2/msys2.github.io/issues/4
  patch -p1 -i "${srcdir}"/0006-Don-t-remove-files-that-live-outside-of-path.patch
  patch -p1 -i "${srcdir}"/0007-Don-t-prevent-qmake-linking-qmltooling-plugin.patch
  patch -p1 -i "${srcdir}"/0008-Use-QTPLUGIN-qminimal-on-Windows-too.patch
  patch -p1 -i "${srcdir}"/0010-fix-version-pass-to-windres.patch
}

build() {
  local _config
  cd "${srcdir}"
  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  mkdir build-${CARCH}
  if check_option "debug" "n"; then
    _config="release"
  else
    _config="debug"
  fi
  cd build-${CARCH}
  ${MINGW_PREFIX}/qt5-static/bin/qmake.exe ../qt-${_realname}-${pkgver}/installerfw.pro CONFIG+="${_config}" CONFIG+=no_testcase_installs
  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install
  rm -rf ${pkgdir}${MINGW_PREFIX}/lib
  
  install -Dm644 ${srcdir}/qt-${_realname}-${pkgver}/LICENSE.GPL3-EXCEPT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.GPL3-EXCEPT
  install -Dm644 ${srcdir}/qt-${_realname}-${pkgver}/LICENSE.FDL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.FDL
}
