1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: vdr-plugin-2.eclass
7 # Gentoo VDR Project <vdr@gentoo.org>
9 # Matthias Schwarzott <zzam@gentoo.org>
10 # Joerg Bornkessel <hd_brummy@gentoo.org>
11 # Christian Ruppert <idl0r@gentoo.org>
12 # (undisclosed contributors)
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 # @ECLASS-VARIABLE: VDR_MAINTAINER_MODE
60 # Output from function dev_check if it is defined in ebuild or eclass,
61 # helpfull for gentoo ebuild developer
63 # This will also install any debug files in /usr/share/vdr/maintainer-data
65 # This is intended to be set by user in make.conf. Ebuilds must not set
68 # VDR_MAINTAINER_MODE=1
70 # @FUNCTION: fix_vdr_libsi_include
72 # Plugins failed on compile with wrong path of libsi includes,
73 # this can be fixed by 'function + space separated list of files'
77 # fix_vdr_libsi_include bla.c foo.c
80 # @FUNCTION: remove_i18n_include
82 # Compile will fail if plugin still use the old i18n language handling,
83 # most parts are fixed by vdr-plugin-2.eclass internal functions itself.
84 # Remove unneeded i18.n includes from files, if they are still wrong there,
85 # this can be fixed by 'function + space separated list of files"
89 # remove_i18n_include bla.n foo.n
92 # Applying your own local/user patches:
93 # This is done by using the epatch_user() function of the eutils.eclass.
94 # Simply add your patches into one of these directories:
95 # /etc/portage/patches/<CATEGORY>/<PF|P|PN>/
96 # Quote: where the first of these three directories to exist will be the one to
97 # use, ignoring any more general directories which might exist as well.
99 # For more details about it please take a look at the eutils.class.
101 inherit eutils flag-o-matic multilib toolchain-funcs unpacker
105 *) die "EAPI ${EAPI} unsupported."
108 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm pkg_config
112 # Name of the plugin stripped from all vdrplugin-, vdr- and -cvs pre- and postfixes
113 VDRPLUGIN="${PN/#vdrplugin-/}"
114 VDRPLUGIN="${VDRPLUGIN/#vdr-/}"
115 VDRPLUGIN="${VDRPLUGIN/%-cvs/}"
117 DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin-2.eclass)"
119 # Works in most cases
120 S="${WORKDIR}/${VDRPLUGIN}-${PV}"
122 # depend on headers for DVB-driver
123 COMMON_DEPEND=">=media-tv/gentoo-vdr-scripts-0.4.2"
125 DEPEND="${COMMON_DEPEND}
126 virtual/linuxtv-dvb-headers"
127 RDEPEND="${COMMON_DEPEND}
128 >=app-eselect/eselect-vdr-0.0.2"
130 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]]; then
132 DEPEND="vdr? ( ${DEPEND} )"
133 RDEPEND="vdr? ( ${RDEPEND} )"
136 # New method of storing plugindb
137 # Called from src_install
138 # file maintained by normal portage-methods
139 create_plugindb_file() {
140 local NEW_VDRPLUGINDB_DIR=/usr/share/vdr/vdrplugin-rebuild/
141 local DB_FILE="${NEW_VDRPLUGINDB_DIR}/${CATEGORY}-${PF}"
142 insinto "${NEW_VDRPLUGINDB_DIR}"
144 # BUG: portage-2.1.4_rc9 will delete the EBUILD= line, so we cannot use this code.
145 # cat <<-EOT > "${D}/${DB_FILE}"
148 # EBUILD=${CATEGORY}/${PN}
152 echo "VDRPLUGIN_DB=1"
153 echo "CREATOR=ECLASS"
154 echo "EBUILD=${CATEGORY}/${PN}"
155 echo "EBUILD_V=${PVR}"
156 echo "PLUGINS=\"$@\""
157 } > "${D}/${DB_FILE}"
160 create_header_checksum_file() {
161 # Danger: Not using $ROOT here, as compile will also not use it !!!
162 # If vdr in $ROOT and / differ, plugins will not run anyway
164 local CHKSUM="header-md5-vdr"
166 if [[ -f ${VDR_CHECKSUM_DIR}/header-md5-vdr ]]; then
167 cp "${VDR_CHECKSUM_DIR}/header-md5-vdr" "${CHKSUM}"
168 elif type -p md5sum >/dev/null 2>&1; then
170 cd "${VDR_INCLUDE_DIR}"
171 md5sum *.h libsi/*.h|LC_ALL=C sort --key=2
174 die "Could not create md5 checksum of headers"
177 insinto "${VDR_CHECKSUM_DIR}"
180 newins "${CHKSUM}" "header-md5-${p_name}"
184 fix_vdr_libsi_include() {
185 dev_check "Fixing include of libsi-headers"
189 -e '/#include/s:"\(.*libsi.*\)":<\1>:' \
190 -e '/#include/s:<.*\(libsi/.*\)>:<vdr/\1>:'
194 vdr_patchmakefile() {
195 einfo "Patching Makefile"
196 [[ -e Makefile ]] || die "Makefile of plugin can not be found!"
197 cp Makefile "${WORKDIR}"/Makefile.before
199 # plugin makefiles use VDRDIR in strange ways
201 # 1. $(VDRDIR) contains Make.config
202 # 2. $(VDRDIR) contains config.h
203 # 3. $(VDRDIR)/include/vdr contains the headers
204 # 4. $(VDRDIR) contains main vdr Makefile
205 # 5. $(VDRDIR)/locale exists
206 # 6. $(VDRDIR) allows to access vdr source files
208 # We only have one directory (for now /usr/include/vdr),
209 # that contains vdr-headers and Make.config.
210 # To satisfy 1-3 we do this:
211 # Set VDRDIR=/usr/include/vdr
212 # Set VDRINCDIR=/usr/include
213 # Change $(VDRDIR)/include to $(VDRINCDIR)
216 -e "s:^VDRDIR.*$:VDRDIR = ${VDR_INCLUDE_DIR}:" \
217 -e "/^VDRDIR/a VDRINCDIR = ${VDR_INCLUDE_DIR%/vdr}" \
218 -e '/VDRINCDIR.*=/!s:$(VDRDIR)/include:$(VDRINCDIR):' \
220 -e 's:-I$(DVBDIR)/include::' \
223 # may be needed for multiproto:
225 # -e "s:^DVBDIR.*$:DVBDIR = ${DVB_INCLUDE_DIR}:" \
226 # -e 's:-I$(DVBDIR)/include:-I$(DVBDIR):'
228 if ! grep -q APIVERSION Makefile; then
229 ebegin " Converting to APIVERSION"
231 -e 's:^APIVERSION = :APIVERSION ?= :' \
232 -e 's:$(LIBDIR)/$@.$(VDRVERSION):$(LIBDIR)/$@.$(APIVERSION):' \
233 -e '/VDRVERSION =/a\APIVERSION = $(shell sed -ne '"'"'/define APIVERSION/s/^.*"\\(.*\\)".*$$/\\1/p'"'"' $(VDRDIR)/config.h)'
237 # Correcting Compile-Flags
238 # Do not overwrite CXXFLAGS, add LDFLAGS if missing
240 -e '/^CXXFLAGS[[:space:]]*=/s/=/?=/' \
241 -e '/LDFLAGS/!s:-shared:$(LDFLAGS) -shared:'
243 # Disabling file stripping, the package manager takes care of it
246 -e '/strip \$(LIBDIR)\/\$@/d' \
247 -e 's/STRIP.*=.*$/STRIP = true/'
249 # Use a file instead of a variable as single-stepping via ebuild
250 # destroys environment.
251 touch "${WORKDIR}"/.vdr-plugin_makefile_patched
255 # A lot useful debug infos
256 # set VDR_MAINTAINER_MODE="1" in make.conf
257 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
258 eerror "\t Gentoo Developer Debug: $@"
263 # plugins without converting to gettext
265 local GETTEXT_MISSING=$( grep xgettext Makefile )
266 if [[ -z ${GETTEXT_MISSING} ]]; then
267 dev_check "Plugin isn't converted to gettext handling \n"
274 [[ -f po ]] && local po_dir="${S}"
275 local po_subdir=( ${S}/${PO_SUBDIR} )
278 pofile_dir=( ${po_dir} ${po_subdir[*]} )
282 # Patching Makefile for linguas support.
283 # Only locales, enabled through the LINGUAS (make.conf) variable will be
284 # "compiled" and installed.
286 einfo "Patching for Linguas support"
287 einfo "available Languages for ${P} are:"
291 for f in ${pofile_dir[*]}; do
292 PLUGIN_LINGUAS=$( ls ${f}/po --ignore="*.pot" | sed -e "s:.po::g" | cut -d_ -f1 | tr \\\012 ' ' )
293 einfo "LINGUAS=\"${PLUGIN_LINGUAS}\""
295 sed -i ${f}/Makefile \
296 -e 's:\$(wildcard[[:space:]]*\$(PODIR)/\*.po):\$(foreach dir,\$(LINGUAS),\$(wildcard \$(PODIR)\/\$(dir)\*.po)):' \
297 || die "sed failed for Linguas"
300 strip-linguas ${PLUGIN_LINGUAS} en
304 # i18n handling was deprecated since >=media-video/vdr-1.5.9,
305 # finally with >=media-video/vdr-1.7.27 it has been dropped entirely and some
306 # plugins will fail to "compile" because they're still using the old variant.
307 # Simply remove the i18n.o object from Makefile (OBJECT) and
308 # remove "static const tI18nPhrase*" from i18n.h.
310 # Plugins that are still using the old method will be pmasked until they're
311 # fixed or in case of maintainer timeout they'll be masked for removal.
315 local I18N_OBJECT=$( grep i18n.o Makefile )
316 if [[ -n ${I18N_OBJECT} ]]; then
318 if [[ "${KEEP_I18NOBJECT:-no}" = "yes" ]]; then
319 dev_check "Forced to keep i18n.o"
321 sed -i "s:i18n.o::g" Makefile
322 dev_check "OBJECT i18n.o found"
323 dev_check "removed per sed \n"
327 dev_check "OBJECT i18n.o not found in Makefile"
328 dev_check "all fine or manual review needed? \n"
331 local I18N_STRING=$( [[ -e i18n.h ]] && grep tI18nPhrase i18n.h )
332 if [[ -n ${I18N_STRING} ]]; then
333 sed -i "s:^extern[[:space:]]*const[[:space:]]*tI18nPhrase://static const tI18nPhrase:" i18n.h
334 dev_check "obsolete tI18nPhrase found"
335 dev_check "disabled per sed, please recheck \n"
337 dev_check "obsolete tI18nPhrase not found, fine..."
338 dev_check "please review, may be in subdir... \n"
342 remove_i18n_include() {
343 # remove uneeded i18.n includes
348 -e "s:^#include[[:space:]]*\"i18n.h\"://:"
351 dev_check "removed i18n.h include in ${@}"
354 vdr-plugin-2_print_enable_command() {
355 local p_name c=0 l=""
356 for p_name in ${vdr_plugin_list}; do
358 l="$l ${p_name#vdr-}"
363 1) elog "Installed plugin${l}" ;;
364 *) elog "Installed $c plugins:${l}" ;;
366 elog "To activate a plugin execute this command:"
367 elog "\teselect vdr-plugin enable <plugin_name> ..."
372 [[ -f "${VDR_INCLUDE_DIR}"/config.h ]]
375 ## exported functions
377 vdr-plugin-2_pkg_setup() {
378 # missing ${chost}- tag
381 # -fPIC is needed for shared objects on some platforms (amd64 and others)
384 # Plugins need to be compiled with position independent code, otherwise linking
385 # VDR against it will fail
386 if has_version ">=media-video/vdr-1.7.13"; then
387 append-cxxflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
390 # Where should the plugins live in the filesystem
391 if has_version ">=media-video/vdr-1.7.34"; then
392 VDR_PLUGIN_DIR=$(pkg-config --variable=libdir vdr)
394 # obsolete, as we have only >=media-video/vdr-2
395 VDR_PLUGIN_DIR="/usr/$(get_libdir)/vdr/plugins"
398 VDR_CHECKSUM_DIR="${VDR_PLUGIN_DIR%/plugins}/checksums"
400 # was /usr/lib/... some time ago
401 # since gentoo-vdr-scripts-0.3.6 it works with /usr/share/...
402 VDR_RC_DIR="/usr/share/vdr/rcscript"
405 VDR_INCLUDE_DIR="/usr/include/vdr"
406 DVB_INCLUDE_DIR="/usr/include"
408 TMP_LOCALE_DIR="${WORKDIR}/tmp-locale"
410 if has_version ">=media-video/vdr-1.7.34"; then
411 LOCDIR=$(pkg-config --variable=locdir vdr)
413 # obsolete, as we have only >=media-video/vdr-2
414 LOCDIR="/usr/share/locale"
418 # set to invalid values to detect abuses
419 VDRVERSION="eclass_no_vdr_installed"
420 APIVERSION="eclass_no_vdr_installed"
422 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]] && ! use vdr; then
423 einfo "VDR not found!"
431 if has_version ">=media-video/vdr-1.7.34"; then
432 VDRVERSION=$(awk -F'"' '/define VDRVERSION/ {print $2}' "${VDR_INCLUDE_DIR}"/config.h)
433 APIVERSION=$(pkg-config --variable=apiversion vdr)
435 # obsolete, as we have only >=media-video/vdr-2
436 VDRVERSION=$(awk -F'"' '/define VDRVERSION/ {print $2}' "${VDR_INCLUDE_DIR}"/config.h)
437 APIVERSION=$(awk -F'"' '/define APIVERSION/ {print $2}' "${VDR_INCLUDE_DIR}"/config.h)
438 [[ -z ${APIVERSION} ]] && APIVERSION="${VDRVERSION}"
441 einfo "Compiling against"
442 einfo "\tvdr-${VDRVERSION} [API version ${APIVERSION}]"
444 if [[ -n "${VDR_LOCAL_PATCHES_DIR}" ]]; then
445 eerror "Using VDR_LOCAL_PATCHES_DIR is deprecated!"
446 eerror "Please move all your patches into"
447 eerror "${EROOT}/etc/portage/patches/${CATEGORY}/${P}"
448 eerror "and remove or unset the VDR_LOCAL_PATCHES_DIR variable."
453 vdr-plugin-2_src_util() {
457 vdr-plugin-2_src_util unpack add_local_patch patchmakefile linguas_patch i18n
460 vdr-plugin-2_src_util add_local_patch patchmakefile linguas_patch i18n
466 cd "${S}" || die "Could not change to plugin-source-directory!"
470 cd "${S}" || die "Could not change to plugin-source-directory!"
485 vdr-plugin-2_src_unpack() {
486 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
487 eerror "Wrong use of vdr-plugin-2.eclass."
488 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_unpack."
490 eerror "Please report this at bugs.gentoo.org."
491 die "vdr-plugin-2_src_unpack not called!"
495 vdr-plugin-2_src_util unpack
497 vdr-plugin-2_src_util $@
501 vdr-plugin-2_src_prepare() {
502 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
503 eerror "Wrong use of vdr-plugin-2.eclass."
504 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_prepare."
506 eerror "Please report this at bugs.gentoo.org."
507 die "vdr-plugin-2_src_prepare not called!"
510 [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
511 debug-print "$FUNCNAME: applying user patches"
513 vdr-plugin-2_src_util prepare
516 vdr-plugin-2_src_compile() {
517 [ -z "$1" ] && vdr-plugin-2_src_compile compile
522 if [[ ! -f ${WORKDIR}/.vdr-plugin_makefile_patched ]]; then
523 eerror "Wrong use of vdr-plugin-2.eclass."
524 eerror "An ebuild for a vdr-plugin will not work without"
525 eerror "calling vdr-plugin-2_src_compile to patch the Makefile."
527 eerror "Please report this at bugs.gentoo.org."
528 die "vdr-plugin-2_src_compile not called!"
532 BUILD_TARGETS=${BUILD_TARGETS:-${VDRPLUGIN_MAKE_TARGET:-all }}
533 emake ${BUILD_PARAMS} \
535 LOCALEDIR="${TMP_LOCALE_DIR}" \
536 LOCDIR="${TMP_LOCALE_DIR}" \
539 || die "emake failed"
547 vdr-plugin-2_src_install() {
548 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
549 eerror "Wrong use of vdr-plugin-2.eclass."
550 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_install."
552 eerror "Please report this at bugs.gentoo.org."
553 die "vdr-plugin-2_src_install not called!"
558 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
559 local mname="${P}-Makefile"
560 cp "${S}"/Makefile "${mname}.patched"
561 cp Makefile.before "${mname}.before"
563 diff -u "${mname}.before" "${mname}.patched" > "${mname}.diff"
565 insinto "/usr/share/vdr/maintainer-data/makefile-changes"
566 doins "${mname}.diff"
568 insinto "/usr/share/vdr/maintainer-data/makefile-before"
569 doins "${mname}.before"
571 insinto "/usr/share/vdr/maintainer-data/makefile-patched"
572 doins "${mname}.patched"
578 local SOFILE_STRING=$(grep SOFILE Makefile)
579 if [[ -n ${SOFILE_STRING} ]]; then
580 BUILD_TARGETS=${BUILD_TARGETS:-${VDRPLUGIN_MAKE_TARGET:-install }}
581 einstall ${BUILD_PARAMS} \
585 || die "einstall (makefile target) failed"
587 dev_check "Plugin use still the old Makefile handling"
588 insinto "${VDR_PLUGIN_DIR}"
592 if [[ -d ${TMP_LOCALE_DIR} ]]; then
593 einfo "Installing locales"
594 cd "${TMP_LOCALE_DIR}"
597 for linguas in ${LINGUAS[*]}; do
599 cp -r --parents ${linguas}* ${D}/${LOCDIR}
603 cd "${D}/usr/$(get_libdir)/vdr/plugins"
605 # create list of all created plugin libs
608 for p in libvdr-*.so.*; do
610 p_name="${p_name#lib}"
611 vdr_plugin_list="${vdr_plugin_list} ${p_name}"
616 create_header_checksum_file ${vdr_plugin_list}
617 create_plugindb_file ${vdr_plugin_list}
620 for docfile in README* HISTORY CHANGELOG; do
621 [[ -f ${docfile} ]] && dodoc ${docfile}
624 # if VDR_CONFD_FILE is empty and ${FILESDIR}/confd exists take it
625 [[ -z ${VDR_CONFD_FILE} ]] && [[ -e ${FILESDIR}/confd ]] && VDR_CONFD_FILE=${FILESDIR}/confd
627 if [[ -n ${VDR_CONFD_FILE} ]]; then
628 newconfd "${VDR_CONFD_FILE}" vdr.${VDRPLUGIN}
631 # if VDR_RCADDON_FILE is empty and ${FILESDIR}/rc-addon.sh exists take it
632 [[ -z ${VDR_RCADDON_FILE} ]] && [[ -e ${FILESDIR}/rc-addon.sh ]] && VDR_RCADDON_FILE=${FILESDIR}/rc-addon.sh
634 if [[ -n ${VDR_RCADDON_FILE} ]]; then
635 insinto "${VDR_RC_DIR}"
636 newins "${VDR_RCADDON_FILE}" plugin-${VDRPLUGIN}.sh
640 vdr-plugin-2_pkg_postinst() {
641 vdr-plugin-2_print_enable_command
643 if [[ -n "${VDR_CONFD_FILE}" ]]; then
644 elog "Please have a look at the config-file"
645 elog "\t/etc/conf.d/vdr.${VDRPLUGIN}"
650 vdr-plugin-2_pkg_postrm() {
654 vdr-plugin-2_pkg_config() {