# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=usb_modeswitch
pkgver=2.6.1
pkgrel=4.1
_pkgdata=20191128
pkgdesc="Activating switchable USB devices on Linux."
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="http://www.draisberghof.de/usb_modeswitch/"
license=('GPL')
depends=('libusb' 'tcl')
makedepends=('gcc' 'make' 'systemd')
backup=("etc/$pkgname.conf")
source=("http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-${pkgver}.tar.bz2"
	"http://www.draisberghof.de/usb_modeswitch/usb-modeswitch-data-${_pkgdata}.tar.bz2"
	"usb-modeswitch-${pkgver}-device_reference.txt::http://www.draisberghof.de/usb_modeswitch/device_reference.txt")
sha256sums=('5195d9e136e52f658f19e9f93e4f982b1b67bffac197d0a455cd8c2cd245fa34'
            '3f039b60791c21c7cb15c7986cac89650f076dc274798fa242231b910785eaf9'
            '846b45a82a31c9755ab86d9c051e706aff445e1e793575b7ae195a4edeb4d594')

prepare() {
  cd "$srcdir"/usb-modeswitch-$pkgver/
  sed -i 's|/usr/sbin/usb_mode|/usr/bin/usb_mode|g' usb_modeswitch{.conf,_dispatcher.tcl,.sh}
}

build() {
  cd "$srcdir"/usb-modeswitch-$pkgver/
  make clean
  make SBINDIR=/usr/bin
}

package() {
  cd "$srcdir"/usb-modeswitch-$pkgver/

  mkdir -p "$pkgdir"/usr/lib/udev
  mkdir -p "$pkgdir"/etc
  mkdir -p "$pkgdir"/usr/share/man/man1
  mkdir -p "$pkgdir"/usr/lib/systemd/system

  make \
    DESTDIR="$pkgdir" \
    UDEVDIR="$pkgdir"/usr/lib/udev \
    SBINDIR="$pkgdir"/usr/bin \
    SYSDIR="$pkgdir"/usr/lib/systemd/system \
    install

  cp "$srcdir"/usb-modeswitch-${pkgver}-device_reference.txt "$pkgdir"/etc/usb_modeswitch.setup

  cd "$srcdir"/usb-modeswitch-data-${_pkgdata}
  make DESTDIR="$pkgdir" install RULESDIR="$pkgdir"/usr/lib/udev/rules.d
}
