# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=libimobiledevice
pkgver=1.3.0
pkgrel=13
pkgdesc='Library to communicate with services on iOS devices using native protocols'
arch=('x86_64')
url='https://libimobiledevice.org/'
license=('LGPL-2.1-or-later')
depends=('glibc' 'libplist' 'libusbmuxd' 'openssl')
makedepends=('cython' 'doxygen' 'git' 'python-setuptools')
optdepends=('python: Python bindings')
source=("git+https://github.com/libimobiledevice/libimobiledevice.git#tag=$pkgver"
        'libimobiledevice-libplist-2.3.0.patch'
        'libimobiledevice-cython3.patch'
        'libimobiledevice-python3.patch')
b2sums=('49d7d01a78a618860b774db835e4f0a7fb37743dc8f4b0b1a1fbefe71c3590d07de04616de2129c2a6090ac4211826004227c28dacff0e61e130e1c4c87c3072'
        '136390910a57e70c3ce458ab5c6def4e079b7eb4c2946447102078ca511f8d112caf9460c074ecbb6c8a4f526e0aa50015d2f92acf66dbbb666bd007e361ee5e'
        '6e0d5eeeeedfd1888e2f24a4bf9ccb97e2761b9ae44d07a238f3235f4b61ad7d12918c801620e2c0f1f23aebb1754411f7f7e81a3a10126a0a0f1b8f4057d9b5'
        '0c6ee9f22baf8258e097411a0857f8a902b839a694d0c4ed790b054a0b5f63da3168883953e7302d2c942c0db42a340e8e9948bcdc95412d882d465869f5d878')

prepare() {
  cd $pkgname

  # 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
  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
  make docs
)

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

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