# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=live-media
pkgver=2017.10.28
pkgrel=0
pkgdesc="A set of C++ libraries for multimedia streaming"
url="http://live555.com/liveMedia"
arch="all"
license="LGPL"
subpackages="$pkgname-dev $pkgname-utils"
options="!check"
source="http://live555.com/liveMedia/public/live.$pkgver.tar.gz"
builddir="$srcdir"/live

prepare() {
	cd "$builddir"
	sed -e "/^COMPILE_OPTS/s/$/ $CFLAGS -fPIC -DPIC -DXLOCALE_NOT_USED=1 -DRTSPCLIENT_SYNCHRONOUS_INTERFACE/" \
		-i config.linux-with-shared-libraries
}

build() {
	cd "$builddir"
	./genMakefiles linux-with-shared-libraries
	make C_COMPILER="${CC:-gcc}" CPLUSPLUS_COMPILER="${CXX:-g++}" \
		|| return 1
}

package() {
	local testprog f so
	cd "$builddir"
	mkdir -p "$pkgdir"/usr/lib
	for f in BasicUsageEnvironment UsageEnvironment liveMedia groupsock; do
		mkdir -p "$pkgdir"/usr/include/$f
		cp $f/include/*.h* "$pkgdir"/usr/include/$f
		cp $f/lib${f}.a "$pkgdir"/usr/lib || true
		for so in $f/lib*.so.*; do
			soname=$(scanelf -B --format "#F%S" $so)
			cp $so "$pkgdir"/usr/lib/ || return 1
			so=${so##*/}
			ln -s ${so} "$pkgdir"/usr/lib/${soname} || return 1
			ln -s ${so} "$pkgdir"/usr/lib/${soname%.so.*}.so || return 1
		done
	done

	mkdir -p "$pkgdir"/usr/bin
	for testprog in `find testProgs -type f -perm 755`; do
		install ${testprog} "$pkgdir"/usr/bin
	done
}

utils() {
	pkgdesc="multimedia RTSP streaming tools"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
}

sha512sums="eea5bdb8d89e76c8b6aeb6ec04b77af3048cb41f228d230ba4da6045e9bc691a456023d44d8650fe690b08143567ed5af5b633f5b6522debff79344a813dc7d0  live.2017.10.28.tar.gz"
