--- vdr-plugin.eclass	2012-04-24 01:13:52.000000000 +0200
+++ vdr-plugin-2.eclass	2012-04-25 21:49:53.000000000 +0200
@@ -1,8 +1,8 @@
 # Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/vdr-plugin.eclass,v 1.88 2012/04/23 23:13:52 hd_brummy Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/vdr-plugin-2.eclass,v 1.86 2012/04/07 10:18:24 hd_brummy Exp $
 
-# @ECLASS: vdr-plugin.eclass
+# @ECLASS: vdr-plugin-2.eclass
 # @MAINTAINER:
 # vdr@gentoo.org
 # @BLURB: common vdr plugin ebuild functions
@@ -45,10 +45,12 @@
 
 inherit base multilib eutils flag-o-matic
 
-if ! has "${EAPI:-0}" 0 1 2 3 4; then
-	die "API of vdr-plugin.eclass in EAPI=\"${EAPI}\" not established"
+if ! has "${EAPI:-4}" 4; then
+	die "API of vdr-plugin-2.eclass in EAPI=\"${EAPI}\" not established"
 fi
 
+EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm pkg_config
+
 IUSE=""
 
 # Name of the plugin stripped from all vdrplugin-, vdr- and -cvs pre- and postfixes
@@ -56,9 +58,9 @@
 VDRPLUGIN="${VDRPLUGIN/#vdr-/}"
 VDRPLUGIN="${VDRPLUGIN/%-cvs/}"
 
-DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin.eclass)"
+DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin-2.eclass)"
 
-# works in most cases
+# Works in most cases
 S="${WORKDIR}/${VDRPLUGIN}-${PV}"
 
 # depend on headers for DVB-driver
@@ -69,10 +71,9 @@
 RDEPEND="${COMMON_DEPEND}
 	>=app-admin/eselect-vdr-0.0.2"
 
-# this is a hack for ebuilds like vdr-xineliboutput that want to
+# This is a hack for ebuilds like vdr-xineliboutput that want to
 # conditionally install a vdr-plugin
 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]]; then
-	# make DEPEND conditional
 	IUSE="${IUSE} vdr"
 	DEPEND="vdr? ( ${DEPEND} )"
 	RDEPEND="vdr? ( ${RDEPEND} )"
@@ -102,7 +103,7 @@
 	} > "${D}/${DB_FILE}"
 }
 
-# Delete files created outside of vdr-plugin.eclass
+# Delete files created outside of vdr-plugin-2.eclass
 #   vdrplugin-rebuild.ebuild converted plugindb and files are
 #   not deleted by portage itself - should only be needed as
 #   long as not every system has switched over to
@@ -127,8 +128,7 @@
 }
 
 
-create_header_checksum_file()
-{
+create_header_checksum_file() {
 	# Danger: Not using $ROOT here, as compile will also not use it !!!
 	# If vdr in $ROOT and / differ, plugins will not run anyway
 
@@ -152,9 +152,8 @@
 	done
 }
 
-fix_vdr_libsi_include()
-{
-	#einfo "Fixing include of libsi-headers"
+fix_vdr_libsi_include() {
+	dev_check "Fixing include of libsi-headers"
 	local f
 	for f; do
 		sed -i "${f}" \
@@ -192,7 +191,7 @@
 		-e 's:-I$(DVBDIR)/include::' \
 		-e 's:-I$(DVBDIR)::'
 
-	# maybe needed for multiproto:
+	# may be needed for multiproto:
 	#sed -i Makefile \
 	#	-e "s:^DVBDIR.*$:DVBDIR = ${DVB_INCLUDE_DIR}:" \
 	#	-e 's:-I$(DVBDIR)/include:-I$(DVBDIR):'
@@ -212,7 +211,7 @@
 		-e '/^CXXFLAGS[[:space:]]*=/s/=/?=/' \
 		-e '/LDFLAGS/!s:-shared:$(LDFLAGS) -shared:'
 
-	# Disabling file stripping, useful for debugging
+	# Disabling file stripping, the package manager takes care of it
 	sed -i Makefile \
 		-e '/@.*strip/d' \
 		-e '/strip \$(LIBDIR)\/\$@/d' \
@@ -223,89 +222,94 @@
 	touch "${WORKDIR}"/.vdr-plugin_makefile_patched
 }
 
-vdr_has_gettext() {
-	has_version ">=media-video/vdr-1.5.7"
+# Begin new vdr-plugin-2.eclass content
+dev_check() {
+	# A lot useful debug infos
+	# set VDR_MAINTAINER_MODE="1" in /etc/make.conf
+	if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
+		eerror "\t Maintainer Info: $@"
+	fi
 }
 
-plugin_has_gettext() {
-	[[ -d po ]]
-}
+gettext_missing() {
+	# plugins without converting to gettext
 
-vdr_i18n_convert_to_gettext() {
-	if has_version ">=media-video/vdr-1.7.22"; then
-		local i18n_tool="${ROOT}/usr/share/vdr/bin/i18n-to-gettext"
-	else
-		local i18n_tool="${ROOT}/usr/share/vdr/bin/i18n-to-gettext.pl"
+	local GETTEXT_MISSING=$( grep xgettext Makefile )
+	if [ -z ${GETTEXT_MISSING} ]; then
+		dev_check "Plugin isn't converted to gettext handling \n"
 	fi
+}
 
-	if [[ ${NO_GETTEXT_HACK} == "1" ]]; then
-		ewarn "Conversion to gettext disabled in ebuild"
-		return 1
-	fi
+linguas_support() {
+#	Patching Makefile for linguas support.
+#	Only locales, enabled through the LINGUAS (make.conf) variable will be
+#	"compiled" and installed.
+#
+#	Some plugins have po/ in a subdir
+#	set PO_SUBDIR in .ebuild
+#	i.e media-plugins/vdr-streamdev
+#	PO_SUBDIR="client server"
 
-	if [[ ! -x ${i18n_tool} ]]; then
-		eerror "Missing ${i18n_tool}"
-		eerror "Please re-emerge vdr"
-		die "Missing ${i18n_tool}"
-	fi
+	einfo "Patching for Linguas support"
+	einfo "available Languages for ${P} are:"
+
+	[[ -f po ]] && local po_dir="${S}"
+	local po_subdir=( ${S}/${PO_SUBDIR} )
+	local f
 
-	ebegin "Auto converting translations to gettext"
-	# call i18n-to-gettext tool
-	# take all texts missing tr call into special file
-	"${i18n_tool}" 2>/dev/null \
-		|sed -e '/^"/!d' \
-			-e '/^""$/d' \
-			-e 's/\(.*\)/trNOOP(\1)/' \
-		> dummy-translations-trNOOP.c
+	makefile_dir=( ${po_dir} ${po_subdir[*]} )
 
-	# if there were untranslated texts just run it again
-	# now the missing calls are listed in
-	# dummy-translations-trNOOP.c
-	if [[ -s dummy-translations-trNOOP.c ]]; then
-		"${i18n_tool}" &>/dev/null
-	fi
+	for f in ${makefile_dir[*]}; do
 
-	# now use the modified Makefile
-	if [[ -f Makefile.new ]]; then
-		mv Makefile.new Makefile
-		eend 0 ""
-	else
-		eend 1 "Conversion to gettext failed. Plugin needs fixing."
-		return 1
-	fi
-}
+		PLUGIN_LINGUAS=$( ls ${f}/po | tr \\\012 ' ' | tr -d [:upper:] | tr -d [:punct:] |sed -e "s:po::g" )
+		einfo "LINGUAS=\"${PLUGIN_LINGUAS}\""
 
-vdr_i18n_disable_gettext() {
-	#einfo "Disabling gettext support in plugin"
+		sed -i ${f}/Makefile \
+			-e 's:\$(wildcard[[:space:]]*\$(PODIR)/\*.po):\$(foreach dir,\$(LINGUAS),\$(wildcard \$(PODIR)\/\$(dir)\*.po)):' \
+			|| die "sed failed for Linguas"
+	done
 
-	# Remove i18n Target if using older vdr
-	sed -i Makefile \
-		-e '/^all:/s/ i18n//'
+	# maintainer check
+	if [[ ! -d po ]]; then
+		dev_check "po dir not found? May be in subdir? \n"
+	fi
 }
 
 vdr_i18n() {
-	if vdr_has_gettext; then
-		#einfo "VDR has gettext support"
-		if plugin_has_gettext; then
-			#einfo "Plugin has gettext support, fine"
-			if [[ ${NO_GETTEXT_HACK} == "1" ]]; then
-				ewarn "Please remove unneeded NO_GETTEXT_HACK from ebuild."
-			fi
-		else
-			vdr_i18n_convert_to_gettext
-			if [[ $? != 0 ]]; then
-				einfo "Plugin has no OSD texts or will have only english OSD texts"
-			fi
-		fi
+# 	i18n handling was deprecated since >=media-video/vdr-1.5.9,
+#	finally with >=media-video/vdr-1.7.27 it has been dropped entirely and some
+#	plugins will fail to "compile" because they're still using the old variant.
+#	Simply remove the i18n.o object from Makefile (OBJECT) and
+#	remove "static const tI18nPhrase*" from i18n.h.
+#
+#	Plugins that are still using the old method will be pmasked until they're
+#	fixed or in case of maintainer timeout they'll be masked for removal.
+
+	gettext_missing
+
+	local I18N_OBJECT=$( grep i18n.o Makefile )
+	if [[ -n ${I18N_OBJECT} ]]; then
+		sed -i "s:i18n.o::g" Makefile
+		dev_check "OBJECT i18n.o found"
+		dev_check "removed per sed \n"
 	else
-		#einfo "VDR has no gettext support"
-		if plugin_has_gettext; then
-			vdr_i18n_disable_gettext
-		fi
+		dev_check "OBJECT i18n.o not found in Makefile"
+		dev_check "all fine or manual review needed? \n"
+	fi
+
+	local I18N_STRING=$( [[ -e i18n.h ]] && grep tI18nPhrase i18n.h )
+	if [[ -n ${I18N_STRING} ]]; then
+		sed -i "s:^extern[[:space:]]*const[[:space:]]*tI18nPhrase://static const tI18nPhrase:" i18n.h
+		dev_check "obsolete tI18nPhrase found"
+		dev_check "disabled per sed, please recheck \n"
+	else
+		dev_check "obsolete tI18nPhrase not found, fine..."
+		dev_check "please review, may be in subdir... \n"
 	fi
 }
+# end new vdr-plugin-2.eclass content
 
-vdr-plugin_copy_source_tree() {
+vdr-plugin-2_copy_source_tree() {
 	pushd . >/dev/null
 	cp -r "${S}" "${T}"/source-tree
 	cd "${T}"/source-tree
@@ -319,7 +323,7 @@
 	popd >/dev/null
 }
 
-vdr-plugin_install_source_tree() {
+vdr-plugin-2_install_source_tree() {
 	einfo "Installing sources"
 	destdir="${VDRSOURCE_DIR}/vdr-${VDRVERSION}/PLUGINS/src/${VDRPLUGIN}"
 	insinto "${destdir}-${PV}"
@@ -328,7 +332,7 @@
 	dosym "${VDRPLUGIN}-${PV}" "${destdir}"
 }
 
-vdr-plugin_print_enable_command() {
+vdr-plugin-2_print_enable_command() {
 	local p_name c=0 l=""
 	for p_name in ${vdr_plugin_list}; do
 		c=$(( c+1 ))
@@ -351,7 +355,7 @@
 
 ## exported functions
 
-vdr-plugin_pkg_setup() {
+vdr-plugin-2_pkg_setup() {
 	# -fPIC is needed for shared objects on some platforms (amd64 and others)
 	append-flags -fPIC
 
@@ -397,8 +401,7 @@
 	einfo "Compiling against"
 	einfo "\tvdr-${VDRVERSION} [API version ${APIVERSION}]"
 
-
-	if [ -n "${VDR_LOCAL_PATCHES_DIR}" ]; then
+	if [[ -n "${VDR_LOCAL_PATCHES_DIR}" ]]; then
 		eerror "Using VDR_LOCAL_PATCHES_DIR is deprecated!"
 		eerror "Please move all your patches into"
 		eerror "${EROOT}/etc/portage/patches/${CATEGORY}/${P}"
@@ -407,14 +410,14 @@
 	fi
 }
 
-vdr-plugin_src_util() {
+vdr-plugin-2_src_util() {
 	while [ "$1" ]; do
 		case "$1" in
 		all)
-			vdr-plugin_src_util unpack add_local_patch patchmakefile i18n
+			vdr-plugin-2_src_util unpack add_local_patch patchmakefile linguas_patch i18n
 			;;
-		prepare|all_but_unpack)
-			vdr-plugin_src_util add_local_patch patchmakefile i18n
+		prepare)
+			vdr-plugin-2_src_util add_local_patch patchmakefile linguas_patch i18n
 			;;
 		unpack)
 			base_src_unpack
@@ -428,11 +431,10 @@
 			vdr_patchmakefile
 			;;
 		i18n)
-			# i18n-to-gettext tool removed starting with version 1.7.27
-			if has_version "<media-video/vdr-1.7.27"; then
-				cd "${S}" || die "Could not change to plugin-source-directory!"
-				vdr_i18n
-			fi
+			vdr_i18n
+			;;
+		linguas_patch)
+			linguas_support
 			;;
 		esac
 
@@ -440,51 +442,43 @@
 	done
 }
 
-vdr-plugin_src_unpack() {
+vdr-plugin-2_src_unpack() {
 	if [[ -z ${VDR_INCLUDE_DIR} ]]; then
-		eerror "Wrong use of vdr-plugin.eclass."
-		eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin_pkg_setup."
+		eerror "Wrong use of vdr-plugin-2.eclass."
+		eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_pkg_setup."
 		echo
 		eerror "Please report this at bugs.gentoo.org."
-		die "vdr-plugin_pkg_setup not called!"
+		die "vdr-plugin-2_pkg_setup not called!"
 	fi
-	if [ -z "$1" ]; then
-		case "${EAPI:-0}" in
-			2|3|4)
-				vdr-plugin_src_util unpack
-				;;
-			*)
-				vdr-plugin_src_util all
-				;;
-		esac
 
+	if [ -z "$1" ]; then
+		vdr-plugin-2_src_util unpack
 	else
-		vdr-plugin_src_util $@
+		vdr-plugin-2_src_util $@
 	fi
 }
 
-vdr-plugin_src_prepare() {
+vdr-plugin-2_src_prepare() {
 	base_src_prepare
-	vdr-plugin_src_util prepare
+	vdr-plugin-2_src_util prepare
 }
 
-vdr-plugin_src_compile() {
-	[ -z "$1" ] && vdr-plugin_src_compile copy_source compile
+vdr-plugin-2_src_compile() {
+	[ -z "$1" ] && vdr-plugin-2_src_compile copy_source compile
 
 	while [ "$1" ]; do
-
 		case "$1" in
 		copy_source)
-			[[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin_copy_source_tree
+			[[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin-2_copy_source_tree
 			;;
 		compile)
 			if [[ ! -f ${WORKDIR}/.vdr-plugin_makefile_patched ]]; then
-				eerror "Wrong use of vdr-plugin.eclass."
+				eerror "Wrong use of vdr-plugin-2.eclass."
 				eerror "An ebuild for a vdr-plugin will not work without"
-				eerror "calling vdr-plugin_src_unpack to patch the Makefile."
+				eerror "calling vdr-plugin-2_src_unpack to patch the Makefile."
 				echo
 				eerror "Please report this at bugs.gentoo.org."
-				die "vdr-plugin_src_unpack not called!"
+				die "vdr-plugin-2_src_unpack not called!"
 			fi
 			cd "${S}"
 
@@ -503,8 +497,8 @@
 	done
 }
 
-vdr-plugin_src_install() {
-	[[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin_install_source_tree
+vdr-plugin-2_src_install() {
+	[[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin-2_install_source_tree
 	cd "${WORKDIR}"
 
 	if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
@@ -525,8 +519,6 @@
 
 	fi
 
-
-
 	cd "${S}"
 	insinto "${VDR_PLUGIN_DIR}"
 	doins libvdr-*.so.*
@@ -543,7 +535,7 @@
 	create_header_checksum_file ${vdr_plugin_list}
 	create_plugindb_file ${vdr_plugin_list}
 
-	if vdr_has_gettext && [[ -d ${TMP_LOCALE_DIR} ]]; then
+	if [[ -d ${TMP_LOCALE_DIR} ]]; then
 		einfo "Installing locales"
 		cd "${TMP_LOCALE_DIR}"
 		insinto "${LOCDIR}"
@@ -563,7 +555,6 @@
 		newconfd "${VDR_CONFD_FILE}" vdr.${VDRPLUGIN}
 	fi
 
-
 	# if VDR_RCADDON_FILE is empty and ${FILESDIR}/rc-addon.sh exists take it
 	[[ -z ${VDR_RCADDON_FILE} ]] && [[ -e ${FILESDIR}/rc-addon.sh ]] && VDR_RCADDON_FILE=${FILESDIR}/rc-addon.sh
 
@@ -573,8 +564,8 @@
 	fi
 }
 
-vdr-plugin_pkg_postinst() {
-	vdr-plugin_print_enable_command
+vdr-plugin-2_pkg_postinst() {
+	vdr-plugin-2_print_enable_command
 
 	if [[ -n "${VDR_CONFD_FILE}" ]]; then
 		elog "Please have a look at the config-file"
@@ -583,19 +574,10 @@
 	fi
 }
 
-vdr-plugin_pkg_postrm() {
+vdr-plugin-2_pkg_postrm() {
 	delete_orphan_plugindb_file
 }
 
-vdr-plugin_pkg_config() {
+vdr-plugin-2_pkg_config() {
 :
 }
-
-case "${EAPI:-0}" in
-	2|3|4)
-		EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm pkg_config
-		;;
-	*)
-		EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_postrm pkg_config
-		;;
-esac
