# Maintainer: Anatol Pomozov <anatol.pomozov@gmail.com>

pkgname=shairport-sync
pkgver=4.3.5
pkgrel=4
pkgdesc='Emulates an AirPort Express for the purpose of streaming music from iTunes and compatible iPods and iPhones'
url='https://github.com/mikebrady/shairport-sync'
arch=(x86_64)
license=(GPL)
backup=(etc/shairport-sync.conf)
depends=(openssl avahi libsoxr popt alsa-lib libconfig libpipewire libpulse jack mosquitto)
makedepends=(glib2-devel xmltoman vim) # vim for xxd tool
source=(shairport-sync-$pkgver.zip::https://github.com/mikebrady/shairport-sync/archive/$pkgver.zip
        shairport-sync.sysusers
        remove_useradd.patch)
sha256sums=('7ade79a2dc1d20479279a996da78147194a84fa7cfb0bcd1cba7ddb7fc0f9a7f'
            'bc2d92254910996e837d1c4c7dd81eddfb96a9f5f0cb2faad9fcb0414ea79a1d'
            '3973049b1a92c729efacd3312636a8c7f3d51cd62c7d5af214668c8104378dc6')

prepare() {
  cd shairport-sync-$pkgver

  patch -p1 < ../remove_useradd.patch
}

build() {
  cd shairport-sync-$pkgver

  autoreconf -i -f
  configure_args=(
    --prefix=/usr
    --sysconfdir=/etc
    # Audio Output
    --with-alsa
    --with-pa
    --with-pw
    --with-jack
    --with-stdout
    --with-pipe
    # Audio Options
    --with-soxr
    --with-convolution
    # Metadata
    --with-metadata
    # IPC
    --with-mqtt-client
    --with-dbus-interface
    --with-mpris-interface
    # Zeroconf/Bonjour
    --with-avahi
    --with-dns_sd
    # Misc
    --with-systemd
    --with-ssl=openssl
    --with-configfiles
    --with-pkg-config
  )
  ./configure "${configure_args[@]}"
  make

  sed 's|/usr/local/bin/|/usr/bin/|' -i scripts/shairport-sync.service.in
}

package() {
  cd shairport-sync-$pkgver
  make DESTDIR="$pkgdir" install
  install -D -m644 "$srcdir"/shairport-sync.sysusers "$pkgdir"/usr/lib/sysusers.d/shairport-sync.conf
  install -D -m664 LICENSES "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  rm "$pkgdir"/etc/shairport-sync.conf.sample
}
