# Description:	Bluetooth libraries and utilities
# URL:		http://www.bluez.org/
# Maintainer:	Alan Mizrahi, alan at mizrahi dot com dot ve
# Depends on:	dbus alsa-lib libusb-compat
# Optional:	pygobject dbus-python sox gst-plugins-base-compat

name=bluez
version=4.101
release=5
source=(http://www.kernel.org/pub/linux/bluetooth/bluez-$version.tar.xz bluetoothd
http://git.kernel.org/cgit/bluetooth/bluez.git/patch/lib/bluetooth.h?id=cf52a40302d0d20ccca22a7a1f53e46ef8abfca8
)

build() {
	cd $name-$version

	# Fix bluetooth.h to compile in strict C
	patch -p1 -i $SRC/'bluetooth.h?id=cf52a40302d0d20ccca22a7a1f53e46ef8abfca8'

	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--libexecdir=/lib \
		--mandir=/usr/share/man \
		--enable-audio \
		--enable-usb \
		--enable-tools \
		--enable-test \
		--enable-hidd \
		--enable-hid2hci \
		--enable-pand \
		--enable-cups \
		--enable-alsa \
		--enable-bccmd \
		--enable-dfutool \
		--enable-dund

	make
	make DESTDIR=$PKG install

	# install all available tools and test programs with man pages
	shopt -s nullglob
	for i in test/* tools/*; do
		if [ -x $i -a ! -d $i -a ! -x $PKG/usr/bin/${i##*/} -a ! -x $PKG/usr/sbin/${i##*/} ]; then
			if [ -f $i.8 ]; then
				install -D -m 755 $i $PKG/usr/sbin/bluez-${i#*/}
			else
				install -D -m 755 $i $PKG/usr/bin/bluez-${i#*/}
			fi

			for j in $i.[1-8]; do
				install -D -m 644 $j $PKG/usr/share/man/man${j##*.}/bluez-${j##*/}
			done
		fi
	done

	# install init script
	install -D -m 755 $SRC/bluetoothd $PKG/etc/rc.d/bluetoothd

	# install config files
	for i in audio input network serial; do
		install -D -m 644 $i/$i.conf $PKG/etc/bluetooth/$i.conf
	done

	# this is because of the /usr/etc CRUX oddity
	mkdir $PKG/usr/etc
	mv $PKG/etc/dbus-1 $PKG/usr/etc

	# fix some python scripts
	sed -ie 's|from gi.repository import GObject|import gobject as GObject|g' \
		$PKG/usr/bin/bluez-{simple-agent,test-device,test-discovery,test-manager}
	sed -ie 's|hstest|bluez-hstest|g' $PKG/usr/bin/bluez-hsplay
}