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 \
110 -o \( -name '*.bs' -a -empty \) \) -delete
111 find "${D}" -depth -mindepth 1 -type d -empty -delete
115 # @FUNCTION: perl_remove_temppath
116 # @USAGE: perl_remove_temppath
118 # Look through ${D} for text files containing the temporary installation
119 # folder (i.e. ${D}). If the pattern is found (i.e. " text"), replace it with `/'.
120 perl_remove_temppath() {
121 debug-print-function $FUNCNAME "$@"
123 find "${D}" -type f -not -name '*.so' -print0 | while read -rd '' f ; do
124 if file "${f}" | grep -q -i " text" ; then
125 grep -q "${D}" "${f}" && ewarn "QA: File contains a temporary path ${f}"
126 sed -i -e "s:${D}:/:g" "${f}"
131 # @FUNCTION: perl_rm_files
132 # @USAGE: perl_rm_files "file_1" "file_2"
134 # Remove certain files from a Perl release and remove them from the MANIFEST
137 # Most useful in src_prepare for nuking bad tests, and is highly recommended
138 # for any tests like 'pod.t', 'pod-coverage.t' or 'kwalitee.t', as what they
139 # test is completely irrelevant to end users, and frequently fail simply
140 # because the authors of Test::Pod... changed their recommendations, and thus
141 # failures are only useful feedback to Authors, not users.
143 # Removing from MANIFEST also avoids needless log messages warning
144 # users about files "missing from their kit".
146 debug-print-function $FUNCNAME "$@"
147 local skipfile="${T}/.gentoo_makefile_skip"
148 local manifile="${S}/MANIFEST"
149 local manitemp="${T}/.gentoo_manifest_temp"
152 for filename in "$@"; do
153 einfo "Removing un-needed ${filename}";
155 rm -f "${S}/${filename}"
156 [[ -e "${manifile}" ]] && echo "${filename}" >> "${skipfile}"
158 if [[ -e "${manifile}" && -e "${skipfile}" ]]; then
159 einfo "Fixing Manifest"
160 grep -v -F -f "${skipfile}" "${manifile}" > "${manitemp}"
161 mv -f -- "${manitemp}" "${manifile}"
167 # @FUNCTION: perl_link_duallife_scripts
168 # @USAGE: perl_link_duallife_scripts
170 # Moves files and generates symlinks so dual-life packages installing scripts do not
171 # lead to file collisions. Mainly for use in pkg_postinst and pkg_postrm, and makes
172 # only sense for perl-core packages.
173 perl_link_duallife_scripts() {
174 debug-print-function $FUNCNAME "$@"
175 if [[ ${CATEGORY} != perl-core ]] || ! has_version ">=dev-lang/perl-5.8.8-r8" ; then
180 if has "${EBUILD_PHASE:-none}" "postinst" "postrm" ; then
181 for i in "${DUALLIFESCRIPTS[@]}" ; do
182 alternatives_auto_makesym "/${i}" "/${i}-[0-9]*"
184 for i in "${DUALLIFEMAN[@]}" ; do
185 ff=`echo "${EROOT}"/${i%.1}-${PV}-${P}.1*`
187 alternatives_auto_makesym "/${i}${ff}" "/${i%.1}-[0-9]*"
190 pushd "${ED}" > /dev/null
191 for i in $(find usr/bin -maxdepth 1 -type f 2>/dev/null) ; do
192 mv ${i}{,-${PV}-${P}} || die
193 #DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i##*/}
194 DUALLIFESCRIPTS[${#DUALLIFESCRIPTS[*]}]=${i}
196 for i in $(find usr/share/man/man1 -maxdepth 1 -type f 2>/dev/null) ; do
197 mv ${i} ${i%.1}-${PV}-${P}.1 || die
198 DUALLIFEMAN[${#DUALLIFEMAN[*]}]=${i}
204 # @FUNCTION: perl_check_env
205 # @USAGE: perl_check_env
207 # Checks a blacklist of known-suspect ENV values that can be accidentally set by users
208 # doing personal perl work, which may accidentally leak into portage and break the
209 # system perl installaton.
210 # Dies if any of the suspect fields are found, and tell the user what needs to be unset.
211 # There's a workaround, but you'll have to read the code for it.
215 for i in PERL_MM_OPT PERL5LIB PERL5OPT PERL_MB_OPT PERL_CORE PERLPREFIX; do
217 [ -v $i ] || continue;
219 # Warn only once, and warn only when one of the bad values are set.
220 # record failure here.
221 if [ ${errored:-0} == 0 ]; then
222 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
223 elog "perl-module.eclass: Suspicious environment values found.";
225 eerror "perl-module.eclass: Suspicious environment values found.";
233 # Print ENV name/value pair
234 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
235 elog " $i=\"$value\"";
237 eerror " $i=\"$value\"";
241 # Return if there were no failures
242 [ ${errored:-0} == 0 ] && return;
244 # Return if user knows what they're doing
245 if [ -n "${I_KNOW_WHAT_I_AM_DOING}" ]; then
246 elog "Continuing anyway, seems you know what you're doing."
250 eerror "Your environment settings may lead to undefined behavior and/or build failures."
251 die "Please fix your environment ( ~/.bashrc, package.env, ... ), see above for details."