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

_realname=libgphoto2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.27
pkgrel=1
pkgdesc="libgphoto2 is a free, redistributable, ready to use set of digital camera software applications for Unix-like system (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://gphoto.org/proj/libgphoto2/"
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libgd"
         "${MINGW_PACKAGE_PREFIX}-libexif"
         "${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-libtool")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=(https://sourceforge.net/projects/gphoto/files/libgphoto/${pkgver}/${_realname}-${pkgver}.tar.gz
        libgphoto2-gp_system_filename-fix.patch
        libgphoto2-fix-lumix.patch
	libgphoto2-configure-ws232.patch)
sha256sums=('fd48f6f58259ba199e834010aca0af3672ca0223ed0a98ba89ec693a415f242a'
            '27c558cdf88bee6ce1f3f564d6dfbc0b78809c33b98d20c9e58e40e335d7b0dd'
            '08b6d5b56d01daae60afa4f0b924ddff2c6d5ef2a5bf6057c601f1efb7019016'
            'fcda293776f18cd506f3aed09b8e0a969c7dbf390574b4b8c3c8377e827dbf8a')
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner 

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libgphoto2-gp_system_filename-fix.patch"
  patch -Np1 -i "${srcdir}/libgphoto2-fix-lumix.patch"
  patch -Np1 -i "${srcdir}/libgphoto2-configure-ws232.patch"
  autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  #mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  #Note: --with-libusb=no is required for Windows 10 to work.
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  
  ./configure \
    --prefix="${MINGW_PREFIX}"      \
    --build=${MINGW_CHOST}          \
    --host=${MINGW_CHOST}           \
    --with-libusb=no \
    --with-gdlib=auto \
    --disable-internal-docs


  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

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

  # Remove unused udev helper
  rm -rf "${pkgdir}/${MINGW_PREFIX}/lib/udev"

  # Remove recursive symlink
  rm -rfv "${pkgdir}/${MINGW_PREFIX}/include/gphoto2/gphoto2"  

  # install profile script
  mkdir -p "${pkgdir}${MINGW_PREFIX}"/etc/profile.d

  cat > ${pkgdir}${MINGW_PREFIX}/etc/profile.d/${_realname}.sh <<EOF
export CAMLIBS=${MINGW_PREFIX}/lib/${_realname}/${pkgver}
export IOLIBS=${MINGW_PREFIX}/lib/${_realname}_port/0.12.0
EOF

}
