1 # Copyright 1999-2016 Gentoo Foundation
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 # @BLURB: common vdr plugin ebuild functions
14 # Eclass for easing maintenance of vdr plugin ebuilds
16 # @ECLASS-VARIABLE: VDR_CONFD_FILE
19 # A plugin config file can be specified through the $VDR_CONFD_FILE variable, it
20 # defaults to ${FILESDIR}/confd. Each config file will be installed as e.g.
21 # ${D}/etc/conf.d/vdr.${VDRPLUGIN}
23 # @ECLASS-VARIABLE: VDR_RCADDON_FILE
26 # Installing rc-addon files is basically the same as for plugin config files
27 # (see above), it's just using the $VDR_RCADDON_FILE variable instead.
28 # The default value when $VDR_RCADDON_FILE is undefined is:
29 # ${FILESDIR}/rc-addon.sh and will be installed as
30 # ${VDR_RC_DIR}/plugin-${VDRPLUGIN}.sh
32 # The rc-addon files will be sourced by the startscript when the specific plugin
34 # rc-addon files may be used to prepare everything that is necessary for the
35 # plugin start/stop, like passing extra command line options and so on.
37 # NOTE: rc-addon files must be valid shell scripts!
39 # @ECLASS-VARIABLE: GENTOO_VDR_CONDITIONAL
42 # This is a hack for ebuilds like vdr-xineliboutput that want to
43 # conditionally install a vdr-plugin
45 # @ECLASS-VARIABLE: PO_SUBDIR
48 # By default, translation are found in"${S}"/po but this
49 # default can be overridden by defining PO_SUBDIR.
53 # PO_SUBDIR="bla foo/bla"
56 # @ECLASS-VARIABLE: VDR_MAINTAINER_MODE
59 # Output from function vdr_dev_check if it is defined in ebuild or eclass,
60 # helpfull for gentoo ebuild developer
62 # This will also install any debug files in /usr/share/vdr/maintainer-data
64 # This is intended to be set by user in make.conf. Ebuilds must not set
67 # VDR_MAINTAINER_MODE=1
69 # @FUNCTION: fix_vdr_libsi_include
71 # Plugins failed on compile with wrong path of libsi includes,
72 # this can be fixed by 'function + space separated list of files'
76 # fix_vdr_libsi_include bla.c foo.c
79 # @FUNCTION: vdr_remove_i18n_include
81 # Compile will fail if plugin still use the old i18n language handling,
82 # most parts are fixed by vdr-plugin-2.eclass internal functions itself.
83 # Remove unneeded i18.n includes from files, if they are still wrong there,
84 # this can be fixed by 'function + space separated list of files"
88 # vdr_remove_i18n_include bla.n foo.n
91 # Applying your own local/user patches:
92 # This is done by using the
93 # (EAPI = 4,5) epatch_user() function of the eutils.eclass,
94 # (EAPI = 6) eapply_user function integrated in EAPI = 6.
95 # Simply add your patches into one of these directories:
96 # /etc/portage/patches/<CATEGORY>/<PF|P|PN>/
97 # Quote: where the first of these three directories to exist will be the one to
98 # use, ignoring any more general directories which might exist as well.
100 # For more details about it please take a look at the eutils.class.
102 [[ ${EAPI} == [45] ]] && inherit eutils multilib
103 inherit flag-o-matic toolchain-funcs unpacker
108 *) die "EAPI ${EAPI} unsupported."
112 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_compile src_install pkg_postinst pkg_postrm pkg_config
116 # Name of the plugin stripped from all vdrplugin-, vdr- and -cvs pre- and postfixes
117 VDRPLUGIN="${PN/#vdrplugin-/}"
118 VDRPLUGIN="${VDRPLUGIN/#vdr-/}"
119 VDRPLUGIN="${VDRPLUGIN/%-cvs/}"
121 DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin-2.eclass)"
123 # Works in most cases
124 S="${WORKDIR}/${VDRPLUGIN}-${PV}"
126 # depend on headers for DVB-driver
127 COMMON_DEPEND=">=media-tv/gentoo-vdr-scripts-0.4.2"
129 DEPEND="${COMMON_DEPEND}
130 virtual/linuxtv-dvb-headers"
131 RDEPEND="${COMMON_DEPEND}
132 >=app-eselect/eselect-vdr-0.0.2"
134 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]]; then
136 DEPEND="vdr? ( ${DEPEND} )"
137 RDEPEND="vdr? ( ${RDEPEND} )"
140 # New method of storing plugindb
141 # Called from src_install
142 # file maintained by normal portage-methods
143 vdr_create_plugindb_file() {
144 local NEW_VDRPLUGINDB_DIR=/usr/share/vdr/vdrplugin-rebuild/
145 local DB_FILE="${NEW_VDRPLUGINDB_DIR}/${CATEGORY}-${PF}"
146 insinto "${NEW_VDRPLUGINDB_DIR}"
148 # BUG: portage-2.1.4_rc9 will delete the EBUILD= line, so we cannot use this code.
149 # cat <<-EOT > "${D}/${DB_FILE}"
152 # EBUILD=${CATEGORY}/${PN}
155 # obsolet? fix me later...
157 echo "VDRPLUGIN_DB=1"
158 echo "CREATOR=ECLASS"
159 echo "EBUILD=${CATEGORY}/${PN}"
160 echo "EBUILD_V=${PVR}"
161 echo "PLUGINS=\"$@\""
162 } > "${D}/${DB_FILE}"
165 vdr_create_header_checksum_file() {
166 # Danger: Not using $ROOT here, as compile will also not use it !!!
167 # If vdr in $ROOT and / differ, plugins will not run anyway
169 local CHKSUM="header-md5-vdr"
171 if [[ -f ${VDR_CHECKSUM_DIR}/header-md5-vdr ]]; then
172 cp "${VDR_CHECKSUM_DIR}/header-md5-vdr" "${CHKSUM}"
173 elif type -p md5sum >/dev/null 2>&1; then
175 cd "${VDR_INCLUDE_DIR}"
176 md5sum *.h libsi/*.h|LC_ALL=C sort --key=2
179 die "Could not create md5 checksum of headers"
182 insinto "${VDR_CHECKSUM_DIR}"
185 newins "${CHKSUM}" "header-md5-${p_name}"
189 fix_vdr_libsi_include() {
190 vdr_dev_check "Fixing include of libsi-headers"
194 -e '/#include/s:"\(.*libsi.*\)":<\1>:' \
195 -e '/#include/s:<.*\(libsi/.*\)>:<vdr/\1>:'
199 vdr_patchmakefile() {
200 einfo "Patching Makefile"
201 [[ -e Makefile ]] || die "Makefile of plugin can not be found!"
202 cp Makefile "${WORKDIR}"/Makefile.before
204 # plugin makefiles use VDRDIR in strange ways
206 # 1. $(VDRDIR) contains Make.config
207 # 2. $(VDRDIR) contains config.h
208 # 3. $(VDRDIR)/include/vdr contains the headers
209 # 4. $(VDRDIR) contains main vdr Makefile
210 # 5. $(VDRDIR)/locale exists
211 # 6. $(VDRDIR) allows to access vdr source files
213 # We only have one directory (for now /usr/include/vdr),
214 # that contains vdr-headers and Make.config.
215 # To satisfy 1-3 we do this:
216 # Set VDRDIR=/usr/include/vdr
217 # Set VDRINCDIR=/usr/include
218 # Change $(VDRDIR)/include to $(VDRINCDIR)
221 -e "s:^VDRDIR.*$:VDRDIR = ${VDR_INCLUDE_DIR}:" \
222 -e "/^VDRDIR/a VDRINCDIR = ${VDR_INCLUDE_DIR%/vdr}" \
223 -e '/VDRINCDIR.*=/!s:$(VDRDIR)/include:$(VDRINCDIR):' \
225 -e 's:-I$(DVBDIR)/include::' \
228 # may be needed for multiproto:
230 # -e "s:^DVBDIR.*$:DVBDIR = ${DVB_INCLUDE_DIR}:" \
231 # -e 's:-I$(DVBDIR)/include:-I$(DVBDIR):'
232 # obsolet? fix me later...
234 if ! grep -q APIVERSION Makefile; then
235 ebegin " Converting to APIVERSION"
237 -e 's:^APIVERSION = :APIVERSION ?= :' \
238 -e 's:$(LIBDIR)/$@.$(VDRVERSION):$(LIBDIR)/$@.$(APIVERSION):' \
239 -e '/VDRVERSION =/a\APIVERSION = $(shell sed -ne '"'"'/define APIVERSION/s/^.*"\\(.*\\)".*$$/\\1/p'"'"' $(VDRDIR)/config.h)'
243 # Correcting Compile-Flags
244 # Do not overwrite CXXFLAGS, add LDFLAGS if missing
246 -e '/^CXXFLAGS[[:space:]]*=/s/=/?=/' \
247 -e '/LDFLAGS/!s:-shared:$(LDFLAGS) -shared:'
249 # Disabling file stripping, the package manager takes care of it
252 -e '/strip \$(LIBDIR)\/\$@/d' \
253 -e 's/STRIP.*=.*$/STRIP = true/'
255 # Use a file instead of a variable as single-stepping via ebuild
256 # destroys environment.
257 touch "${WORKDIR}"/.vdr-plugin_makefile_patched
261 # A lot useful debug infos
262 # set VDR_MAINTAINER_MODE="1" in make.conf
263 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
264 eerror "\t Gentoo Developer Debug: $@"
268 vdr_gettext_missing() {
269 # plugins without converting to gettext
271 local GETTEXT_MISSING=$( grep xgettext Makefile )
272 if [[ -z ${GETTEXT_MISSING} ]]; then
273 vdr_dev_check "Plugin isn't converted to gettext handling \n"
277 vdr_detect_po_dir() {
280 [[ -f po ]] && local po_dir="${S}"
281 local po_subdir=( ${S}/${PO_SUBDIR} )
284 pofile_dir=( ${po_dir} ${po_subdir[*]} )
287 vdr_linguas_support() {
288 # Patching Makefile for linguas support.
289 # Only locales, enabled through the LINGUAS (make.conf) variable will be
290 # compiled and installed.
292 einfo "Patching for Linguas support"
293 einfo "available Languages for ${P} are:"
297 for f in ${pofile_dir[*]}; do
298 PLUGIN_LINGUAS=$( ls ${f}/po --ignore="*.pot" | sed -e "s:.po::g" | cut -d_ -f1 | tr \\\012 ' ' )
299 einfo "LINGUAS=\"${PLUGIN_LINGUAS}\""
301 sed -i ${f}/Makefile \
302 -e 's:\$(wildcard[[:space:]]*\$(PODIR)/\*.po):\$(foreach dir,\$(LINGUAS),\$(wildcard \$(PODIR)\/\$(dir)\*.po)):' \
303 || die "sed failed for Linguas"
306 strip-linguas ${PLUGIN_LINGUAS} en
310 # i18n handling was deprecated since >=media-video/vdr-1.5.9,
311 # finally with >=media-video/vdr-1.7.27 it has been dropped entirely and some
312 # plugins will fail to compile because they're still using the old variant.
313 # Simply remove the i18n.o object from Makefile (OBJECT) and
314 # remove "static const tI18nPhrase*" from i18n.h.
318 local I18N_OBJECT=$( grep i18n.o Makefile )
319 if [[ -n ${I18N_OBJECT} ]]; then
321 if [[ "${KEEP_I18NOBJECT:-no}" = "yes" ]]; then
322 vdr_dev_check "Forced to keep i18n.o"
324 sed -i "s:i18n.o::g" Makefile
325 vdr_dev_check "OBJECT i18n.o found"
326 vdr_dev_check "removed per sed \n"
330 vdr_dev_check "OBJECT i18n.o not found in Makefile"
331 vdr_dev_check "all fine or manual review needed? \n"
334 local I18N_STRING=$( [[ -e i18n.h ]] && grep tI18nPhrase i18n.h )
335 if [[ -n ${I18N_STRING} ]]; then
336 sed -i "s:^extern[[:space:]]*const[[:space:]]*tI18nPhrase://static const tI18nPhrase:" i18n.h
337 vdr_dev_check "obsolete tI18nPhrase found"
338 vdr_dev_check "disabled per sed, please recheck \n"
340 vdr_dev_check "obsolete tI18nPhrase not found, fine..."
341 vdr_dev_check "please review, may be in subdir... \n"
345 vdr_remove_i18n_include() {
346 # remove uneeded i18.n includes
351 -e "s:^#include[[:space:]]*\"i18n.h\"://:"
354 vdr_dev_check "removed i18n.h include in ${@}"
357 vdr-plugin-2_print_enable_command() {
358 local p_name c=0 l=""
359 for p_name in ${vdr_plugin_list}; do
361 l="$l ${p_name#vdr-}"
366 1) elog "Installed plugin${l}" ;;
367 *) elog "Installed $c plugins:${l}" ;;
369 elog "To activate a plugin execute this command:"
370 elog "\teselect vdr-plugin enable <plugin_name> ..."
375 [[ -f "${VDR_INCLUDE_DIR}"/config.h ]]
378 ## exported functions
380 vdr-plugin-2_pkg_setup() {
381 # missing ${chost}- tag
384 # -fPIC is needed for shared objects on some platforms (amd64 and others)
387 # Plugins need to be compiled with position independent code, otherwise linking
388 # VDR against it will fail
389 # depricated if fi, as we have only >=vdr-2 in the tree, fix me later...
390 if has_version ">=media-video/vdr-1.7.13"; then
391 append-cxxflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
394 # Where should the plugins live in the filesystem
395 VDR_PLUGIN_DIR=$(pkg-config --variable=libdir vdr)
397 VDR_CHECKSUM_DIR="${VDR_PLUGIN_DIR%/plugins}/checksums"
399 VDR_RC_DIR="/usr/share/vdr/rcscript"
402 VDR_INCLUDE_DIR="/usr/include/vdr"
403 DVB_INCLUDE_DIR="/usr/include"
405 TMP_LOCALE_DIR="${WORKDIR}/tmp-locale"
407 LOCDIR=$(pkg-config --variable=locdir vdr)
410 # set to invalid values to detect abuses
411 VDRVERSION="eclass_no_vdr_installed"
412 APIVERSION="eclass_no_vdr_installed"
414 if [[ "${GENTOO_VDR_CONDITIONAL:-no}" = "yes" ]] && ! use vdr; then
415 einfo "VDR not found!"
423 VDRVERSION=$(awk -F'"' '/define VDRVERSION/ {print $2}' "${VDR_INCLUDE_DIR}"/config.h)
424 APIVERSION=$(pkg-config --variable=apiversion vdr)
426 einfo "Compiling against"
427 einfo "\tvdr-${VDRVERSION} [API version ${APIVERSION}]"
429 if [[ -n "${VDR_LOCAL_PATCHES_DIR}" ]]; then
430 eerror "Using VDR_LOCAL_PATCHES_DIR is deprecated!"
431 eerror "Please move all your patches into"
432 eerror "${EROOT}/etc/portage/patches/${CATEGORY}/${P}"
433 eerror "and remove or unset the VDR_LOCAL_PATCHES_DIR variable."
438 vdr-plugin-2_src_util() {
442 vdr-plugin-2_src_util unpack add_local_patch patchmakefile linguas_patch i18n
445 vdr-plugin-2_src_util add_local_patch patchmakefile linguas_patch i18n
451 cd "${S}" || die "Could not change to plugin-source-directory (src_util)"
452 if [[ ${EAPI} != [45] ]]; then
459 cd "${S}" || die "Could not change to plugin-source-directory (src_util)"
474 vdr-plugin-2_src_unpack() {
475 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
476 eerror "Wrong use of vdr-plugin-2.eclass."
477 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_unpack."
479 eerror "Please report this at bugs.gentoo.org."
480 die "vdr-plugin-2_src_unpack not called!"
484 vdr-plugin-2_src_util unpack
486 vdr-plugin-2_src_util $@
490 vdr-plugin-2_src_prepare() {
491 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
492 eerror "Wrong use of vdr-plugin-2.eclass."
493 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_prepare."
495 eerror "Please report this at bugs.gentoo.org."
496 die "vdr-plugin-2_src_prepare not called!"
499 [[ ${EAPI} == [45] ]] && [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
500 [[ ${EAPI} != [45] ]] && [[ ${PATCHES[@]} ]] && eapply "${PATCHES[@]}"
502 debug-print "$FUNCNAME: applying user patches"
504 vdr-plugin-2_src_util prepare
507 vdr-plugin-2_src_compile() {
508 [ -z "$1" ] && vdr-plugin-2_src_compile compile
513 if [[ ! -f ${WORKDIR}/.vdr-plugin_makefile_patched ]]; then
514 eerror "Wrong use of vdr-plugin-2.eclass."
515 eerror "An ebuild for a vdr-plugin will not work without"
516 eerror "calling vdr-plugin-2_src_compile to patch the Makefile."
518 eerror "Please report this at bugs.gentoo.org."
519 die "vdr-plugin-2_src_compile not called!"
521 cd "${S}" || die "could not change to plugin source directory (src_compile)"
523 emake all ${BUILD_PARAMS} \
524 LOCALEDIR="${TMP_LOCALE_DIR}" \
525 LOCDIR="${TMP_LOCALE_DIR}" \
528 || die "emake all failed"
536 vdr-plugin-2_src_install() {
537 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
538 eerror "Wrong use of vdr-plugin-2.eclass."
539 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin-2_src_install."
541 eerror "Please report this at bugs.gentoo.org."
542 die "vdr-plugin-2_src_install not called!"
545 cd "${WORKDIR}" || die "could not change to plugin workdir directory (src_install)"
547 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
548 local mname="${P}-Makefile"
549 cp "${S}"/Makefile "${mname}.patched"
550 cp Makefile.before "${mname}.before"
552 diff -u "${mname}.before" "${mname}.patched" > "${mname}.diff"
554 insinto "/usr/share/vdr/maintainer-data/makefile-changes"
555 doins "${mname}.diff"
557 insinto "/usr/share/vdr/maintainer-data/makefile-before"
558 doins "${mname}.before"
560 insinto "/usr/share/vdr/maintainer-data/makefile-patched"
561 doins "${mname}.patched"
565 cd "${S}" || die "could not change to plugin source directory (src_install)"
567 local SOFILE_STRING=$(grep SOFILE Makefile)
568 if [[ -n ${SOFILE_STRING} ]]; then
573 || die "emake install (makefile target) failed"
575 vdr_dev_check "Plugin use still the old Makefile handling"
576 insinto "${VDR_PLUGIN_DIR}"
580 if [[ -d ${TMP_LOCALE_DIR} ]]; then
581 einfo "Installing locales"
582 cd "${TMP_LOCALE_DIR}" || die "could not change to TMP_LOCALE_DIR"
585 for linguas in ${LINGUAS[*]}; do
587 cp -r --parents ${linguas}* ${D}/${LOCDIR}
591 cd "${D}/usr/$(get_libdir)/vdr/plugins" || die "could not change to D/usr/libdir/vdr/plugins"
593 # create list of all created plugin libs
596 for p in libvdr-*.so.*; do
598 p_name="${p_name#lib}"
599 vdr_plugin_list="${vdr_plugin_list} ${p_name}"
602 cd "${S}" || die "could not change to plugin source directory (src_install)"
604 vdr_create_header_checksum_file ${vdr_plugin_list}
605 vdr_create_plugindb_file ${vdr_plugin_list}
607 if [[ ${EAPI} != [45] ]]; then
611 for docfile in README* HISTORY CHANGELOG; do
612 [[ -f ${docfile} ]] && dodoc ${docfile}
616 # if VDR_CONFD_FILE is empty and ${FILESDIR}/confd exists take it
617 [[ -z ${VDR_CONFD_FILE} ]] && [[ -e ${FILESDIR}/confd ]] && VDR_CONFD_FILE=${FILESDIR}/confd
619 if [[ -n ${VDR_CONFD_FILE} ]]; then
620 newconfd "${VDR_CONFD_FILE}" vdr.${VDRPLUGIN}
623 # if VDR_RCADDON_FILE is empty and ${FILESDIR}/rc-addon.sh exists take it
624 [[ -z ${VDR_RCADDON_FILE} ]] && [[ -e ${FILESDIR}/rc-addon.sh ]] && VDR_RCADDON_FILE=${FILESDIR}/rc-addon.sh
626 if [[ -n ${VDR_RCADDON_FILE} ]]; then
627 insinto "${VDR_RC_DIR}"
628 newins "${VDR_RCADDON_FILE}" plugin-${VDRPLUGIN}.sh
632 vdr-plugin-2_pkg_postinst() {
633 vdr-plugin-2_print_enable_command
635 if [[ -n "${VDR_CONFD_FILE}" ]]; then
636 elog "Please have a look at the config-file"
637 elog "\t/etc/conf.d/vdr.${VDRPLUGIN}"
642 vdr-plugin-2_pkg_postrm() {
646 vdr-plugin-2_pkg_config() {