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

_realname=gphoto2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.27
pkgrel=1
pkgdesc="The gphoto2 commandline tool for accessing and controlling digital cameras. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='http://www.gphoto.org/'
license=('GNU')
depends=("${MINGW_PACKAGE_PREFIX}-libgphoto2"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-popt")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libtool")
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner
source=("https://sourceforge.net/projects/gphoto/files/gphoto/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "01_gphoto_close_before_rename.patch"
	"gphoto2-check-popt.patch")
sha256sums=('993175db0354d5b0eb278c72a3e80589ce0cb2141639e43cfabc65981a1f2476'
            'ca4e431c4f2bca1272a6580ebab7d81a82fa38fad07624cc8c6328b458293b19'
            'fdc32ca1291b42f5d0b5f57ec2de47dfa6201bf45342a202ae86eb1caafd45d0')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/01_gphoto_close_before_rename.patch
  # https://github.com/gphoto/gphoto2/pull/419
  patch -p1 -i ${srcdir}/gphoto2-check-popt.patch
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}


package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
