# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jaroslav Lichtblau <svetlemodry@archlinux.org>
# Contributor: Tom Gundersen <teg@jklm.no>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Giacomo Rizzo <alt@free-os.it>

pkgname=gpsd
pkgver=3.25
pkgrel=4
pkgdesc="GPS daemon and library to support USB/serial GPS devices"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="http://catb.org/gpsd/"
license=('BSD')
depends=('dbus'
         'gcc-libs'
         'glibc'
         'python'
         'libusb'
         'bluez-libs'
         'pps-tools')
optdepends=('gtk3: GUI frontends'
            'php: generate a PHP status page for your GPS'
            'php-gd: image support for the PHP status page'
            'python-cairo: GUI frontends'
            'python-gobject: GUI frontends'
            'python-pyserial: GUI frontends'
            'qt5-base: for Qgpsmm')
makedepends=('scons' 'docbook-xsl' 'qt5-base' 'python-gobject' 'python-cairo' 'python-pyserial' 'gtk3' 'python-setuptools')
backup=('etc/default/gpsd')
source=(https://download-mirror.savannah.gnu.org/releases/$pkgname/$pkgname-$pkgver.tar.gz{,.sig}
        $pkgname.conf)
sha256sums=('b368b6a305e3f7a6382d23a0cbfc1d78923060b6b7f54cf7987a73c7b4a9afc2'
            'SKIP'
            'dcfa71c4c730b486269995468bdcfa8e96bf3c282db1dadea9384d32015d277f')
validpgpkeys=('EED4A0893DCC705DB309E202CCF29C7238522905'  # Gary E. Miller <gem@rellim.com>
              'DB239ACA177A35AFBC13F819DD3DD9BBA8F257E8') # Eric S. Raymond

build() {
  cd $pkgname-$pkgver

  export LINKFLAGS="${LDFLAGS}"
  _pythonpath=`python -c "from sysconfig import get_path; print(get_path('platlib'))"`
  scons prefix=/usr \
        systemd=yes \
        gpsd_group=uucp \
        python_libdir=$_pythonpath \
        sbindir=/usr/bin \
        qt_versioned=5
  scons build
}

package() {
  cd $pkgname-$pkgver

  export DESTDIR="${pkgdir}"
  scons install
  install -Dm755 gpsinit -t "${pkgdir}"/usr/bin

  install -Dm644 "$srcdir/gpsd.conf" "${pkgdir}"/etc/default/gpsd

  install -Dm644 gpsd-$pkgver/gpsd.rules "${pkgdir}"/usr/lib/udev/rules.d/25-gpsd-usb.rules

  install -Dm755 gpsd.hotplug -t "${pkgdir}"/usr/lib/udev/

  sed -e 's|/local||' -i packaging/X11/*.desktop
  install -Dm644 packaging/X11/*.desktop -t "${pkgdir}"/usr/share/applications/

  install -Dm644 gpsd-$pkgver/systemd/{gpsd.service,gpsd.socket,gpsdctl@.service} -t "${pkgdir}"/usr/lib/systemd/system/

  install -Dm644 COPYING "${pkgdir}"/usr/share/licenses/$pkgname/LICENSE
}
