# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gnokii
pkgver=0.6.31
pkgrel=7
pkgdesc="Tools and user space driver for use with mobile phones"
url="http://www.gnokii.org/"
arch="all"
license="GPL"
depends=""
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs xgnokii $pkgname-smsd
	$pkgname-smsd-pgsql:pgsql $pkgname-smsd-mysql:mysql
	$pkgname-smsd-sqlite:sqlite $pkgname-lang"

makedepends="gtk+-dev mariadb-connector-c-dev intltool libusb-compat-dev libxpm-dev
	bluez-dev libical-dev postgresql-dev sqlite-dev
	autoconf automake libtool"
source="http://www.gnokii.org/download/gnokii/gnokii-$pkgver.tar.bz2
	gnokii.patch
	xgnokii.patch
	gnokii-0.6.31-gcc5.patch
	"

_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	cd "$_builddir"
	update_config_sub || return 1
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	autoreconf || return 1
	sed -i 's|cellphone|phone|' xgnokii/xgnokii.desktop.in
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-security \
		--disable-unix98test \
		--disable-phonet \
		--with-x \
		|| return 1
	make
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1
}

libs() {
	pkgdesc="gnokii shared libraries"
	replaces="libgnokii"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/libgnokii.so.* "$subpkgdir"/usr/lib/
}

xgnokii() {
	pkgdesc="Gtk+ gnokii application"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/xgnokii "$subpkgdir"/usr/bin/
}

smsd() {
	pkgdesc="SMS Daemon for mobile phones"
	mkdir -p "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/smsd "$subpkgdir"/usr/bin/
}

pgsql() {
	pkgdesc="SMSD plugin for PostgreSQL storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*pq.so "$subpkgdir"/usr/lib/smsd/
}

mysql() {
	pkgdesc="SMSD plugin for MySQL storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*mysql.so "$subpkgdir"/usr/lib/smsd/
}

sqlite() {
	pkgdesc="SMSD plugin for SQLite storage backend"
	depends="gnokii-smsd"
	mkdir -p "$subpkgdir"/usr/lib/smsd
	mv "$pkgdir"/usr/lib/smsd/*sqlite*.so "$subpkgdir"/usr/lib/smsd/
}
md5sums="d9627f4a1152d3ea7806df4532850d5f  gnokii-0.6.31.tar.bz2
5de7a1c6a59b740df9d24f5c08cea448  gnokii.patch
6b87d13cb012bfdfd3581d89f42a3cff  xgnokii.patch
5bcf2dadd31a826d1f80b53bb37d9bd0  gnokii-0.6.31-gcc5.patch"
sha256sums="8f5a083b05c1a66a3402ca5cd80084e14c2c0632c991bb53b03c78e9adb02501  gnokii-0.6.31.tar.bz2
4bde95dd970c314e2243f3deea9047665802fa09bc5b97ebfa9b5b6c2844af7b  gnokii.patch
08a2df9d843de490969adf44a6a8871f55aa2ad784c24d9cd44894fb203f7770  xgnokii.patch
eafe67990e383e92636a88de27f003674374db81d986ddbb397ab18d82b6556d  gnokii-0.6.31-gcc5.patch"
sha512sums="529f6d0d29873f48ac00cf7151ba35dcbd93405ab27d69848ed17dea73f4fba71721d1811d921441b4214777b9b33f760b372631627cc108eb94c39684da343d  gnokii-0.6.31.tar.bz2
a253cd0a461b06b3d11202f36c518f6364705008c36d4e7ecd292ecd2e4288e42fbd55110405c6bb2d2d82499e047876aa92a9292b629d1323189a9164359d32  gnokii.patch
b7033907d8bca55366b09ef976e1f1e48a31ef2630e55770200fc3818c1a36aa6478bc73cb4f180b469d21157ad5af389dc075280f22251b7402d7ab584f37dc  xgnokii.patch
548a32f93b059e45c8616dedf49a0ce3b0e63463f8ddc3384b473d91bd12c3fab2c6e21de0b09d2b330c189454a2bf3e486aa25122ea58392d9cb11994592086  gnokii-0.6.31-gcc5.patch"
