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

pkgname=shairport-sync
pkgver=5.0.4
pkgrel=1
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=('9631ec74c1537bdf0b67c0336e1db09c38907e76cd4b4db6d722b661737ef6e0'
            'bc2d92254910996e837d1c4c7dd81eddfb96a9f5f0cb2faad9fcb0414ea79a1d'
            'b10bcba9dbe0988868ceabe1b6e1d6d9dbce385661a76a139f0c365966db45f2')

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-startup
    --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
}
