# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=winsparkle
_wx_basever=3.2
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=0.7.0
pkgrel=5
pkgdesc='App update framework for Windows, inspired by Sparkle for OS X (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://winsparkle.org/'
license=('spdx:MIT')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw"
)
depends=("${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs") # gcc-libs not needed?
source=("https://github.com/vslavik/winsparkle/releases/download/v${pkgver}/WinSparkle-${pkgver}-src.zip"
        001-compile-fixes.patch
        Makefile)
sha256sums=('748adadd539c7ed3fd8f62d2f960b04d715fedb3e8f328f97decae85f29dc399'
            '7e2f9fb05f7c6191597fa20341e765c2d8c1bec868f0bba4165fee7140bb5afa'
            '07cf20f933d3cb8face34ba927b535756fcfadeaeb3ddf754f8521454528a08f')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

prepare() {
  cd "${srcdir}/WinSparkle-${pkgver}-src"
  cp ../Makefile src

  apply_patch_with_msg \
    001-compile-fixes.patch
}

build() {
  cd "${srcdir}/WinSparkle-${pkgver}-src/src"
  make
}

package() {
  cd "${srcdir}/WinSparkle-${pkgver}-src"
  install -D -m644 include/winsparkle.h         "${pkgdir}${MINGW_PREFIX}/include/winsparkle.h"
  install -D -m644 include/winsparkle-version.h "${pkgdir}${MINGW_PREFIX}/include/winsparkle-version.h"
  install -D -m644 src/libwinsparkle.a          "${pkgdir}${MINGW_PREFIX}/lib/libwinsparkle.a"
  install -D -m644 src/libwinsparkle.dll.a      "${pkgdir}${MINGW_PREFIX}/lib/libwinsparkle.dll.a"
  install -D -m755 src/libwinsparkle.dll        "${pkgdir}${MINGW_PREFIX}/bin/libwinsparkle.dll"
  install -D -m644 COPYING                      "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
