# Template file for 'bluez'
pkgname=bluez
version=5.86
revision=2
build_style=gnu-configure
configure_args="--with-udevdir=/usr/lib/udev --disable-systemd
 --enable-sixaxis --enable-threads --enable-library --enable-deprecated
 --enable-external-ell --enable-mesh --enable-nfc --enable-experimental
 --enable-hid2hci"
hostmakedepends="automake flex libtool pkg-config python3-docutils"
makedepends="cups-devel eudev-libudev-devel libglib-devel libical-devel
 readline-devel ell-devel json-c-devel"
short_desc="Bluetooth tools and daemons"
maintainer="Érico Nogueira <ericonr@disroot.org>"
license="GPL-2.0-or-later, LGPL-2.1-or-later"
homepage="http://www.bluez.org/"
changelog="https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/ChangeLog"
distfiles="${KERNEL_SITE}/bluetooth/bluez-${version}.tar.xz"
checksum=99f144540c6070591e4c53bcb977eb42664c62b7b36cb35a29cf72ded339621d
conf_files="/etc/bluetooth/main.conf"
system_groups="bluetooth"

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	makedepends+=" musl-legacy-compat"
fi

post_patch() {
	# Use system ell
	rm -r ell/*
}

pre_configure() {
	autoreconf -fi
}

post_install() {
	vinstall ${wrksrc}/src/main.conf 644 etc/bluetooth
	vinstall profiles/input/input.conf 644 etc/bluetooth
	vinstall profiles/network/network.conf 644 etc/bluetooth
	vbin attrib/gatttool
	vbin tools/btgatt-client
	vbin tools/btgatt-server
	vbin tools/btmgmt
	vsv bluetoothd

	vdoc ${FILESDIR}/README.voidlinux

	rm ${DESTDIR}/etc/bluetooth/mesh-main.conf
}

libbluetooth_package() {
	short_desc="Library to use the Bluez Linux Bluetooth Stack"
	pkg_install() {
		vmove "usr/lib/libbluetooth.so.*"
	}
}

libbluetooth-devel_package() {
	depends="libbluetooth>=${version}_${revision}"
	short_desc="Development files to use the BlueZ Linux Bluetooth library"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
	}
}

bluez-cups_package() {
	short_desc="CUPS printer backend for Bluetooth printers"
	pkg_install() {
		vmove usr/lib/cups/backend/bluetooth
	}
}

bluez-deprecated_package() {
	short_desc+=" - deprecated tools"
	pkg_install() {
		vmove usr/bin/ciptool
		vmove usr/bin/hciattach
		vmove usr/bin/hciconfig
		vmove usr/bin/hcidump
		vmove usr/bin/hcitool
		vmove usr/bin/rfcomm
		vmove usr/bin/sdptool
		vmove usr/bin/gatttool
		vmove usr/share/man/man1/ciptool.1
		vmove usr/share/man/man1/hciattach.1
		vmove usr/share/man/man1/hciconfig.1
		vmove usr/share/man/man1/hcidump.1
		vmove usr/share/man/man1/hcitool.1
		vmove usr/share/man/man1/rfcomm.1
		vmove usr/share/man/man1/sdptool.1
	}
}

bluez-hid2hci_package() {
	short_desc+=" - hid2hci"
	pkg_install() {
		vmove usr/lib/udev
		vmove usr/share/man/man1/hid2hci.1
	}
}

bluez-obex_package() {
	short_desc+=" - obex OBject EXchange"
	pkg_install() {
		vmove usr/libexec/bluetooth/obexd
		vmove usr/share/dbus-1/services/org.bluez.obex.service
		vmove "usr/share/man/man5/org.bluez.obex.*"
	}
}

bluez-mesh_package() {
	short_desc+=" - mesh"
	pkg_install() {
		vmove "usr/bin/mesh*"
		vmove usr/libexec/bluetooth/bluetooth-meshd
		vmove usr/share/man/man8/bluetooth-meshd.8
		vmove usr/share/dbus-1/system-services/org.bluez.mesh.service
		vmove usr/share/dbus-1/system.d/bluetooth-mesh.conf
		vsv bluetooth-meshd
		vinstall mesh/bluetooth-mesh.conf 644 etc/bluetooth
		vinstall mesh/mesh-main.conf 644 etc/bluetooth
	}
}
