# Maintainer: Peter Budai <peterbudai at hotmail dot com>

_realname=gphoto2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.32
pkgrel=1
pkgdesc="The gphoto2 commandline tool for accessing and controlling digital cameras (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='http://www.gphoto.org/'
msys2_repository_url="https://github.com/gphoto/gphoto2"
msys2_references=(
  'anitya: 10207'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libgphoto2"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libltdl"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-popt")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner
source=("https://github.com/gphoto/gphoto2/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz"{,.asc}
        "01_gphoto_close_before_rename.patch"
        "02_fix-spawnve-usage.patch"
        "03-no-fnmatch.patch")
sha256sums=('be08a449bbed9613bc9db105997c4ba71410d41870496420359a99b37502c406'
            'SKIP'
            '5722c6971d0795b6678972695b26eafcddd20a2a7c5e78aecaa4d0ec1ae26a7b'
            '70079291e40b2877cb9c31fdb3c6c45eac19ce7dff566b2811f55eb15bf937c0'
            'f0443a928c8faafdc06eb1636cd8bb84ac2c5d96500c9aba328075908082af98')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/01_gphoto_close_before_rename.patch
  patch -p1 -i "${srcdir}"/02_fix-spawnve-usage.patch
  patch -p1 -i "${srcdir}"/03-no-fnmatch.patch

  autoreconf -fiv
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  export LDFLAGS="$LDFLAGS -lshlwapi"

 ../"${_realname}-${pkgver}"/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}


package() {
  cd "build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
