### this file is sourced not run
PKGVER=4.101 # the final version of bluez4
PKGBUILD=1
PKGARCH=x86_64

# BLFS 7.5 modified with Fatdog64 build config 
# + arch patches from here: https://bugs.archlinux.org/task/35695
# + ubuntu patches from here: https://launchpad.net/ubuntu/+source/bluez/4.101-0ubuntu25
TARBALL=bluez-$PKGVER.tar.xz
MD5SUM=c828c172f01f20c6ecd7f407894956a2 
SRC_URL=http://www.kernel.org/pub/linux/bluetooth/$TARBALL
BUNDLE=

SLACKREQ='glib dbus alsa-lib libsndfile libusb cups'
SLACKDESC="bluez: bluez $PKGVER (Bluetooth protocol stack)  
bluez:  
bluez: The BlueZ package contains the Bluetooth protocol stack for Linux. It 
bluez: enables you to connect to bluetooth devices - provided that you have 
bluez: bluetooth hardware in your machine.  
bluez: 
bluez: 
bluez: 
bluez: 
bluez: 
bluez:
"

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/bluez* &&
	
	# apply arch patches
	tar -xf $CHROOT_DIR/tmp/pkg/bluez-arch-patches.tar.gz &&
	for p in *.patch; do patch -Np1 -i $p || return 1; done &&
	
	# apply ubuntu patches, we only apply some as there are some
	# duplicates with arch
	tar -xf ../pkg/bluez_4.101-0ubuntu25.debian.tar.xz
	for p in $(cat ../pkg/ubuntu25-series); do
		patch -Np1 -i debian/patches/$p || return 1
	done &&
	
	cp $CHROOT_DIR/tmp/pkg/hex2hcd.c . &&
	cp $CHROOT_DIR/tmp/pkg/brcm_patchram*.c .
}
### default pkg_package
### build
pkg_build() {
	cd /tmp/bluez*
	CONFFLAGS="$CONFFLAGS \
            --enable-bccmd \
            --enable-dfutool \
            --enable-dund \
            --enable-hid2hci \
            --enable-hidd \
            --enable-pand \
            --enable-tools \
            --enable-wiimote \
            --disable-test \
            --without-systemdunitdir \
            --enable-alsa --enable-cups --enable-usb \
            --with-ouifile=/usr/share/misc/oui.txt"
    pkg_build_autoconf &&
    
	for CONFFILE in audio input network serial ; do
		install -v -m644 ${CONFFILE}/${CONFFILE}.conf /etc/bluetooth/${CONFFILE}.conf
	done &&
	install -v -m755 -d /usr/share/doc/bluez-4.101 &&
	install -v -m644 doc/*.txt /usr/share/doc/bluez-4.101 &&
	pkg_build_slackdesc &&
	
	# build hex2hcd for converting Broadcom windows firmware to Linux format
	gcc -Os -s -o /usr/bin/hex2hcd hex2hcd.c &&
	
	# tool to upload broadcom firmware. Not needed for if btusb.ko can already patch it.
	gcc -Os -s -o /usr/bin/brcm_patchram_plus_usb brcm_patchram_plus_usb.c -lbluetooth &&
	gcc -Os -s -o /usr/bin/brcm_patchram_plus brcm_patchram_plus.c -lbluetooth &&
	
	# legacy link for Fatdog apps
	rm -f /etc/bluetooth/var && 
	ln -sf /var/lib/bluetooth /etc/bluetooth/var && 
	
	# add Enable=Socket by default
	sed -i -e '/\[General\]/aEnable=Socket' /etc/bluetooth/audio.conf  && 
	
	# examples
	cp -a test /usr/share/doc/bluez-4.101/examples
}


