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 perl_fix_packlist() {
135 debug-print-function $FUNCNAME "$@"
137 find "${D}" -type f -name '.packlist' -print0 | while read -rd '' f ; do
138 if file "${f}" | grep -q -i " text" ; then
139 sed -i -e "s:${D}:/:g" "${f}"
144 # @FUNCTION: perl_remove_temppath
145 # @USAGE: perl_remove_temppath
147 # Look through ${D} for text files containing the temporary installation
148 # folder (i.e. ${D}). If the pattern is found, replace it with `/' and warn.
149 perl_remove_temppath() {
150 debug-print-function $FUNCNAME "$@"
152 find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
153 if file "${f}" | grep -q -i " text" ; then
154 grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
155 sed -i -e "s:${D}:/:g" "${f}"
160 # @FUNCTION: perl_rm_files
161 # @USAGE: perl_rm_files "file_1" "file_2"
163 # Remove certain files from a Perl release and remove them from the MANIFEST
166 # Most useful in src_prepare for nuking bad tests, and is highly recommended
167 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
168 # test is completely irrelevant to end users, and frequently fail simply
169 # because the authors of Test::Pod... changed their recommendations, and thus
170 # failures are only useful feedback to Authors, not users.
172 # Removing from MANIFEST also avoids needless log messages warning
173 # users about files "missing from their kit".
175 debug-print-function $FUNCNAME "$@"
176 local skipfile="${T}/.gentoo_makefile_skip"
177 local manifile="${S}/MANIFEST"
178 local manitemp="${T}/.gentoo_manifest_temp"
181 for filename in "$@"; do
182 einfo "Removing un-needed ${filename}";
184 rm -f "${S}/${filename}"
185 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
187 if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
188 einfo "Fixing Manifest"
189 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
190 mv -f -- "${manitemp}" "${manifile}"
196 # @FUNCTION: perl_link_duallife_scripts
197 # @USAGE: perl_link_duallife_scripts
199 # Moves files and generates symlinks so dual-life packages installing scripts do not
200 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes
201 # only sense for perl-core packages.
202 perl_link_duallife_scripts() {
203 debug-print-function $FUNCNAME "$@"
204 if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
209 if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
210 for i in "${DUALLIFESCRIPTS[@]}" ; do
211 alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
213 for i in "${DUALLIFEMAN[@]}" ; do
214 ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
216 alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
219 pushd "${ED}" > /dev/null
220 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
221 mv ${i}{,-${PV}-${P}} || die
222 #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
223 DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
225 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
226 mv ${i} ${i%.1}-${PV}-${P}.1 || die
227 DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
233 # @FUNCTION: perl_check_env
234 # @USAGE: perl_check_env
236 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
237 # doing personal perl work, which may accidentally leak into portage and break the
238 # system perl installaton.
239 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
240 # There's a workaround, but you'll have to read the code for it.
244 for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
246 [ -v $i ] || continue;
248 # Warn only once, and warn only when one of the bad values are set.
249 # record failure here.
250 if [ ${errored:-0} == 0 ]; then
251 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
252 elog "perl-module.eclass: Suspicious environment values found.";
254 eerror "perl-module.eclass: Suspicious environment values found.";
262 # Print ENV name/value pair
263 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
264 elog " $i=\"$value\"";
266 eerror " $i=\"$value\"";
270 # Return if there were no failures
271 [ ${errored:-0} == 0 ] && return;
273 # Return if user knows what they're doing
274 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
275 elog "Continuing anyway, seems you know what you're doing."
279 eerror "Your environment settings may lead to undefined behavior and/or build failures."
280 die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."