1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: vdr-plugin-2.eclass
6 # Gentoo VDR Project <vdr@gentoo.org>
8 # Matthias Schwarzott <zzam@gentoo.org>
9 # Joerg Bornkessel <hd_brummy@gentoo.org>
10 # Christian Ruppert <idl0r@gentoo.org>
11 # (undisclosed contributors)
12 # @SUPPORTED_EAPIS: 5 6 7
13 # @BLURB: common vdr plugin ebuild functions
15 # Eclass for easing maintenance of vdr plugin ebuilds
17 # @ECLASS-VARIABLE: VDR_CONFD_FILE
20 # A plugin config file can be specified through the $VDR_CONFD_FILE variable, it
21 # defaults to ${FILESDIR}/confd. Each config file will be installed as e.g.
22 # ${D}/etc/conf.d/vdr.${VDRPLUGIN}
24 # @ECLASS-VARIABLE: VDR_RCADDON_FILE
27 # Installing rc-addon files is basically the same as for plugin config files
28 # (see above), it's just using the $VDR_RCADDON_FILE variable instead.
29 # The default value when $VDR_RCADDON_FILE is undefined is:
30 # ${FILESDIR}/rc-addon.sh and will be installed as
31 # ${VDR_RC_DIR}/plugin-${VDRPLUGIN}.sh
33 # The rc-addon files will be sourced by the startscript when the specific plugin
35 # rc-addon files may be used to prepare everything that is necessary for the
36 # plugin start/stop, like passing extra command line options and so on.
38 # NOTE: rc-addon files must be valid shell scripts!
40 # @ECLASS-VARIABLE: GENTOO_VDR_CONDITIONAL
43 # This is a hack for ebuilds like vdr-xineliboutput that want to
44 # conditionally install a vdr-plugin
46 # @ECLASS-VARIABLE: PO_SUBDIR
49 # By default, translation are found in"${S}"/po but this
50 # default can be overridden by defining PO_SUBDIR.
54 # PO_SUBDIR="bla foo/bla"
57 # @FUNCTION: fix_vdr_libsi_include
59 # Plugins failed on compile with wrong path of libsi includes,
60 # this can be fixed by 'function + space separated list of files'
64 # fix_vdr_libsi_include bla.c foo.c
67 # @FUNCTION: vdr_remove_i18n_include
69 # Compile will fail if plugin still use the old i18n language handling,
70 # most parts are fixed by vdr-plugin-2.eclass internal functions itself.
71 # Remove unneeded i18.n includes from files, if they are still wrong there,
72 # this can be fixed by 'function + space separated list of files"
76 # vdr_remove_i18n_include bla.n foo.n
79 # Applying your own local/user patches:
80 # This is done by using the
81 # (EAPI = 5) epatch_user() function of the eutils.eclass,
82 # (EAPI = 6,7) eapply_user function integrated in EAPI = 6.
83 # Simply add your patches into one of these directories:
84 # /etc/portage/patches/<CATEGORY>/<PF|P|PN>/
85 # Quote: where the first of these three directories to exist will be the one to
86 # use, ignoring any more general directories which might exist as well.
88 # For more details about it please take a look at the eutils.class.
90 [[ ${EAPI} == [5] ]] && inherit multilib
91 [[ ${EAPI} == [56] ]] && inherit eutils
92 inherit flag-o-matic toolchain-funcs unpacker
97 *) die "EAPI ${EAPI} unsupported."
101 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm pkg_config
105 # Name of the plugin stripped from all vdrplugin-, vdr- and -cvs pre- and postfixes
106 VDRPLUGIN="${PN/#vdrplugin-/}"
107 VDRPLUGIN="${VDRPLUGIN/#vdr-/}"
108 VDRPLUGIN="${VDRPLUGIN/%-cvs/}"
110 DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin-2.eclass)"
112 # Works in most cases
113 S="${WORKDIR}/${VDRPLUGIN}-${PV}"
115 # depend on headers for DVB-driver
116 COMMON_DEPEND=">=media-tv/gentoo-vdr-scripts-0.4.2"
118 DEPEND="${COMMON_DEPEND}
119 virtual/linuxtv-dvb-headers"
120 RDEPEND="${COMMON_DEPEND}
121 >=app-eselect/eselect-vdr-0.0.2"
123 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]]; then
125 DEPEND="vdr? ( ${DEPEND} )"
126 RDEPEND="vdr? ( ${RDEPEND} )"
129 # New method of storing plugindb
130 # Called from src_install
131 # file maintained by normal portage-methods
132 vdr_create_plugindb_file() {
133 local NEW_VDRPLUGINDB_DIR=/usr/share/vdr/vdrplugin-rebuild/
134 local DB_FILE="${NEW_VDRPLUGINDB_DIR}/${CATEGORY}-${PF}"
135 insinto "${NEW_VDRPLUGINDB_DIR}"
137 # BUG: portage-2.1.4_rc9 will delete the EBUILD= line, so we cannot use this code.
138 # cat <<-EOT > "${D}/${DB_FILE}"
141 # EBUILD=${CATEGORY}/${PN}
144 # obsolet? fix me later...
146 echo "VDRPLUGIN_DB=1"
147 echo "CREATOR=ECLASS"
148 echo "EBUILD=${CATEGORY}/${PN}"
149 echo "EBUILD_V=${PVR}"
150 echo "PLUGINS=\"$@\""
151 } > "${D%/}/${DB_FILE}"
154 vdr_create_header_checksum_file() {
155 # Danger: Not using $ROOT here, as compile will also not use it !!!
156 # If vdr in $ROOT and / differ, plugins will not run anyway
158 local CHKSUM="header-md5-vdr"
160 if [[ -f ${VDR_CHECKSUM_DIR}/header-md5-vdr ]]; then
161 cp "${VDR_CHECKSUM_DIR}/header-md5-vdr" "${CHKSUM}"
162 elif type -p md5sum >/dev/null 2>&1; then
164 cd "${VDR_INCLUDE_DIR}"
165 md5sum *.h libsi/*.h|LC_ALL=C sort --key=2
168 die "Could not create md5 checksum of headers"
171 insinto "${VDR_CHECKSUM_DIR}"
174 newins "${CHKSUM}" "header-md5-${p_name}"
178 fix_vdr_libsi_include() {
179 eqawarn "Fixing include of libsi-headers"
183 -e '/#include/s:"\(.*libsi.*\)":<\1>:' \
184 -e '/#include/s:<.*\(libsi/.*\)>:<vdr/\1>:'
188 vdr_patchmakefile() {
189 einfo "Patching Makefile"
190 [[ -e Makefile ]] || die "Makefile of plugin can not be found!"
191 cp Makefile "${WORKDIR}"/Makefile.before
193 # plugin makefiles use VDRDIR in strange ways
195 # 1. $(VDRDIR) contains Make.config
196 # 2. $(VDRDIR) contains config.h
197 # 3. $(VDRDIR)/include/vdr contains the headers
198 # 4. $(VDRDIR) contains main vdr Makefile
199 # 5. $(VDRDIR)/locale exists
200 # 6. $(VDRDIR) allows to access vdr source files
202 # We only have one directory (for now /usr/include/vdr),
203 # that contains vdr-headers and Make.config.
204 # To satisfy 1-3 we do this:
205 # Set VDRDIR=/usr/include/vdr
206 # Set VDRINCDIR=/usr/include
207 # Change $(VDRDIR)/include to $(VDRINCDIR)
210 -e "s:^VDRDIR.*$:VDRDIR = ${VDR_INCLUDE_DIR}:" \
211 -e "/^VDRDIR/a VDRINCDIR = ${VDR_INCLUDE_DIR%/vdr}" \
212 -e '/VDRINCDIR.*=/!s:$(VDRDIR)/include:$(VDRINCDIR):' \
214 -e 's:-I$(DVBDIR)/include::' \
217 if ! grep -q APIVERSION Makefile; then
218 ebegin " Converting to APIVERSION"
220 -e 's:^APIVERSION = :APIVERSION ?= :' \
221 -e 's:$(LIBDIR)/$@.$(VDRVERSION):$(LIBDIR)/$@.$(APIVERSION):' \
222 -e '/VDRVERSION =/a\APIVERSION = $(shell sed -ne '"'"'/define APIVERSION/s/^.*"\\(.*\\)".*$$/\\1/p'"'"' $(VDRDIR)/config.h)'
226 # Correcting Compile-Flags
227 # Do not overwrite CXXFLAGS, add LDFLAGS if missing
229 -e '/^CXXFLAGS[[:space:]]*=/s/=/?=/' \
230 -e '/LDFLAGS/!s:-shared:$(LDFLAGS) -shared:'
232 # Disabling file stripping, the package manager takes care of it
235 -e '/strip \$(LIBDIR)\/\$@/d' \
236 -e 's/STRIP.*=.*$/STRIP = true/'
238 # Use a file instead of a variable as single-stepping via ebuild
239 # destroys environment.
240 touch "${WORKDIR}"/.vdr-plugin_makefile_patched
243 vdr_gettext_missing() {
244 # plugins without converting to gettext
246 local GETTEXT_MISSING=$( grep xgettext Makefile )
247 if [[ -z ${GETTEXT_MISSING} ]]; then
248 eqawarn "Plugin isn't converted to gettext handling!"
252 vdr_detect_po_dir() {
253 # helper function to find the
254 # DIR ${S}/po or DIR ${S]/_subdir_/po
256 [[ -f po ]] && local po_dir="${S}"
257 local po_subdir=( ${S}/${PO_SUBDIR} )
260 pofile_dir=( ${po_dir} ${po_subdir[*]} )
263 vdr_linguas_support() {
264 # Patching Makefile for linguas support.
265 # Only locales, enabled through the LINGUAS (make.conf) variable will be
266 # compiled and installed.
268 einfo "Patching for Linguas support"
269 einfo "available Languages for ${P} are:"
273 for f in ${pofile_dir[*]}; do
274 if [[ -d ${f}/po ]]; then
275 PLUGIN_LINGUAS=$( ls ${f}/po --ignore="*.pot" | sed -e "s:.po::g" | cut -d_ -f1 | tr \\\012 ' ' )
277 einfo "LINGUAS=\"${PLUGIN_LINGUAS}\""
279 sed -i ${f}/Makefile \
280 -e 's:\$(wildcard[[:space:]]*\$(PODIR)/\*.po):\$(foreach dir,\$(LINGUAS),\$(wildcard \$(PODIR)\/\$(dir)\*.po)):' \
281 || die "sed failed for Linguas"
284 strip-linguas ${PLUGIN_LINGUAS} en
288 # i18n handling was deprecated since >=media-video/vdr-1.5.9,
289 # finally with >=media-video/vdr-1.7.27 it has been dropped entirely and some
290 # plugins will fail to compile because they're still using the old variant.
291 # Simply remove the i18n.o object from Makefile (OBJECT) and
292 # remove "static const tI18nPhrase*" from i18n.h.
296 local I18N_OBJECT=$( grep i18n.o Makefile )
297 if [[ -n ${I18N_OBJECT} ]]; then
299 if [[ "${KEEP_I18NOBJECT:-no}" = "yes" ]]; then
300 eqawarn "Forced to keep i18n.o"
302 sed -i "s:i18n.o::g" Makefile
303 eqawarn "OBJECT i18n.o found, removed per sed"
307 local I18N_STRING=$( [[ -e i18n.h ]] && grep tI18nPhrase i18n.h )
308 if [[ -n ${I18N_STRING} ]]; then
309 sed -i "s:^extern[[:space:]]*const[[:space:]]*tI18nPhrase://static const tI18nPhrase:" i18n.h
310 eqawarn "obsolete tI18nPhrase found, disabled per sed, please recheck"
314 vdr_remove_i18n_include() {
315 # remove uneeded i18.n includes
320 -e "s:^#include[[:space:]]*\"i18n.h\"://:"
323 eqawarn "removed i18n.h include in ${@}"
326 vdr-plugin-2_print_enable_command() {
327 local p_name c=0 l=""
328 for p_name in ${vdr_plugin_list}; do
330 l="$l ${p_name#vdr-}"
335 1) elog "Installed plugin${l}" ;;
336 *) elog "Installed $c plugins:${l}" ;;
338 elog "To activate a plugin execute this command:"
339 elog "\teselect vdr-plugin enable <plugin_name> ..."
344 [[ -f "${VDR_INCLUDE_DIR}"/config.h ]]
347 ## exported functions
349 vdr-plugin-2_pkg_setup() {
350 # missing ${chost}- tag
353 # -fPIC is needed for shared objects on some platforms (amd64 and others)
356 # Plugins need to be compiled with position independent code, otherwise linking
357 # VDR against it will fail
358 append-cxxflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
360 # Where should the plugins live in the filesystem
361 VDR_PLUGIN_DIR=$(pkg-config --variable=libdir vdr)
363 VDR_CHECKSUM_DIR="${VDR_PLUGIN_DIR%/plugins}/checksums"
365 VDR_RC_DIR="/usr/share/vdr/rcscript"
368 VDR_INCLUDE_DIR="/usr/include/vdr"
369 DVB_INCLUDE_DIR="/usr/include"
371 TMP_LOCALE_DIR="${WORKDIR}/tmp-locale"
373 LOCDIR=$(pkg-config --variable=locdir vdr)
376 # set to invalid values to detect abuses
377 VDRVERSION="eclass_no_vdr_installed"
378 APIVERSION="eclass_no_vdr_installed"
380 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]] && ! use vdr; then
381 einfo "VDR not found!"
389 VDRVERSION=$(awk -F'"' '/define VDRVERSION/ {print $2}' "${VDR_INCLUDE_DIR}"/config.h)
390 APIVERSION=$(pkg-config --variable=apiversion vdr)
392 einfo "Compiling against"
393 einfo "\tvdr-${VDRVERSION} [API version ${APIVERSION}]"
395 if [[ -n "${VDR_LOCAL_PATCHES_DIR}" ]]; then
396 eerror "Using VDR_LOCAL_PATCHES_DIR is deprecated!"
397 eerror "Please move all your patches into"
398 eerror "${EROOT%/}/etc/portage/patches/${CATEGORY}/${P}"
399 eerror "and remove or unset the VDR_LOCAL_PATCHES_DIR variable."
404 vdr-plugin-2_src_util() {
408 vdr-plugin-2_src_util unpack add_local_patch patchmakefile linguas_patch i18n
411 vdr-plugin-2_src_util add_local_patch patchmakefile linguas_patch i18n
417 cd "${S}" || die "Could not change to plugin-source-directory (src_util)"
418 if [[ ${EAPI} != [5] ]]; then
425 cd "${S}" || die "Could not change to plugin-source-directory (src_util)"
440 vdr-plugin-2_src_unpack() {
441 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
442 eerror "Wrong use of vdr-plugin-2.eclass."
443 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_unpack."
445 eerror "Please report this at bugs.gentoo.org."
446 die "vdr-plugin-2_src_unpack not called!"
450 vdr-plugin-2_src_util unpack
452 vdr-plugin-2_src_util $@
456 vdr-plugin-2_src_prepare() {
457 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
458 eerror "Wrong use of vdr-plugin-2.eclass."
459 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_prepare."
461 eerror "Please report this at bugs.gentoo.org."
462 die "vdr-plugin-2_src_prepare not called!"
465 [[ ${EAPI} == [5] ]] && [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
466 [[ ${EAPI} != [5] ]] && [[ ${PATCHES[@]} ]] && eapply "${PATCHES[@]}"
468 debug-print "$FUNCNAME: applying user patches"
470 vdr-plugin-2_src_util prepare
473 vdr-plugin-2_src_compile() {
474 [ -z "$1" ] && vdr-plugin-2_src_compile compile
479 if [[ ! -f ${WORKDIR}/.vdr-plugin_makefile_patched ]]; then
480 eerror "Wrong use of vdr-plugin-2.eclass."
481 eerror "An ebuild for a vdr-plugin will not work without"
482 eerror "calling vdr-plugin-2_src_compile to patch the Makefile."
484 eerror "Please report this at bugs.gentoo.org."
485 die "vdr-plugin-2_src_compile not called!"
487 cd "${S}" || die "could not change to plugin source directory (src_compile)"
489 emake all ${BUILD_PARAMS} \
490 LOCALEDIR="${TMP_LOCALE_DIR}" \
491 LOCDIR="${TMP_LOCALE_DIR}" \
494 || die "emake all failed"
502 vdr-plugin-2_src_install() {
503 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
504 eerror "Wrong use of vdr-plugin-2.eclass."
505 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_install."
507 eerror "Please report this at bugs.gentoo.org."
508 die "vdr-plugin-2_src_install not called!"
511 cd "${WORKDIR}" || die "could not change to plugin workdir directory (src_install)"
513 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
514 local mname="${P}-Makefile"
515 cp "${S}"/Makefile "${mname}.patched"
516 cp Makefile.before "${mname}.before"
518 diff -u "${mname}.before" "${mname}.patched" > "${mname}.diff"
520 insinto "/usr/share/vdr/maintainer-data/makefile-changes"
521 doins "${mname}.diff"
523 insinto "/usr/share/vdr/maintainer-data/makefile-before"
524 doins "${mname}.before"
526 insinto "/usr/share/vdr/maintainer-data/makefile-patched"
527 doins "${mname}.patched"
531 cd "${S}" || die "could not change to plugin source directory (src_install)"
533 local SOFILE_STRING=$(grep SOFILE Makefile)
534 if [[ -n ${SOFILE_STRING} ]]; then
539 || die "emake install (makefile target) failed"
541 eqawarn "Plugin use still the old Makefile handling"
542 insinto "${VDR_PLUGIN_DIR}"
546 if [[ -d ${TMP_LOCALE_DIR} ]]; then
547 einfo "Installing locales"
548 cd "${TMP_LOCALE_DIR}" || die "could not change to TMP_LOCALE_DIR"
551 for linguas in ${LINGUAS[*]}; do
553 cp -r --parents ${linguas}* ${D%/}/${LOCDIR}
557 cd "${D%/}/usr/$(get_libdir)/vdr/plugins" || die "could not change to D/usr/libdir/vdr/plugins"
559 # create list of all created plugin libs
562 for p in libvdr-*.so.*; do
564 p_name="${p_name#lib}"
565 vdr_plugin_list="${vdr_plugin_list} ${p_name}"
568 cd "${S}" || die "could not change to plugin source directory (src_install)"
570 vdr_create_header_checksum_file ${vdr_plugin_list}
571 vdr_create_plugindb_file ${vdr_plugin_list}
573 if [[ ${EAPI} != [45] ]]; then
577 for docfile in README* HISTORY CHANGELOG; do
578 [[ -f ${docfile} ]] && dodoc ${docfile}
582 # if VDR_CONFD_FILE is empty and ${FILESDIR}/confd exists take it
583 [[ -z ${VDR_CONFD_FILE} ]] && [[ -e ${FILESDIR}/confd ]] && VDR_CONFD_FILE=${FILESDIR}/confd
585 if [[ -n ${VDR_CONFD_FILE} ]]; then
586 newconfd "${VDR_CONFD_FILE}" vdr.${VDRPLUGIN}
589 # if VDR_RCADDON_FILE is empty and ${FILESDIR}/rc-addon.sh exists take it
590 [[ -z ${VDR_RCADDON_FILE} ]] && [[ -e ${FILESDIR}/rc-addon.sh ]] && VDR_RCADDON_FILE=${FILESDIR}/rc-addon.sh
592 if [[ -n ${VDR_RCADDON_FILE} ]]; then
593 insinto "${VDR_RC_DIR}"
594 newins "${VDR_RCADDON_FILE}" plugin-${VDRPLUGIN}.sh
598 vdr-plugin-2_pkg_postinst() {
599 vdr-plugin-2_print_enable_command
601 if [[ -n "${VDR_CONFD_FILE}" ]]; then
602 elog "Please have a look at the config-file"
603 elog "\t/etc/conf.d/vdr.${VDRPLUGIN}"
608 vdr-plugin-2_pkg_postrm() {
612 vdr-plugin-2_pkg_config() {