# 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=3
pkgdesc="Digital camera access library"
url="http://www.gphoto.org/"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL-2.1-or-later)
depends=(
  bash
  curl
  gd
  glibc
  libexif
  libjpeg-turbo
  libltdl
  libusb
  libxml2
)
makedepends=(
  autoconf-archive
  git
)
provides=(libgphoto2{,_port}.so)
source=("git+https://github.com/gphoto/libgphoto2#tag=v$pkgver")
b2sums=('4359a165282d4c1a512f9cf01367421e735897b0e790271848f1a1eafd8bfdd13e27257b0e62fdc089cd959b10135935b765c4646a0e564dacd85c7eb1f62c82')
validpgpkeys=(
  7C4AFD61D8AAE7570796A5172209D6902F969C95 # Marcus Meissner <marcus@jet.franken.de>
)

prepare() {
  cd $pkgname
  autoreconf -fvi
}

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

  case "${CARCH}" in
    powerpc) export CFLAGS+=' -Wno-incompatible-pointer-types' ;;
  esac

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

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

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

  (
    export LD_LIBRARY_PATH="$pkgdir/usr/lib"
    export CAMLIBS="$PWD/$pkgver"

    "$pkgdir/usr/lib/libgphoto2/print-camera-list" hwdb \
      | install -Dm644 /dev/stdin "$pkgdir/usr/lib/udev/hwdb.d/20-gphoto.hwdb"
    "$pkgdir/usr/lib/libgphoto2/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:
