makedepends=(cairo python-cairo python-gobject libusb bluez desktop-file-utils php scons docbook-xsl xmlto dbus qtbase asciidoc python-setuptools)

description="GPS daemon and library to support USB/serial GPS devices"
url="http://catb.org/gpsd/"

packager="Great-OS Team"
maintainer="Great-OS Team"

name=gpsd
version=3.27.3
release=5

source=(https://download.savannah.gnu.org/releases/$name/$name-$version.tar.gz)

build() {
  cd $name-$version

  export LINKFLAGS="${LDFLAGS}"
  
  _pythonpath=$(python3 -c "from sysconfig import get_path; print(get_path('platlib'))")

  scons prefix=/usr \
        systemd=yes \
        qt_versioned=5 \
        python_libdir=${_pythonpath} \
        gpsd_group=uucp \
        sbindir=/usr/bin
  
  scons build
}

package() {
  cd $name-$version

  export DESTDIR=$PKG
  
  scons install
  
  install -Dm755 gpsinit -t $PKG/usr/bin
  
  chmod 755 $PKG/usr/bin/*

  mkdir -p $PKG/etc/gpsd

  cat > $PKG/etc/gpsd/gpsd.conf << "EOF"
# Default settings for gpsd.
START_DAEMON="true"
GPSD_OPTIONS=""
DEVICES=""
USBAUTO="true"
EOF

  install -Dm644 $name-$version/gpsd.rules $PKG/usr/lib/udev/rules.d/25-gpsd-usb.rules

  install -Dm755 gpsd.hotplug $PKG/usr/lib/udev/gpsd.hotplug

  install -Dm644 packaging/X11/xgps.desktop \
    $PKG/usr/share/applications/xgps.desktop
  
  install -Dm644 packaging/X11/xgpsspeed.desktop \
    $PKG/usr/share/applications/xgpsspeed.desktop
  
  install -Dm644 packaging/X11/gpsd-logo.png \
    $PKG/usr/share/gpsd/gpsd-logo.png

  install -Dm644 $name-$version/systemd/gpsd.service "${PKG}"/usr/lib/systemd/system/gpsd.service
  install -Dm644 $name-$version/systemd/gpsd.socket "${PKG}"/usr/lib/systemd/system/gpsd.socket
  install -Dm644 $name-$version/systemd/gpsdctl@.service "${PKG}"/usr/lib/systemd/system/gpsdctl@.service
}
