# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: Eduardo Romero <eduardo@archlinux.org>
# Contributor: Damir Perisa <damir.perisa@bluewin.ch>

pkgname=libgphoto2
pkgver=2.5.31
pkgrel=2
pkgdesc="Digital camera access library"
url="http://www.gphoto.org/"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL)
depends=(
  curl
  gd
  libexif
  libjpeg
  libltdl
  libusb
  libxml2
)
makedepends=(
  autoconf-archive
  git
)
provides=(libgphoto2{,_port}.so)
_commit=ba28af2d22fd4cb7fa76a8ff569ba498e8021db5  # tags/libgphoto2-2_5_31-release
source=("git+https://github.com/gphoto/libgphoto2#commit=$_commit"
        libgphoto2-2.5.31-c99.patch)
b2sums=('4359a165282d4c1a512f9cf01367421e735897b0e790271848f1a1eafd8bfdd13e27257b0e62fdc089cd959b10135935b765c4646a0e564dacd85c7eb1f62c82'
        '161b4fceaca4f61a86f6957802c36d9566a67c554748b0d2fc6a77863bd3d420bcbbdaadc96ac54cc886ec80cb046d0e541dcd014bec99f55361914de96127d8')
validpgpkeys=('7C4AFD61D8AAE7570796A5172209D6902F969C95') # Marcus Meissner

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^libgphoto2-//;s/-release//;s/^v//;s/_/./g;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgname

  patch -Np1 -i ${srcdir}/libgphoto2-2.5.31-c99.patch

  autoreconf -fvi
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --disable-rpath
  )

  cd $pkgname
  ./configure "${configure_options[@]}"
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  cd $pkgname
  make DESTDIR="$pkgdir" install

  # Remove unused udev helper
  rm -rv "$pkgdir/usr/lib/udev"

  _genudev
}

_genudev() (
  cd "$pkgdir/usr/lib/libgphoto2"

  export LD_LIBRARY_PATH="$pkgdir/usr/lib${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
  export CAMLIBS="$PWD/$pkgver"

  ./print-camera-list hwdb \
    | install -Dm644 /dev/stdin "$pkgdir/usr/lib/udev/hwdb.d/20-gphoto.hwdb"
  ./print-camera-list udev-rules version 201 \
    | install -Dm644 /dev/stdin "$pkgdir/usr/lib/udev/rules.d/40-gphoto.rules"
)

# vim:set sw=2 sts=-1 et:
