# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Gabriel Martinez < reitaka at gmail dot com >

pkgname=libimobiledevice
pkgver=1.3.0
pkgrel=13
pkgdesc='Library to communicate with services on iOS devices using native protocols'
arch=('x86_64' 'aarch64')
url='https://libimobiledevice.org/'
license=('LGPL-2.1-or-later')
depends=('glibc' 'libplist' 'libusbmuxd' 'openssl')
makedepends=('cython' 'python' 'python-setuptools')
optdepends=('python: Python bindings')
source=("https://github.com/libimobiledevice/$pkgname/releases/download/$pkgver/$pkgname-$pkgver.tar.bz2"
        'libimobiledevice-libplist-2.3.0.patch'
        'libimobiledevice-cython3.patch'
        'libimobiledevice-python3.patch')
sha256sums=('53f2640c6365cd9f302a6248f531822dc94a6cced3f17128d4479a77bd75b0f6'
            '57fb4616c68c240aad47df52168fa30e4bf43845bfbe53df23cc412003ae64fd'
            'cb6e7feb779f8a414551ecc90423dee1e654fab3acc5fdd15c61d5cea410bff4'
            '3b706669b52d51cd7dff6c12f244ef6421eaa68c9ac5001e5f38fae1876f8b16')

prepare() {
  cd $pkgname-$pkgver

  # Fix build with libplist 2.3.0
  patch -Np1 -i ../libimobiledevice-libplist-2.3.0.patch

  # Fix build with cython 3
  patch -Np1 -i ../libimobiledevice-cython3.patch

  # Fix compatibility with python 3
  patch -Np1 -i ../libimobiledevice-python3.patch

  autoreconf -fi
}

build() (
  cd $pkgname-$pkgver
  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
)

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

  # Include documentation
  install -dm755 "$pkgdir/usr/share/doc/$pkgname"
  cp -r docs/html "$pkgdir/usr/share/doc/$pkgname/"
}
