# Contributor: Stefan Reiff <kroko87@hotmail.com>
# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Taner Tas <taner76@gmail.com>
pkgname=vdr
pkgver=2.6.1
pkgrel=6
pkgdesc="Video Disk Recorder"
url="http://www.tvdr.de/"
arch="all"
license="GPL-2.0-or-later"
depends_dev="
	alsa-lib-dev
	fontconfig-dev
	freetype-dev
	fribidi-dev
	gettext-dev
	jansson-dev
	libcap-dev
	libcdio-dev
	libdvbcsa-dev
	libexif-dev
	libjpeg-turbo-dev
	libva-dev
	libvdpau-dev
	libwebsockets-dev
	libx11-dev
	mpv-dev
	ncurses-dev
	openssl-dev
	tinyxml2-dev
	xcb-util-dev
	xcb-util-wm-dev
	"
makedepends="$depends_dev bash coreutils groff perl util-linux"
install="$pkgname.pre-install"
pkgusers="$pkgname"
pkggroups="$pkgname"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-openrc
	$pkgname-femon
	$pkgname-mpv
	$pkgname-epgsearch
	$pkgname-streamdev
	$pkgname-vnsiserver
	$pkgname-dvbapi
	$pkgname-svdrpservice
	$pkgname-vdrmanager
	$pkgname-skincurses
	$pkgname-osd2web"
#no testsuite available
options="!check"

_femon_ver=ff59839f7d5246b286d12352c3e67fc96f698e9a
_mpv_ver=ec5770edf16cdeb0a30bf1189a8dc6af60c8d101
_vnsiserver_ver=47a90dd9298753083a9a6482bb9990ea9a88aa7a
_streamdev_ver=da74779591827ad7e10493b0eade65a11c525171
_epgsearch_ver=76d2b108bf17fde2a98e021c8bbfecb1a9a7e92e
_dvbapi_ver=e6b639442f75413a09cd5556750983c4ca382062
_svdrpservice_ver=1.0.0
_vdrmanager_ver=3a8b944ee18ae2db7e60bce1fb600d2b0ce6428c
_osd2web_ver=25309c0723ba9060ebd5a2dab26899523c94dc22

_confd_dir=etc/vdr/conf.d
_plugins_conf_dir=etc/vdr/plugins

source="$pkgname-$pkgver.tar.bz2::http://git.tvdr.de/?p=vdr.git;a=snapshot;h=refs/tags/$pkgver;sf=tbz2
	$pkgname.initd
	conf.d/00-vdr.conf
	vdr-plugin-femon-$_femon_ver.tar.gz::https://github.com/rofafor/vdr-plugin-femon/archive/$_femon_ver.tar.gz
	conf.d/femon.conf
	vdr-plugin-mpv-$_mpv_ver.tar.gz::https://github.com/vdr-projects/vdr-plugin-mpv/archive/$_mpv_ver.tar.gz
	conf.d/mpv.conf
	vdr-plugin-vnsiserver-$_vnsiserver_ver.tar.gz::https://github.com/mdre77/vdr-plugin-vnsiserver/archive/$_vnsiserver_ver.tar.gz
	conf.d/vnsiserver.conf
	vdr-plugin-streamdev-$_streamdev_ver.tar.gz::https://github.com/vdr-projects/vdr-plugin-streamdev/archive/$_streamdev_ver.tar.gz
	conf.d/streamdev-server.conf
	vdr-plugin-epgsearch-$_epgsearch_ver-2.tar.gz::https://github.com/vdr-projects/vdr-plugin-epgsearch/archive/$_epgsearch_ver.tar.gz
	conf.d/conflictcheckonly.conf
	conf.d/epgsearch.conf
	conf.d/epgsearchonly.conf
	conf.d/quickepgsearch.conf
	vdr-plugin-dvbapi-$_dvbapi_ver.tar.gz::https://github.com/manio/vdr-plugin-dvbapi/archive/$_dvbapi_ver.tar.gz
	conf.d/dvbapi.conf
	vdr-plugin-svdrpservice-2-$_svdrpservice_ver.tar.gz::https://github.com/vdr-projects/vdr-plugin-svdrpservice/archive/refs/tags/$_svdrpservice_ver.tar.gz
	conf.d/svdrpservice.conf
	vdr-plugin-vdrmanager--$_vdrmanager_ver-2.tar.gz::https://github.com/vdr-projects/vdr-plugin-vdrmanager/archive/$_vdrmanager_ver.tar.gz
	vdr-plugin-osd2web-$_osd2web_ver.tar.gz::https://github.com/horchi/vdr-plugin-osd2web/archive/$_osd2web_ver.tar.gz
	conf.d/osd2web.conf
	musl-compat.patch
	Make.config
	include-missing-limits.patch
	streamdev_makefile.patch
	osd2web.patch
	no-execinfo.patch
	"

prepare() {
	cp -aP "$srcdir"/vdr-plugin-femon-$_femon_ver "$builddir"/PLUGINS/src/femon
	cp -aP "$srcdir"/vdr-plugin-mpv-$_mpv_ver "$builddir"/PLUGINS/src/mpv
	cp -aP "$srcdir"/vdr-plugin-vnsiserver-$_vnsiserver_ver "$builddir"/PLUGINS/src/vnsiserver
	cp -aP "$srcdir"/vdr-plugin-streamdev-$_streamdev_ver "$builddir"/PLUGINS/src/streamdev
	cp -aP "$srcdir"/vdr-plugin-epgsearch-$_epgsearch_ver "$builddir"/PLUGINS/src/epgsearch
	cp -aP "$srcdir"/vdr-plugin-dvbapi-$_dvbapi_ver "$builddir"/PLUGINS/src/dvbapi
	cp -aP "$srcdir"/vdr-plugin-svdrpservice-$_svdrpservice_ver "$builddir"/PLUGINS/src/svdrpservice
	cp -aP "$srcdir"/vdr-plugin-vdrmanager-$_vdrmanager_ver/vdr-vdrmanager "$builddir"/PLUGINS/src/vdrmanager
	cp -aP "$srcdir"/vdr-plugin-osd2web-$_osd2web_ver "$builddir"/PLUGINS/src/osd2web
	default_prepare
}

build() {
	cp "$srcdir"/Make.config "$builddir"
	case "$CARCH" in
		x86*) make ;;
		*) make LIBDVBCSA=1 ;;
	esac
}

femon() {
	_plugin_defaults femon
}

mpv() {
	_plugin_defaults mpv
}

vnsiserver() {
	_plugin_defaults vnsiserver
	mkdir -p "$subpkgdir/$_plugins_conf_dir"
	cp -a "$builddir"/PLUGINS/src/vnsiserver/vnsiserver "$subpkgdir/$_plugins_conf_dir"
}

streamdev() {
	_plugin_defaults streamdev-client streamdev-server
	mkdir -p "$subpkgdir/$_plugins_conf_dir"
	cp -a "$builddir"/PLUGINS/src/streamdev/streamdev-server "$subpkgdir/$_plugins_conf_dir"
}

epgsearch() {
	_plugin_defaults conflictcheckonly epgsearch epgsearchonly quickepgsearch
	mkdir -p "$subpkgdir/$_plugins_conf_dir"
	mv "$_plugins_conf_dir"/epgsearch "$subpkgdir/$_plugins_conf_dir"
}

dvbapi() {
	_plugin_defaults dvbapi
}

svdrpservice() {
	_plugin_defaults svdrpservice
}

vdrmanager() {
	_plugin_defaults vdrmanager
	mkdir -p "$subpkgdir/$_confd_dir"
	sed '1s/^/[vdrmanager]\n/' "$srcdir"/vdr-plugin-vdrmanager-$_vdrmanager_ver/vdr-vdrmanager/examples/plugin.vdrmanager.conf \
		> "$subpkgdir/$_confd_dir"/vdrmanager.conf
}

osd2web() {
	_plugin_defaults osd2web
	mkdir -p "$subpkgdir/$_confd_dir"
	mkdir -p "$subpkgdir/$_plugins_conf_dir"
	mv "$_plugins_conf_dir"/osd2web "$subpkgdir/$_plugins_conf_dir"
}

skincurses() {
	_plugin_defaults skincurses
}

package() {
	case "$CARCH" in
		x86*) make -j1 DESTDIR="$pkgdir" install ;;
		*) make -j1 LIBDVBCSA=1 DESTDIR="$pkgdir" install ;;
	esac
	install -D -m755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 $srcdir/00-vdr.conf \
		"$pkgdir"/$_confd_dir/00-vdr.conf
	chown -R $pkgusers:$pkggroups "$pkgdir"/etc/vdr \
		"$pkgdir"/var/cache/vdr "$pkgdir"/var/lib/vdr/video
}

_plugin_defaults() {
	depends="$pkgname=$pkgver-r$pkgrel"
	cd "$pkgdir"
	mkdir -p "$subpkgdir"/usr/lib/vdr
	local plugin_name
	for plugin_name in "$@"; do
		if [ -f "$srcdir"/$plugin_name.conf ]; then
			install -D -m644 "$srcdir"/$plugin_name.conf \
				"$subpkgdir"/$_confd_dir/$plugin_name.conf
		fi
		local x
		for x in $plugin_name; do
			if [ -e "$x" ]; then
				mv "$x" "$subpkgdir"/usr/lib/vdr/
			fi
		done
	done
}

sha512sums="
235ffd1654d8f13ba658533bfa5db9c9669e93106a63a770297997f9b8342807f270f26e7a6f5a3c127cd9f760bb94ae77f884dcad42a500615c28e1cf3fd92f  vdr-2.6.1.tar.bz2
52a6221096f543d7af76f14d1e9227bd9a84151eb1c41654c048f5fcb95759e4d98639ba84921c3306742815f4ee3ba8f93ac1799215cfb1a19370b84f80041f  vdr.initd
43502a337324910c8f5db71097336b55a7a58629f201f3a5032397e406ddaf631c647f64220241a84b2eb1b2e0e85af05fa1b017d3d05732c643a754455609d2  00-vdr.conf
d54f74b0a8db0e606f9f3ba8c94c867e36aaabb103763810075659af86aae477dd7d0f5f5aaa0f668025dd73e3d1549084feb28c62b8c4d156597a78d03e45da  vdr-plugin-femon-ff59839f7d5246b286d12352c3e67fc96f698e9a.tar.gz
c80295dd6b4d27eed0639131e104bd071ea3ff55503fc5fdbed4e7668221775a062d37d9e4ff322e4cdc554f0f4ba29adbe3f6424504a74c93f5d302f8f0a904  femon.conf
2730167a06746288568b38cc4318178c47743131c92a2ef7b44b5b35f8152bd027b17f164c0e3c99855a2f5c4dcec6761545ff2e8721559ab253fcde7756f970  vdr-plugin-mpv-ec5770edf16cdeb0a30bf1189a8dc6af60c8d101.tar.gz
c3663b890af2be949e4faffac1ccc1064bb377aa3ba85b4d136ce71db3a1c49b01e9c327e13cd5d02c3d0d850677c3f97a42628957738c17a74d04ec86950bdf  mpv.conf
583881ec7bdadf43f9b32327d52aa86a201a1fe027ccc7b983d5f1016966deaad3fd321f77572dd3159358978b08a01f8b48ebf6455a9939ae6a84db78c95149  vdr-plugin-vnsiserver-47a90dd9298753083a9a6482bb9990ea9a88aa7a.tar.gz
f5672a2929c1ba177a8223dd071b5968bd0fa3f56ac9e0a267dc596adf8884262c239c53e482d3f7c278ce8adaccbb6a179fde704f77160e3a13e8d0a64904b4  vnsiserver.conf
715126df94a98e3e6f13c833344e628f174427eb81371fc8f9cb283b25bde4011f2f555e922710f6443701bf8ea75164c9d709509fbebb98a9505f98dd9d88dc  vdr-plugin-streamdev-da74779591827ad7e10493b0eade65a11c525171.tar.gz
f1aabdb5ab3f9032419dd9cb60bd48402a0f034fb01f7ade2b625cb505719175f245036fae3699f1d0314f48819919e6f7cb48de73d9acf4ef43114504223f48  streamdev-server.conf
ea50764f6552ff724be81fd97f06069064ad131312618844af6ccb7c6e5c4282558e97d35d6104b6259d3f4b06cd351e3ff0c9eafba0277d6a7dc713c7890a4c  vdr-plugin-epgsearch-76d2b108bf17fde2a98e021c8bbfecb1a9a7e92e-2.tar.gz
770c06cd1769da932f2a962cae29e4158992e2510c9e29b7b9cf9e1dccccefcd1b60e22001c60ba6bc05f25ec2a050a8f5299d52f9920bb50ed976a9a8460150  conflictcheckonly.conf
d3046f1a4dd2b2e1166cae05160be835998826f6aa055fc6d53ee81a1f39a7d6297ed23290056dbf51e054fe6b124c52d539b88064c539b8662dba7a780571fa  epgsearch.conf
7b343b0437783bcc6fe6ab1fd46561855c7b84d9886d2a339622635461831e9db08ebf4f7a5f596e937671fd9cad8e2d3952f61dd438f12f08604698a78f43b8  epgsearchonly.conf
f9c1cc50297b5210aa31b92b17769d4afe20ca0f9f15e190f6e34033b1e2c89a37e332e9f2e9fe4b18e98cc3f4558e3175b59b6b33253fe914bcee689656ed7d  quickepgsearch.conf
a48f966e7ffe4a42fd51ff74b8b71e59ca6ed326d5d189710514602bf2fff3411a2939fb75f1795dcc7c5f28b0c50eceddeb1ce9f83093f50441f252f5c26a19  vdr-plugin-dvbapi-e6b639442f75413a09cd5556750983c4ca382062.tar.gz
7cdf36a2b6b3c470a1117f057bf233de57d395a899fc98f7941f526bbaf6935f4d5a368b4936db26217c1e39afb30cfdbec889aa4078109e3fa53e776f07d3b9  dvbapi.conf
2cb3928a8d3ba0df57deacfabf3309d3d86a787b4d3fb534d00b4876ca17120da227ba9a5b5dbb27914d8fdfb81a0e2250811b8d8af75e9efd01b01171344369  vdr-plugin-svdrpservice-2-1.0.0.tar.gz
9cffb3d8347cfc1028bf39a3b14202ea0bc85d7944a7b12863998abca55d113c36ad327c159bc56d1f58bbe9c43c7beae2bf5b21ffbab70a5bc6c632b8b7c4eb  svdrpservice.conf
5d1b8057b69dd8c42ebe202514cbc69b2d14c6881d739dd3dd419d01e1fcdaabfc8ce2146c9f6c5ccae72ee804b65aeedaae50d55b226705604362d3b6602059  vdr-plugin-vdrmanager--3a8b944ee18ae2db7e60bce1fb600d2b0ce6428c-2.tar.gz
f2fcf3a8d1dd864200f1efd8bf356b49ab6dd5d8c6428fc821f2ccb476953196391118537fb69b83f54dba33ecd2b467fda88341b02059662d68354402521a93  vdr-plugin-osd2web-25309c0723ba9060ebd5a2dab26899523c94dc22.tar.gz
0a31a07399e37516343d9b3b9b4d6984b91ed34c437dae9ee3377417b601f30f344714ee4965616019be1defccbfc3629a1bea89851fa0c28987674c29796936  osd2web.conf
f47461445515e44f5cdb9c6d3b1bcae323bb83ba3de7c77a3be4d9ac99ed9e76ebe2ee720660c5593fa4b6995366b9d98bf1683f7b8786518a444de7754731ca  musl-compat.patch
a6a78f3d3c5b93e263a51c1a648c46dab776c24f413e33637814b15e198643397ae7e475379814a1d7c6e1f0e986f59cbf78e248ba74ce03789fe9d23020face  Make.config
7715ef27c820d9e7964dcc24dd12288f66fdf0a6db34d0da43cf6f16e2f815f23bd714654ffa9c3b7d28854bd1e0f7f201dcc5320f99556be92dd248b73bb86f  include-missing-limits.patch
d65877bb0b2e983cf7b1c4b9e3ed8e4105c25f6ef4bb3c400255f4a30f7e177aa41d7a89871e2c4e2afae1447d6bbe26e79105d5ca20b8593ea49c35ae048952  streamdev_makefile.patch
76eb4074a4a811da458e5ecf855925d295718228c9467c633054c3c6751494af3e06113a549f212f398485f947fb3a283fafe34c198967ab4e2d5c1bf5419495  osd2web.patch
d93df1645ac60d61cdb22efa2d016e733348ff745f6dffb875ac43123bda12e0a71b4bbc5af8b63d9355bdc364567544421aea870c6d1a24be838ffbfdcba951  no-execinfo.patch
"
