/[gentoo-x86]/eclass/vdr-plugin.eclass
Gentoo

Contents of /eclass/vdr-plugin.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (show annotations) (download)
Sat Jun 2 15:07:43 2007 UTC (7 years, 6 months ago) by zzam
Branch: MAIN
Changes since 1.44: +23 -20 lines
Moved checksum creation to own function.

1 # Copyright 1999-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/vdr-plugin.eclass,v 1.44 2007/04/23 07:17:42 zzam Exp $
4 #
5 # Author:
6 # Matthias Schwarzott <zzam@gentoo.org>
7 # Joerg Bornkessel <hd_brummy@gentoo.org>
8
9 # vdr-plugin.eclass
10 #
11 # eclass to create ebuilds for vdr plugins
12 #
13
14 # Example ebuild (vdr-femon):
15 #
16 # inherit vdr-plugin
17 # IUSE=""
18 # SLOT="0"
19 # DESCRIPTION="vdr Plugin: DVB Frontend Status Monitor (signal strengt/noise)"
20 # HOMEPAGE="http://www.saunalahti.fi/~rahrenbe/vdr/femon/"
21 # SRC_URI="http://www.saunalahti.fi/~rahrenbe/vdr/femon/files/${P}.tgz"
22 # LICENSE="GPL-2"
23 # KEYWORDS="~x86"
24 # DEPEND=">=media-video/vdr-1.3.27"
25 #
26 #
27
28 # Installation of a config file for the plugin
29 #
30 # If ${VDR_CONFD_FILE} is set install this file
31 # else install ${FILESDIR}/confd if it exists.
32
33 # Gets installed as /etc/conf.d/vdr.${VDRPLUGIN}.
34 # For the plugin vdr-femon this would be /etc/conf.d/vdr.femon
35
36
37 # Installation of an rc-addon file for the plugin
38 #
39 # If ${VDR_RCADDON_FILE} is set install this file
40 # else install ${FILESDIR}/rc-addon.sh if it exists.
41 #
42 # Gets installed under ${VDR_RC_DIR}/plugin-${VDRPLUGIN}.sh
43 # (in example vdr-femon this would be /usr/share/vdr/rcscript/plugin-femon.sh)
44 #
45 # This file is sourced by the startscript when plugin is activated in /etc/conf.d/vdr
46 # It could be used for special startup actions for this plugins, or to create the
47 # plugin command line options from a nicer version of a conf.d file.
48
49 # HowTo use own local patches; Example
50 #
51 # Add to your /etc/make.conf:
52 # VDR_LOCAL_PATCHES_DIR="/usr/local/patch"
53 #
54 # Add two DIR's in your local patch dir, ${PN}/${PV},
55 # e.g for vdr-burn-0.1.0 should be:
56 # /usr/local/patch/vdr-burn/0.1.0/
57 #
58 # all patches which ending on diff or patch in this DIR will automatically applied
59 #
60
61 inherit base multilib eutils flag-o-matic
62
63 IUSE=""
64
65 # Name of the plugin stripped from all vdrplugin-, vdr- and -cvs pre- and postfixes
66 VDRPLUGIN="${PN/#vdrplugin-/}"
67 VDRPLUGIN="${VDRPLUGIN/#vdr-/}"
68 VDRPLUGIN="${VDRPLUGIN/%-cvs/}"
69
70 DESCRIPTION="vdr Plugin: ${VDRPLUGIN} (based on vdr-plugin.eclass)"
71
72 # works in most cases
73 S="${WORKDIR}/${VDRPLUGIN}-${PV}"
74
75 # depend on headers for DVB-driver
76 RDEPEND=">=media-tv/gentoo-vdr-scripts-0.3.4-r1"
77 DEPEND="media-tv/linuxtv-dvb-headers"
78
79
80 # this code is from linux-mod.eclass
81 update_vdrplugindb() {
82 local VDRPLUGINDB_DIR=${ROOT}/var/lib/vdrplugin-rebuild/
83
84 if [[ ! -f ${VDRPLUGINDB_DIR}/vdrplugindb ]]; then
85 [[ ! -d ${VDRPLUGINDB_DIR} ]] && mkdir -p ${VDRPLUGINDB_DIR}
86 touch ${VDRPLUGINDB_DIR}/vdrplugindb
87 fi
88 if [[ -z $(grep ${CATEGORY}/${PN}-${PVR} ${VDRPLUGINDB_DIR}/vdrplugindb) ]]; then
89 einfo "Adding plugin to vdrplugindb."
90 echo "a:1:${CATEGORY}/${PN}-${PVR}" >> ${VDRPLUGINDB_DIR}/vdrplugindb
91 fi
92 }
93
94 remove_vdrplugindb() {
95 local VDRPLUGINDB_DIR=${ROOT}/var/lib/vdrplugin-rebuild/
96
97 if [[ -n $(grep ${CATEGORY}/${PN}-${PVR} ${VDRPLUGINDB_DIR}/vdrplugindb) ]]; then
98 einfo "Removing ${CATEGORY}/${PN}-${PVR} from vdrplugindb."
99 sed -ie "/.*${CATEGORY}\/${P}.*/d" ${VDRPLUGINDB_DIR}/vdrplugindb
100 fi
101 }
102
103 # New method of storing plugindb
104 # Called from src_install
105 # file maintained by normal portage-methods
106 create_plugindb_file() {
107 local NEW_VDRPLUGINDB_DIR=/usr/share/vdr/vdrplugin-rebuild/
108 local DB_FILE=${NEW_VDRPLUGINDB_DIR}/${CATEGORY}-${PF}
109 insinto ${NEW_VDRPLUGINDB_DIR}
110 cat <<-EOT > ${D}/${DB_FILE}
111 VDRPLUGIN_DB=1
112 CREATOR=ECLASS
113 EBUILD=${CATEGORY}/${PN}
114 EBUILD_V=${PVR}
115 EOT
116 }
117
118 # Delete files created outside of vdr-plugin.eclass
119 # vdrplugin-rebuild.ebuild converted plugindb and files are
120 # not deleted by portage itself - should only be needed as
121 # long as not every system has switched over to
122 # vdrplugin-rebuild-0.2
123 delete_orphan_plugindb_file() {
124 #elog Testing for orphaned plugindb file
125 local NEW_VDRPLUGINDB_DIR=/usr/share/vdr/vdrplugin-rebuild/
126 local DB_FILE=${ROOT}/${NEW_VDRPLUGINDB_DIR}/${CATEGORY}-${PF}
127
128 # file exists
129 [[ -f ${DB_FILE} ]] || return
130
131 # will portage handle the file itself
132 if grep -q CREATOR=ECLASS ${DB_FILE}; then
133 #elog file owned by eclass - don't touch it
134 return
135 fi
136
137 elog "Removing orphaned plugindb-file."
138 elog "\t#rm ${DB_FILE}"
139 rm ${DB_FILE}
140 }
141
142
143 create_header_checksum_file()
144 {
145 # Danger: Not using $ROOT here, as compile will also not use it !!!
146 # If vdr in $ROOT and / differ, plugins will not run anyway
147
148 insinto ${VDR_CHECKSUM_DIR}
149 if [[ -f ${VDR_CHECKSUM_DIR}/header-md5-vdr ]]; then
150 newins ${VDR_CHECKSUM_DIR}/header-md5-vdr header-md5-${PN}
151 else
152 if type -p md5sum >/dev/null 2>&1; then
153 cd ${S}
154 (
155 cd ${VDR_INCLUDE_DIR}
156 md5sum *.h libsi/*.h|LC_ALL=C sort --key=2
157 ) > header-md5-${PN}
158 doins header-md5-${PN}
159 fi
160 fi
161 }
162
163 vdr-plugin_pkg_setup() {
164 # -fPIC is needed for shared objects on some platforms (amd64 and others)
165 append-flags -fPIC
166
167 # Where should the plugins live in the filesystem
168 VDR_PLUGIN_DIR="/usr/$(get_libdir)/vdr/plugins"
169 VDR_CHECKSUM_DIR="${VDR_PLUGIN_DIR%/plugins}/checksums"
170
171 # was /usr/lib/... some time ago
172 # since gentoo-vdr-scripts-0.3.6 it works with /usr/share/...
173 VDR_RC_DIR="/usr/share/vdr/rcscript"
174
175 # Pathes to includes
176 VDR_INCLUDE_DIR="/usr/include/vdr"
177 DVB_INCLUDE_DIR="/usr/include"
178
179
180 VDRVERSION=$(awk -F'"' '/define VDRVERSION/ {print $2}' ${VDR_INCLUDE_DIR}/config.h)
181 APIVERSION=$(awk -F'"' '/define APIVERSION/ {print $2}' ${VDR_INCLUDE_DIR}/config.h)
182 [[ -z ${APIVERSION} ]] && APIVERSION="${VDRVERSION}"
183
184 einfo "Building ${PF} against vdr-${VDRVERSION}"
185 einfo "APIVERSION: ${APIVERSION}"
186 }
187
188 vdr-plugin_src_unpack() {
189 if [[ -z ${VDR_INCLUDE_DIR} ]]; then
190 eerror "Wrong use of vdr-plugin.eclass."
191 eerror "An ebuild for a vdr-plugin will not work without calling vdr-plugin_pkg_setup."
192 echo
193 eerror "Please report this at bugs.gentoo.org."
194 die "vdr-plugin_pkg_setup not called!"
195 fi
196 [ -z "$1" ] && vdr-plugin_src_unpack unpack add_local_patch patchmakefile
197
198 while [ "$1" ]; do
199
200 case "$1" in
201 all_but_unpack)
202 vdr-plugin_src_unpack add_local_patch patchmakefile
203 ;;
204 unpack)
205 base_src_unpack
206 ;;
207 patchmakefile)
208 if ! cd ${S}; then
209 ewarn "There seems to be no plugin-directory with the name ${S##*/}"
210 ewarn "Perhaps you find one among these:"
211 cd "${WORKDIR}"
212 ewarn "$(/bin/ls -1 ${WORKDIR})"
213 die "Could not change to plugin-source-directory!"
214 fi
215
216 einfo "Patching Makefile"
217 [[ -e Makefile ]] || die "Makefile of plugin can not be found!"
218 cp Makefile Makefile.orig
219
220 sed -i Makefile \
221 -e '1i\#Makefile was patched by vdr-plugin.eclass'
222
223 ebegin " Setting Pathes"
224 sed -i Makefile \
225 -e "s:^VDRDIR.*$:VDRDIR = ${VDR_INCLUDE_DIR}:" \
226 -e "s:^DVBDIR.*$:DVBDIR = ${DVB_INCLUDE_DIR}:" \
227 -e "s:^LIBDIR.*$:LIBDIR = ${S}:" \
228 -e "s:^TMPDIR.*$:TMPDIR = ${T}:" \
229 -e 's:-I$(VDRDIR)/include -I$(DVBDIR)/include:-I$(DVBDIR)/include -I$(VDRDIR)/include:' \
230 -e 's:-I$(VDRDIR)/include:-I'"${VDR_INCLUDE_DIR%vdr}"':' \
231 -e 's:-I$(DVBDIR)/include:-I$(DVBDIR):'
232 eend $?
233
234 ebegin " Converting to APIVERSION"
235 sed -i Makefile \
236 -e 's:^APIVERSION = :APIVERSION ?= :' \
237 -e 's:$(LIBDIR)/$@.$(VDRVERSION):$(LIBDIR)/$@.$(APIVERSION):' \
238 -e '2i\APIVERSION = '"${APIVERSION}"
239 eend $?
240
241 ebegin " Correcting Compile-Flags"
242 sed -i Makefile \
243 -e 's:^CXXFLAGS:#CXXFLAGS:' \
244 -e '/LDFLAGS/!s:-shared:$(LDFLAGS) -shared:'
245 eend $?
246
247 ebegin " Disabling file stripping"
248 sed -i Makefile \
249 -e '/@.*strip/d' \
250 -e '/strip \$(LIBDIR)\/\$@/d' \
251 -e '/^STRIP =/d' \
252 -e '/@.*\$(STRIP)/d'
253 eend $?
254
255 # Use a file instead of an variable as single-stepping via ebuild
256 # destroys environment.
257 touch ${WORKDIR}/.vdr-plugin_makefile_patched
258 ;;
259 add_local_patch)
260 cd ${S}
261 if test -d "${VDR_LOCAL_PATCHES_DIR}/${PN}"; then
262 echo
263 einfo "Applying local patches"
264 for LOCALPATCH in ${VDR_LOCAL_PATCHES_DIR}/${PN}/${PV}/*.{diff,patch}; do
265 test -f "${LOCALPATCH}" && epatch "${LOCALPATCH}"
266 done
267 fi
268 ;;
269 esac
270
271 shift
272 done
273 }
274
275 vdr-plugin_copy_source_tree() {
276 pushd . >/dev/null
277 cp -r ${S} ${T}/source-tree
278 cd ${T}/source-tree
279 mv Makefile.orig Makefile
280 sed -i Makefile \
281 -e "s:^DVBDIR.*$:DVBDIR = ${DVB_INCLUDE_DIR}:" \
282 -e 's:^CXXFLAGS:#CXXFLAGS:' \
283 -e 's:-I$(DVBDIR)/include:-I$(DVBDIR):' \
284 -e 's:-I$(VDRDIR) -I$(DVBDIR):-I$(DVBDIR) -I$(VDRDIR):'
285 popd >/dev/null
286 }
287
288 vdr-plugin_install_source_tree() {
289 einfo "Installing sources"
290 destdir=${VDRSOURCE_DIR}/vdr-${VDRVERSION}/PLUGINS/src/${VDRPLUGIN}
291 insinto ${destdir}-${PV}
292 doins -r ${T}/source-tree/*
293
294 dosym ${VDRPLUGIN}-${PV} ${destdir}
295 }
296
297 vdr-plugin_src_compile() {
298 [ -z "$1" ] && vdr-plugin_src_compile prepare compile
299
300 while [ "$1" ]; do
301
302 case "$1" in
303 prepare)
304 [[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin_copy_source_tree
305 ;;
306 compile)
307 if [[ ! -f ${WORKDIR}/.vdr-plugin_makefile_patched ]]; then
308 eerror "Wrong use of vdr-plugin.eclass."
309 eerror "An ebuild for a vdr-plugin will not work without"
310 eerror "calling vdr-plugin_src_unpack to patch the Makefile."
311 echo
312 eerror "Please report this at bugs.gentoo.org."
313 die "vdr-plugin_src_unpack not called!"
314 fi
315 cd ${S}
316
317 emake ${BUILD_PARAMS} ${VDRPLUGIN_MAKE_TARGET:-all} || die "emake failed"
318 ;;
319 esac
320
321 shift
322 done
323 }
324
325 vdr-plugin_src_install() {
326 [[ -n "${VDRSOURCE_DIR}" ]] && vdr-plugin_install_source_tree
327 cd ${S}
328
329 if [[ -n ${VDR_MAINTAINER_MODE} ]]; then
330 local mname=${P}-Makefile
331 cp Makefile ${mname}.patched
332 cp Makefile.orig ${mname}.before
333
334 diff -u ${mname}.before ${mname}.patched > ${mname}.diff
335
336 insinto "/usr/share/vdr/maintainer-data/makefile-changes"
337 doins ${mname}.diff
338
339 insinto "/usr/share/vdr/maintainer-data/makefile-before"
340 doins ${mname}.before
341
342 insinto "/usr/share/vdr/maintainer-data/makefile-patched"
343 doins ${mname}.patched
344
345 fi
346
347 insinto "${VDR_PLUGIN_DIR}"
348 doins libvdr-*.so.*
349 local docfile
350 for docfile in README* HISTORY CHANGELOG; do
351 [[ -f ${docfile} ]] && dodoc ${docfile}
352 done
353
354 # if VDR_CONFD_FILE is empty and ${FILESDIR}/confd exists take it
355 [[ -z ${VDR_CONFD_FILE} ]] && [[ -e ${FILESDIR}/confd ]] && VDR_CONFD_FILE=${FILESDIR}/confd
356
357 if [[ -n ${VDR_CONFD_FILE} ]]; then
358 newconfd "${VDR_CONFD_FILE}" vdr.${VDRPLUGIN}
359 fi
360
361
362 # if VDR_RCADDON_FILE is empty and ${FILESDIR}/rc-addon.sh exists take it
363 [[ -z ${VDR_RCADDON_FILE} ]] && [[ -e ${FILESDIR}/rc-addon.sh ]] && VDR_RCADDON_FILE=${FILESDIR}/rc-addon.sh
364
365 if [[ -n ${VDR_RCADDON_FILE} ]]; then
366 insinto "${VDR_RC_DIR}"
367 newins "${VDR_RCADDON_FILE}" plugin-${VDRPLUGIN}.sh
368 fi
369
370 create_header_checksum_file
371 create_plugindb_file
372 }
373
374 vdr-plugin_pkg_postinst() {
375 if has_version "<=media-tv/vdrplugin-rebuild-0.1"; then
376 update_vdrplugindb
377 fi
378 elog
379 elog "The vdr plugin ${VDRPLUGIN} has now been installed."
380 elog "To activate execute the following command:"
381 elog
382 elog " emerge --config ${PN}"
383 elog
384 if [[ -n "${VDR_CONFD_FILE}" ]]; then
385 elog "And have a look at the config-file"
386 elog "/etc/conf.d/vdr.${VDRPLUGIN}"
387 elog
388 fi
389 }
390
391 vdr-plugin_pkg_postrm() {
392 if has_version "<=media-tv/vdrplugin-rebuild-0.1"; then
393 remove_vdrplugindb
394 fi
395 delete_orphan_plugindb_file
396 }
397
398 vdr-plugin_pkg_config_final() {
399 diff ${conf_orig} ${conf}
400 rm ${conf_orig}
401 }
402
403 vdr-plugin_pkg_config_old() {
404 elog "Using interface of gentoo-vdr-scripts-0.3.6 and older"
405 if [[ -z "${INSTALLPLUGIN}" ]]; then
406 INSTALLPLUGIN="${VDRPLUGIN}"
407 fi
408 # First test if plugin is already inside PLUGINS
409 local conf=/etc/conf.d/vdr
410 conf_orig=${conf}.before_emerge_config
411 cp ${conf} ${conf_orig}
412
413 elog "Reading ${conf}"
414 if ! grep -q "^PLUGINS=" ${conf}; then
415 local LINE=$(sed ${conf} -n -e '/^#.*PLUGINS=/=' | tail -n 1)
416 if [[ -n "${LINE}" ]]; then
417 sed -e ${LINE}'a PLUGINS=""' -i ${conf}
418 else
419 echo 'PLUGINS=""' >> ${conf}
420 fi
421 unset LINE
422 fi
423
424 unset PLUGINS
425 PLUGINS=$(source /etc/conf.d/vdr; echo ${PLUGINS})
426
427 active=0
428 for p in ${PLUGINS}; do
429 if [[ "${p}" == "${INSTALLPLUGIN}" ]]; then
430 active=1
431 break;
432 fi
433 done
434
435 if [[ "${active}" == "1" ]]; then
436 elog "${INSTALLPLUGIN} already activated"
437 echo
438 read -p "Do you want to deactivate ${INSTALLPLUGIN} (yes/no) " answer
439 if [[ "${answer}" != "yes" ]]; then
440 elog "aborted"
441 return
442 fi
443 elog "Removing ${INSTALLPLUGIN} from active plugins."
444 local LINE=$(sed ${conf} -n -e '/^PLUGINS=.*\<'${INSTALLPLUGIN}'\>/=' | tail -n 1)
445 sed -i ${conf} -e ${LINE}'s/\<'${INSTALLPLUGIN}'\>//' \
446 -e ${LINE}'s/ \( \)*/ /g' \
447 -e ${LINE}'s/ "/"/g' \
448 -e ${LINE}'s/" /"/g'
449
450 vdr-plugin_pkg_config_final
451 return
452 fi
453
454
455 elog "Adding ${INSTALLPLUGIN} to active plugins."
456 local LINE=$(sed ${conf} -n -e '/^PLUGINS=/=' | tail -n 1)
457 sed -i ${conf} -e ${LINE}'s/^PLUGINS=" *\(.*\)"/PLUGINS="\1 '${INSTALLPLUGIN}'"/' \
458 -e ${LINE}'s/ \( \)*/ /g' \
459 -e ${LINE}'s/ "/"/g' \
460 -e ${LINE}'s/" /"/g'
461
462 vdr-plugin_pkg_config_final
463 }
464
465 vdr-plugin_pkg_config_new() {
466 elog "Using interface introduced with gentoo-vdr-scripts-0.3.7"
467 if [[ -z "${INSTALLPLUGIN}" ]]; then
468 INSTALLPLUGIN="${VDRPLUGIN}"
469 fi
470
471 active=0
472 # First test if plugin is already inside PLUGINS
473 local conf=/etc/conf.d/vdr.plugins
474 exec 3<${conf}
475 while read -u 3 line; do
476 [[ ${line} == "" ]] && continue
477 [[ ${line:0:1} == "#" ]] && continue
478 set -- ${line}
479 [[ ${1} == ${INSTALLPLUGIN} ]] && active=1
480 done
481 exec 3<&-
482
483 if [[ $active == 0 ]]; then
484 elog "Adding ${INSTALLPLUGIN} to active plugins."
485
486 # The pure edit process.
487 echo "${INSTALLPLUGIN}" >> "${conf}"
488 else
489 elog "${INSTALLPLUGIN} already activated"
490 echo
491 read -p "Do you want to deactivate ${INSTALLPLUGIN} (yes/no) " answer
492 if [[ "${answer}" != "yes" ]]; then
493 elog "aborted"
494 return
495 fi
496 elog "Removing ${INSTALLPLUGIN} from active plugins."
497
498 # The pure edit process
499 sed -i "${conf}" -e "/^[[:space:]]*${INSTALLPLUGIN}[[:space:]]*\$/d"
500 fi
501 }
502
503 vdr-plugin_pkg_config() {
504 if has_version ">media-tv/gentoo-vdr-scripts-0.3.6"; then
505 vdr-plugin_pkg_config_new
506 else
507 vdr-plugin_pkg_config_old
508 fi
509 }
510
511 fix_vdr_libsi_include()
512 {
513 einfo "Fixing include of libsi-headers"
514 local f
515 for f; do
516 sed -i "${f}" \
517 -e '/#include/s:"\(.*libsi.*\)":<\1>:' \
518 -e '/#include/s:<.*\(libsi/.*\)>:<vdr/\1>:'
519 done
520 }
521
522 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst pkg_postrm pkg_config

  ViewVC Help
Powered by ViewVC 1.1.20