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

_realname=installer-framework
pkgbase=mingw-w64-qt-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-qt-${_realname}-git"
pkgdesc="The Qt Installer Framework used for the Qt SDK installer (mingw-w64)"
pkgver=r3068.55c191ed
pkgrel=1
arch=('any')
url='https://www.qt.io/developers/'
license=('GPL3' 'LGPL' 'FDL' 'custom')
provides=("${MINGW_PACKAGE_PREFIX}-qt-${_realname}")
makedepends=("${MINGW_PACKAGE_PREFIX}-qt5-static" "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-make" "${MINGW_PACKAGE_PREFIX}-libwebp"
             "${MINGW_PACKAGE_PREFIX}-jasper" "git")
options=('strip' 'staticlibs')
#options=('!strip' 'debug' 'staticlibs')
source=("${_realname}"::"git+https://github.com/qtproject/${_realname}.git"
        "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")
sha256sums=('SKIP'
            '38ff350982e03aff66a70e87b0202eca7dae696d0b5312270204e8cc572e5aa6'
            '4db7a4c3e6ea3a26de6493e4e2b683251060c7c8cefacf6bfa458026e541e906'
            '2aaf51f346edb6db2367262d0d8e1bb77d0afee51fabd5b2766038a97ebf0ca6'
            '2fbd939417da1a2c0166c0ac47307b9c579f07a3e5b37aa73af1629caa38387f'
            '00857e9a654ecaed93ec79898389329799fdc01968b7562ae1889498b12c943d'
            '8e01c201d98e10bb3e8b90d7e731a9fa4640b6784acad763d2f1d6ee689ffa9a'
            'ef94ad9a00aca5ab66937bd3fe4a3c1714ce610bb59dbb338a92bef5d4beaebf')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git am --committer-date-is-author-date "${srcdir}"/0002-add-installation-stuff-to-pro-files.patch
  git am --committer-date-is-author-date "${srcdir}"/0003-add-recursive-option-to-rmdir-operation.patch
  git am --committer-date-is-author-date "${srcdir}"/0004-add-dirExists-fuction.patch
  # Apply patch from https://bugreports.qt.io/browse/QTIFW-397
  git am --committer-date-is-author-date "${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
  git am --committer-date-is-author-date "${srcdir}"/0006-Don-t-remove-files-that-live-outside-of-path.patch
  git am --committer-date-is-author-date "${srcdir}"/0007-Don-t-prevent-qmake-linking-qmltooling-plugin.patch
  git am --committer-date-is-author-date "${srcdir}"/0008-Use-QTPLUGIN-qminimal-on-Windows-too.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 ../${_realname}/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}/${_realname}/LICENSE.GPL3-EXCEPT ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.GPL3-EXCEPT
  install -Dm644 ${srcdir}/${_realname}/LICENSE.FDL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.FDL
}
