# Maintainer: David P. <megver83@parabola.nu>
# Maintainer (Arch): Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor (Arch): Daniel J Griffiths <ghost1227@archlinux.us>
# Contributor (Arch): Corrado Primier <bardo@aur.archlinux.org>
# Contributor (Arch): William Rea <sillywilly@gmail.com>

_pkgbasename=libpulse
pkgname=lib32-$_pkgbasename
pkgdesc="A featureful, general-purpose sound server (32-bit client libraries)"
pkgver=12.2
pkgrel=1
pkgrel+=.nonsystemd1
arch=(x86_64)
url="https://www.freedesktop.org/wiki/Software/PulseAudio/"
license=(LGPL)
depends=(lib32-dbus lib32-eudev lib32-glib2
         lib32-libasyncns lib32-libcap lib32-libxtst lib32-libsm lib32-libsndfile
         $_pkgbasename)
makedepends=(gcc-multilib libtool-multilib intltool lib32-speexdsp lib32-gtk3 git)
optdepends=('lib32-alsa-plugins: ALSA support')
provides=("lib32-pulseaudio=$pkgver")
conflicts=(lib32-pulseaudio)
replaces=(lib32-pulseaudio)
options=(!emptydirs)
_commit=ee910cf6daa5120ab534eb2e6c573d94b9b182e7  # tags/v12.2^0
source=("git+https://anongit.freedesktop.org/git/pulseaudio/pulseaudio#commit=$_commit")
sha256sums=('SKIP')

_pulsever=$pkgver
[[ $_pulsever = *.*.* ]] && _pulsever=${_pulsever%.*}

_libs="libpulse.la libpulse-simple.la libpulse-mainloop-glib.la"
_pkglibs="libpulsecommon-${_pulsever}.la libpulsedsp.la"

pkgver() {
  cd pulseaudio
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd pulseaudio
  NOCONFIGURE=1 ./bootstrap.sh
}

build() {
  cd pulseaudio

  export CC="gcc -m32"
  export CXX="g++ -m32"
  export PKG_CONFIG_PATH="/usr/lib32/pkgconfig"

  ./configure --prefix=/usr \
    --libdir=/usr/lib32 \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib32 \
    --localstatedir=/var \
    --disable-tcpwrap \
    --disable-bluez4 \
    --disable-samplerate \
    --disable-rpath \
    --disable-default-build-tests \
    --with-systemduserunitdir=no \
    --disable-systemd-login \
    --disable-systemd-daemon \
    --disable-systemd-journal
    DATADIRNAME=share

  # fight unused direct deps
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make -C src $_libs $_pkglibs
}

package() {
  cd pulseaudio
  make -j1 -C src DESTDIR="$pkgdir" \
    lib_LTLIBRARIES="$_libs" install-libLTLIBRARIES
  make -j1 -C src DESTDIR="$pkgdir" \
    pkglib_LTLIBRARIES="$_pkglibs" install-pkglibLTLIBRARIES
  make -j1 DESTDIR="$pkgdir" install-pkgconfigDATA
}
