# Contributor: Der Tiger <der.tiger.alpine@arcor.de>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=usbip-utils
pkgver=4.9
pkgrel=0
pkgdesc="Utilities for USB device sharing over IP network"
url="https://kernel.org/doc/readme/drivers-staging-usbip-userspace-README"
arch="all"
license="GPL-2.0"
depends="glib sysfsutils usbutils"
depends_dev="gcc automake autoconf eudev-dev libtool linux-headers sysfsutils-dev glib-dev"
makedepends="$depends_dev tar"
install=""
subpackages="$pkgname-dev $pkgname-doc"
source="https://kernel.org/pub/linux/kernel/v4.x/linux-$pkgver.tar.gz
	sigcld.patch
	usbip.initd
	usbip.confd"

_baseurl="linux-$pkgver/tools/usb/usbip"
builddir="$srcdir/usbip"

unpack() {
	cd "$srcdir"

	mkdir "$builddir"
	tar -C $builddir --strip-components=4 -zxv -f $srcdir/linux-$pkgver.tar.gz $_baseurl
}

prepare() {
	local i
	cd "$builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i;;
		esac
	done
}

build() {
	cd "$builddir"
	export CFLAGS=$(echo $CFLAGS | sed 's|-Os|-O2|')
	export CPPFLAGS="$CFLAGS"
	/bin/sh autogen.sh
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--libdir=/usr/lib \
		--datarootdir=/usr/share
	make
}

check() {
	cd "$builddir"
	./src/usbip version
	./src/usbipd --version
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	install -m755 -D "$srcdir"/usbip.initd "$pkgdir"/etc/init.d/usbip
	install -m755 -D "$srcdir"/usbip.confd "$pkgdir"/etc/conf.d/usbip
}

sha512sums="598696c4babb575a01796eb7ae618861a1292ef9be708e833131cefda8338622ce4e3d8584a4ecaa15529408f9c640d9a5bf8166c8cf8d116627b4c79f0bf0a6  linux-4.9.tar.gz
9572bcc378523cca337324b8519d87813310ae08a358811f8075d54f1e741eb68c8027f9073452e6e942178b46d2f2942d54e68f97f96665fcd6285cfebe07a7  sigcld.patch
fcbd64d844c9bc187d08cef5995e91a46c0df78deb24e96ac9210c0e2c730eca0301970d9b8ffbf003df274682d05072431a26b59d8c491f396618268a12ec92  usbip.initd
eb8de617e27c4d5fdfee9c442e8f74b0afb4d0fe7b59eca3a19629eb70fea7e09b3c125bc968aa8810d845ce661c829bd0f3fdb2288664f2cccf423bc0ae6ae8  usbip.confd"
