### this file is sourced not run
PKGVER=5.62
PKGBUILD=1
PKGARCH=x86_64

# post BLFS 8.2 2018-07-31 modified with Fatdog64 build config 
TARBALL=bluez-$PKGVER.tar.xz
MD5SUM=06d901a5bb82f9a359fa7d9f19939ae5
SRC_URL=http://www.kernel.org/pub/linux/bluetooth/$TARBALL
BUNDLE=

SLACKREQ='glib dbus libical 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* &&

	cp ../pkg/hex2hcd.c . &&
	cp ../pkg/brcm_patchram*.c . &&
	true
}
### default pkg_package
### build
pkg_build() {
	cd /tmp/bluez*
	CONFFLAGS="$CONFFLAGS \
			--enable-library \
			--disable-systemd \
			--disable-test \
			--enable-threads \
			--enable-backtrace \
			--enable-logger \
			--enable-sap \
			--enable-nfc \
			--enable-midi \
			--enable-health \
			--enable-hid2hci \
			--enable-manpages \
			--enable-deprecated \
			--enable-experimental"
			#--enable-testing # only useful stuff here is btvirt emulator
    pkg_build_autoconf &&
	pkg_build_slackdesc &&

    # install bin
	ln -svf ../libexec/bluetooth/bluetoothd /usr/sbin &&
	ln -svf ../libexec/bluetooth/obexd /usr/sbin &&

	# install conf
	install -v -dm755 /etc/bluetooth &&
	install -v -m644 src/main.conf /etc/bluetooth/main.conf &&

	# install docs
	install -v -dm755 /usr/share/doc/bluez-$PKGVER &&
	install -v -m644 doc/*.txt /usr/share/doc/bluez-$PKGVER &&

	# BLFS extra conf
	install -m644 ../pkg/*.conf /etc/bluetooth &&

	# Fatdog extra bins
	install -m755 attrib/gatttool /usr/bin &&
	install -m755 tools/btgatt-server /usr/bin &&
	install -m755 tools/btgatt-client /usr/bin &&
	install -m755 tools/bdaddr /usr/bin &&
	install -m644 tools/bdaddr.1 /usr/share/man/man1 &&
	install -m755 tools/btmgmt /usr/bin &&
	install -m755 tools/btsnoop /usr/bin &&
	install -m755 tools/obex-*-tool /usr/bin &&
	
	# Fatdog extra conf
	for CONFFILE in input network; do
		install -v -m644 profiles/${CONFFILE}/${CONFFILE}.conf /etc/bluetooth/${CONFFILE}.conf
	done &&
	
	# 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 older Fatdog apps
	rm -f /etc/bluetooth/var && 
	ln -sf /var/lib/bluetooth /etc/bluetooth/var &&

	# startup script
	mkdir -p /etc/init.d &&
	install -m755 /tmp/pkg/85-bluetooth /etc/init.d &&
	
	true
}
   
