# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>

pkgname=libusb
pkgver=1.0.29
pkgrel=1
pkgdesc="Library that provides generic access to USB devices"
arch=(x86_64 aarch64)
url="https://libusb.info/"
_url="https://github.com/libusb/libusb"
license=(LGPL-2.1-or-later)
depends=(glibc)
makedepends=(
  git
  systemd
)
provides=(libusb-1.0.so)
source=(git+$_url.git#tag=v$pkgver)
sha512sums=('1f30c7f4b57352db7c4e786043a431bb52a9faab3fc3fa17d7112d5671da8cc894ec1b8e117185081ea2faad28177d8db4b5fde053327bdadea327e099669cc5')
b2sums=('759be08ecf6d7e3c60427223dda4667538b7de32fe3fe6769b53c46859fec31f678967828fe278253a03677cf9c49a672b08ef39a525875c03ec04c0e1086015')

prepare() {
  cd $pkgname
  autoreconf -fiv
}

build() {
  cd $pkgname
  ./configure --prefix=/usr
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  make -k check -C $pkgname
}

package () {
  depends+=(
    systemd-libs libudev.so
  )

  make DESTDIR="$pkgdir" install -C $pkgname
  install -vDm 644 $pkgname/{AUTHORS,ChangeLog,README} -t "$pkgdir/usr/share/doc/$pkgname/"
}
