# Contributor: Nathan Angelacos <nangel@alpinelinux.org>
# Maintainer: Nathan Angelacos <nangel@alpinelinux.org>
pkgname=gpsd
pkgver=3.17
pkgrel=0
pkgdesc="A GPS daemon"
arch=all
url="http://catb.org/gpsd/"
license="BSD"
makedepends="scons python2-dev libcap-dev ncurses-dev"
subpackages="$pkgname-dev"
source="http://download-mirror.savannah.gnu.org/releases/gpsd/$pkgname-$pkgver.tar.gz
	timepps.h
	gpsd-use-local-timepps-header.patch
	ttydefaults.patch
	gpsd.initd
	gpsd.confd"

builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	# We copy timepps.h to the local build directory instead of
	# creating a pps-tools-dev package for ppstime.h
	# (See https://github.com/ago/pps-tools)
	mkdir -p "$builddir"/sys
	cp timepps.h "$builddir"/sys/

	default_prepare
}

build() {
	cd "$builddir"
        CPPFLAGS="-I. -DHAVE_SYS_TIMEPPS_H"
	scons -j1 prefix=/usr 
}

check() {
	cd "$builddir"
	scons check
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib
	cp -a "$builddir"/libgps*.so* "$pkgdir"/usr/lib/

	mkdir -p "$pkgdir"/usr/sbin
	for a in gpsdecode gpsd gpsctl gpsdctl gpspipe; do
		install -m755 -D "$builddir/"$a "$pkgdir"/usr/sbin/
	done

	install -m755 -D "$srcdir"/gpsd.initd "$pkgdir"/etc/init.d/gpsd
	install -m644 -D "$srcdir"/gpsd.confd "$pkgdir"/etc/conf.d/gpsd
}

sha512sums="71085053f600730e0f2de269c59ce0a17ae106ef01403f02d78418b267c6adb9818d541fba59eb23bf71cdb67c5442c82b4948d262ef7e74bb993dcae677a1b1  gpsd-3.17.tar.gz
eb11fc19243d1789016d88eb7645bfe67c46304547781489bf36eb1dd4c252d523681ff835a6488fa0ef62b6b9e2f781c672279f4439f5d5640a3f214a113048  timepps.h
ca534795df3033f15a2cd2f8cc6de5d71608f30418887f31df6dc1db1f283d5cf82920923a1a4adbcaa147e9e32458eee46aed3d64a9a83c950bb83d5e9d4f6e  gpsd-use-local-timepps-header.patch
e2af8f52fc2d7e663882b6d12c5f4d709aa267b16eb9aeca2a70d8ecc681ae72359f3efcd1636cde576bc8579e008f242574bc0adfab7252d3e763f039e86135  ttydefaults.patch
a0e7bf206ad51c31195f86f79ef92adca425d7f988534c0f70a2dd3053613f6fc46820d62d0330aaef7ca100b5f2ab781ce9643f25b4c99c844ae66e7eec5cbc  gpsd.initd
55d4a51f82d445d3ac93b2855132ef4380908ed045feba6298ed1d0b607cd9054b5325c024dc52b370983ebd5d9b377537aee7d7128c97aa22e3075f4134d404  gpsd.confd"
