# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: William Pitcock <nenolod@dereferenced.org>
pkgname=pulseaudio
pkgver=9.0
pkgrel=3
pkgdesc="A featureful, general-purpose sound server"
url="http://www.freedesktop.org/wiki/Software/PulseAudio"
arch="all !s390x"
license="LGPL"
makedepends="m4 automake libtool intltool bash
	dbus-dev libcap-dev alsa-lib-dev bluez-dev speexdsp-dev avahi-dev libressl-dev eudev-dev
	libsndfile-dev gtk+3.0-dev json-c-dev fftw-dev gconf-dev sbc-dev jack-dev"
install=""
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-bluez
	$pkgname-alsa $pkgname-utils $pkgname-jack $pkgname-zeroconf $pkgname-system
	$pkgname-bash-completion:bashcomp $pkgname-zsh-completion:zshcomp"
source="http://freedesktop.org/software/pulseaudio/releases/pulseaudio-$pkgver.tar.xz
	0001-padsp-Make-it-compile-on-musl.patch
	$pkgname.initd
	$pkgname.confd"

builddir="$srcdir"/$pkgname-$pkgver

build() {
	cd "$builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-bluez5 \
		--disable-bluez4 \
		--disable-nls \
		--disable-orc \
		|| return 1
	make || return 1
}

package() {
	cd "$builddir"
	make -j1 DESTDIR="$pkgdir" install || return 1
}

system() {
	arch="noarch"
	depends="$pkgname"
	pkgdesc="Pulseaudio system-wide init scripts"
	install -D -m755 "$srcdir"/$pkgname.initd \
		"$subpkgdir"/etc/init.d/$pkgname || return 1
	install -D -m644 "$srcdir"/$pkgname.confd \
		"$subpkgdir"/etc/conf.d/$pkgname || return 1
	mv "$pkgdir"/etc/dbus-1 "$subpkgdir"/etc
}

libs() {
	pkgdesc="Pulseaudio libraries"
	mkdir -p "$subpkgdir"/usr/lib \
		"$subpkgdir"/etc/pulse || return 1
	mv "$pkgdir"/usr/lib/pulseaudio \
		"$subpkgdir"/usr/lib/ || return 1
	mv "$pkgdir"/usr/lib/libpulse.so.0* \
		"$pkgdir"/usr/lib/libpulse-simple.so.0* \
		"$subpkgdir"/usr/lib/ || return 1
	mv "$pkgdir"/etc/pulse/client.conf \
		"$subpkgdir"/etc/pulse/ || return 1
}

bluez() {
	pkgdesc="Pulseaudio bluetooth support"
	mkdir -p "$subpkgdir"/usr/lib/pulse-$pkgver/modules
	mv "$pkgdir"/usr/lib/pulse-$pkgver/modules/*bluez*.so \
		"$pkgdir"/usr/lib/pulse-$pkgver/modules/*bluetooth*.so \
		"$subpkgdir"/usr/lib/pulse-$pkgver/modules/ || return 1
}

alsa() {
	pkgdesc="Pulseaudio alsa support"
	mkdir -p "$subpkgdir"/usr/lib/pulse-$pkgver/modules
	mv "$pkgdir"/usr/lib/pulse-$pkgver/modules/*alsa*.so \
		"$subpkgdir"/usr/lib/pulse-$pkgver/modules/ || return 1
}

utils() {
	pkgdesc="Pulseaudio utilities"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/pa* \
		"$pkgdir"/usr/bin/esdcompat \
		"$subpkgdir"/usr/bin/ || return 1
}

jack() {
	pkgdesc="Pulseaudio jack support"
	mkdir -p "$subpkgdir"/usr/lib/pulse-$pkgver/modules
	mv "$pkgdir"/usr/lib/pulse-$pkgver/modules/*jack*.so \
		"$subpkgdir"/usr/lib/pulse-$pkgver/modules/ || return 1
}

zeroconf() {
	pkgdesc="Pulseaudio zeroconf support"
	mkdir -p "$subpkgdir"/usr/lib/pulse-$pkgver/modules
	mv "$pkgdir"/usr/lib/pulse-$pkgver/modules/*avahi*.so \
		"$pkgdir"/usr/lib/pulse-$pkgver/modules/*zeroconf*.so \
		"$pkgdir"/usr/lib/pulse-$pkgver/modules/*raop*.so \
		"$subpkgdir"/usr/lib/pulse-$pkgver/modules/ || return 1
}

bashcomp() {
	pkgdesc="Bash completion for $pkgname"
	arch="noarch"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"
	install -dm755 "$subpkgdir"/usr/share || return 1
	mv "$pkgdir"/usr/share/bash-completion "$subpkgdir"/usr/share
}

zshcomp() {
	pkgdesc="Zsh completion for $pkgname"
	arch="noarch"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel zsh"
	install -dm755 "$subpkgdir"/usr/share || return 1
	mv "$pkgdir"/usr/share/zsh "$subpkgdir"/usr/share
}

md5sums="da7162541b3a9bc20576dbd0d7d1489a  pulseaudio-9.0.tar.xz
9c04ae15da7464e3d0003840b9025eed  0001-padsp-Make-it-compile-on-musl.patch
884cb9a843361844904e8c85542e72fb  pulseaudio.initd
bf7487ba2c48fc8a56bca41c97a18934  pulseaudio.confd"
sha256sums="c3d3d66b827f18fbe903fe3df647013f09fc1e2191c035be1ee2d82a9e404686  pulseaudio-9.0.tar.xz
bfa722e400ba820ee7013ceb050058b4e239b1ea8544be23767ceb70ee0bc332  0001-padsp-Make-it-compile-on-musl.patch
bbd37d052962ddbf6ae633e4e3896da292d3e916a9123558a9b973096dda842d  pulseaudio.initd
c03661e8cc902d27ff6b52f291207f2b008957571b942abdd92a873a52aae0dd  pulseaudio.confd"
sha512sums="2177d4ab2ab7ded43d6eb5ece763504bdd614f9bdc27ab007894f8f7eed3fd0006a5b7550e5fd099d1877423524bc2baa22775372c8cefd9b772c28134d3e55a  pulseaudio-9.0.tar.xz
25b648681d9397631138635c024b5c6e289e32f11bf222afe4d853f62501555b5d75cc9058023d24ab8f97e442bcb37a647667e01582539d146762912a8ce08e  0001-padsp-Make-it-compile-on-musl.patch
34fe54ece5df60ce63a7955cd828a2716670fef71f40960698ae5518fdaf9cd599f4d8f8852e2c88d715600a9ad06a38984415e5eb320071012e5eb6e5c1b8b1  pulseaudio.initd
75b54581591519d63a3362b155c0f9b0501a60763ab394693a456c44d0216138cf3a40bdd0f7442028663bc045e9ffee286f8f8eaf2ee3bb17379b43615fee0e  pulseaudio.confd"
