1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: perl-functions.eclass
9 # Seemant Kulleen <seemant@gentoo.org>
10 # Andreas K. Huettel <dilfridge@gentoo.org>
11 # @BLURB: helper functions eclass for perl modules
13 # The perl-functions eclass is designed to allow easier installation of perl
14 # modules, and their incorporation into the Gentoo Linux system.
15 # It provides helper functions, no phases or variable manipulation in
18 [[ ${CATEGORY} == "perl-core" ]] && inherit alternatives
24 die "EAPI=${EAPI} is not supported by perl-functions.eclass"
30 # @FUNCTION: perl_set_version
31 # @USAGE: perl_set_version
33 # Extract version information and installation paths from the current Perl
36 # This sets the following variables: PERL_VERSION, SITE_ARCH, SITE_LIB,
37 # ARCH_LIB, VENDOR_LIB, VENDOR_ARCH
39 # This function used to be called perlinfo as well.
41 debug-print-function $FUNCNAME "$@"
42 debug-print "$FUNCNAME: perlinfo_done=${perlinfo_done}"
43 ${perlinfo_done} && return 0
46 local f version install{{site,vendor}{arch,lib},archlib}
47 eval "$(perl -V:{version,install{{site,vendor}{arch,lib},archlib}} )"
48 PERL_VERSION=${version}
49 SITE_ARCH=${installsitearch}
50 SITE_LIB=${installsitelib}
51 ARCH_LIB=${installarchlib}
52 VENDOR_LIB=${installvendorlib}
53 VENDOR_ARCH=${installvendorarch}
56 # @FUNCTION: perl_delete_localpod
57 # @USAGE: perl_delete_localpod
59 # Remove stray perllocal.pod files in the temporary install directory D.
61 # This function used to be called fixlocalpod as well.
62 perl_delete_localpod() {
63 debug-print-function $FUNCNAME "$@"
65 find "${D}" -type f -name perllocal.pod -delete
66 find "${D}" -depth -mindepth 1 -type d -empty -delete
69 # @FUNCTION: perl_fix_osx_extra
70 # @USAGE: perl_fix_osx_extra
72 # Look through ${S} for AppleDouble encoded files and get rid of them.
73 perl_fix_osx_extra() {
74 debug-print-function $FUNCNAME "$@"
77 find "${S}" -type f -name "._*" -print0 | while read -rd '' f ; do
78 einfo "Removing AppleDouble encoded Macintosh file: ${f#${S}/}"
81 grep -q "${f}" "${S}"/MANIFEST && \
82 elog "AppleDouble encoded Macintosh file in MANIFEST: ${f#${S}/}"
86 # @FUNCTION: perl_delete_module_manpages
87 # @USAGE: perl_delete_module_manpages
89 # Bump off manpages installed by the current module such as *.3pm files as well
90 # as empty directories.
91 perl_delete_module_manpages() {
92 debug-print-function $FUNCNAME "$@"
94 if [[ -d "${ED}"/usr/share/man ]] ; then
95 find "${ED}"/usr/share/man -type f -name "*.3pm" -delete
96 find "${ED}"/usr/share/man -depth -type d -empty -delete
100 # @FUNCTION: perl_delete_packlist
101 # @USAGE: perl_delete_packlist
103 # Look through ${D} for .packlist files, empty .bs files and empty directories,
104 # and get rid of items found.
105 perl_delete_packlist() {
106 debug-print-function $FUNCNAME "$@"
108 if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
109 find "${D}/${VENDOR_ARCH}" -type f -a -name .packlist -delete
110 perl_delete_emptybsdir
114 # @FUNCTION: perl_delete_emptybsdir
115 # @USAGE: perl_delete_emptybsdir
117 # Look through ${D} for empty .bs files and empty directories,
118 # and get rid of items found.
119 perl_delete_emptybsdir() {
120 debug-print-function $FUNCNAME "$@"
122 if [[ -d ${D}/${VENDOR_ARCH} ]] ; then
123 find "${D}/${VENDOR_ARCH}" -type f \
124 -a -name '*.bs' -a -empty -delete
125 find "${D}" -depth -mindepth 1 -type d -empty -delete
129 # @FUNCTION: perl_fix_packlist
130 # @USAGE: perl_fix_packlist
132 # Look through ${D} for .packlist text files containing the temporary installation
133 # folder (i.e. ${D}). If the pattern is found, silently replace it with `/'.
134 # Remove duplicate entries; then validate all entries in the packlist against ${D}
135 # and prune entries that do not correspond to installed files.
136 perl_fix_packlist() {
137 debug-print-function $FUNCNAME "$@"
139 local packlist_temp="${T}/.gentoo_packlist_temp"
140 find "${D}" -type f -name '.packlist' -print0 | while read -rd '' f ; do
141 if file "${f}" | grep -q -i " text" ; then
142 einfo "Fixing packlist file /${f#${D}}"
144 # remove the temporary build dir path
145 sed -i -e "s:${D}:/:g" "${f}"
147 # remove duplicate entries
148 sort -u "${f}" > "${packlist_temp}"
149 mv "${packlist_temp}" "${f}"
151 # remove files that dont exist
152 cat "${f}" | while read -r entry; do
153 if [ ! -e "${D}/${entry}" ]; then
154 einfo "Pruning surplus packlist entry ${entry}"
155 grep -v -x -F "${entry}" "${f}" > "${packlist_temp}"
156 mv "${packlist_temp}" "${f}"
163 # @FUNCTION: perl_remove_temppath
164 # @USAGE: perl_remove_temppath
166 # Look through ${D} for text files containing the temporary installation
167 # folder (i.e. ${D}). If the pattern is found, replace it with `/' and warn.
168 perl_remove_temppath() {
169 debug-print-function $FUNCNAME "$@"
171 find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
172 if file "${f}" | grep -q -i " text" ; then
173 grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
174 sed -i -e "s:${D}:/:g" "${f}"
179 # @FUNCTION: perl_rm_files
180 # @USAGE: perl_rm_files "file_1" "file_2"
182 # Remove certain files from a Perl release and remove them from the MANIFEST
185 # Most useful in src_prepare for nuking bad tests, and is highly recommended
186 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
187 # test is completely irrelevant to end users, and frequently fail simply
188 # because the authors of Test::Pod... changed their recommendations, and thus
189 # failures are only useful feedback to Authors, not users.
191 # Removing from MANIFEST also avoids needless log messages warning
192 # users about files "missing from their kit".
194 debug-print-function $FUNCNAME "$@"
195 local skipfile="${T}/.gentoo_makefile_skip"
196 local manifile="${S}/MANIFEST"
197 local manitemp="${T}/.gentoo_manifest_temp"
200 for filename in "$@"; do
201 einfo "Removing un-needed ${filename}";
203 rm -f "${S}/${filename}"
204 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
206 if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
207 einfo "Fixing Manifest"
208 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
209 mv -f -- "${manitemp}" "${manifile}"
215 # @FUNCTION: perl_link_duallife_scripts
216 # @USAGE: perl_link_duallife_scripts
218 # Moves files and generates symlinks so dual-life packages installing scripts do not
219 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes
220 # only sense for perl-core packages.
221 perl_link_duallife_scripts() {
222 debug-print-function $FUNCNAME "$@"
223 if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
228 if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
229 for i in "${DUALLIFESCRIPTS[@]}" ; do
230 alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
232 for i in "${DUALLIFEMAN[@]}" ; do
233 ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
235 alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
238 pushd "${ED}" > /dev/null
239 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
240 mv ${i}{,-${PV}-${P}} || die
241 #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
242 DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
244 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
245 mv ${i} ${i%.1}-${PV}-${P}.1 || die
246 DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
252 # @FUNCTION: perl_check_env
253 # @USAGE: perl_check_env
255 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
256 # doing personal perl work, which may accidentally leak into portage and break the
257 # system perl installaton.
258 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
259 # There's a workaround, but you'll have to read the code for it.
263 for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
265 [ -v $i ] || continue;
267 # Warn only once, and warn only when one of the bad values are set.
268 # record failure here.
269 if [ ${errored:-0} == 0 ]; then
270 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
271 elog "perl-module.eclass: Suspicious environment values found.";
273 eerror "perl-module.eclass: Suspicious environment values found.";
281 # Print ENV name/value pair
282 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
283 elog " $i=\"$value\"";
285 eerror " $i=\"$value\"";
289 # Return if there were no failures
290 [ ${errored:-0} == 0 ] && return;
292 # Return if user knows what they're doing
293 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
294 elog "Continuing anyway, seems you know what you're doing."
298 eerror "Your environment settings may lead to undefined behavior and/or build failures."
299 die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."
302 # @FUNCTION: perl_doexamples
303 # @USAGE: perl_doexamples "file_1" "file_2"
305 # Install example files ready-to-run.
306 # Is called under certain circumstances in perl-module.eclass src_install
307 # (see the documentation there).
310 debug-print-function $FUNCNAME "$@"
312 einfo "Installing examples into /usr/share/doc/${PF}/examples"
314 # no compression since we want ready-to-run scripts
315 docompress -x /usr/share/doc/${PF}/examples
320 # is there a way to undo "docinto" ?