# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gsm
pkgver=1.0.22
pkgrel=3
_soname=1.0.12
pkgdesc="Shared libraries for GSM speech compressor"
url="https://www.quut.com/gsm/"
arch="all"
license="TU-Berlin-2.0"
makedepends="$depends_dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-tools"
source="https://www.quut.com/gsm/gsm-$pkgver.tar.gz
	gsm-64bit.patch
	gsm-makefile.patch
	"

builddir="$srcdir"/gsm-${pkgver%.*}-pl${pkgver##*.}

build() {
	export RPM_OPT_FLAGS="$CFLAGS -fPIC"
	make all
}

check() {
	make addtst
}

package() {
	mkdir -p "$pkgdir"/usr/bin \
		"$pkgdir"/usr/include/gsm \
		"$pkgdir"/usr/lib \
		"$pkgdir"/usr/share/man/man1 \
		"$pkgdir"/usr/share/man/man3

	make install \
		INSTALL_ROOT="$pkgdir"/usr \
		GSM_INSTALL_INC="$pkgdir"/usr/include/gsm \
		GSM_INSTALL_LIB="$pkgdir"/usr/lib
	cp -p lib/libgsm.so.$_soname "$pkgdir"/usr/lib/
	ln -s libgsm.so.$_soname "$pkgdir"/usr/lib/libgsm.so.1
	ln -s libgsm.so.$_soname "$pkgdir"/usr/lib/libgsm.so

	# the makefile is really broken
	install -Dm644 inc/gsm.h \
		-t "$pkgdir"/usr/include/gsm/
	ln -s gsm/gsm.h "$pkgdir"/usr/include/gsm.h

	rm -f "$pkgdir"/usr/lib/lib*.a
}

tools() {
	pkgdesc="GSM speech compressor tools"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr
}

sha512sums="
f4284f096ed4d606ddece5c1b28edb63feacc26a0b664f1350c040dbf50113d27bedfd9896bf1620cb4fc3a6c8f6a5244955a6c625ded833dcee607c63c97dd2  gsm-1.0.22.tar.gz
5b01f6d2fd3ee7cd859da70870463e2ccc6614c5fb1bd5efc88a223a0c5477271221557fef13ba46697e70cc5820c13efff738413f8990d5884b95cc89c30152  gsm-64bit.patch
acfb7623a7d66580b704967e335e2c30b9d4ce62226c268f588451d5c8d040846c627fbe77473f4eb0a0c9c144d2dddd75f124e7e91f4ecf0da77039be54b4a9  gsm-makefile.patch
"
