1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: eutils.eclass
6 # base-system@gentoo.org
7 # @BLURB: many extra (but common) functions that are used in ebuilds
9 # The eutils eclass contains a suite of functions that complement
10 # the ones that ebuild.sh already contain. The idea is that the functions
11 # are not required in all ebuilds but enough utilize them to have a common
12 # home rather than having multiple ebuilds implementing the same thing.
14 # Due to the nature of this eclass, some functions may have maintainers
15 # different from the overall eclass!
17 if [[ -z ${_EUTILS_ECLASS} ]]; then
20 inherit multilib toolchain-funcs
25 # Proxy to ewarn for package managers that don't provide eqawarn and use the PM
26 # implementation if available. Reuses PORTAGE_ELOG_CLASSES as set by the dev
28 if ! declare -F eqawarn >/dev/null ; then
30 has qa ${PORTAGE_ELOG_CLASSES} && ewarn "$@"
35 # @FUNCTION: ecvs_clean
36 # @USAGE: [list of dirs]
38 # Remove CVS directories recursiveley. Useful when a source tarball contains
39 # internal CVS directories. Defaults to $PWD.
41 [[ $# -eq 0 ]] && set -- .
42 find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf
43 find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
46 # @FUNCTION: esvn_clean
47 # @USAGE: [list of dirs]
49 # Remove .svn directories recursiveley. Useful when a source tarball contains
50 # internal Subversion directories. Defaults to $PWD.
52 [[ $# -eq 0 ]] && set -- .
53 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
56 # @FUNCTION: egit_clean
57 # @USAGE: [list of dirs]
59 # Remove .git* directories/files recursiveley. Useful when a source tarball
60 # contains internal Git directories. Defaults to $PWD.
62 [[ $# -eq 0 ]] && set -- .
63 find "$@" -type d -name '.git*' -prune -print0 | xargs -0 rm -rf
66 # @FUNCTION: estack_push
67 # @USAGE: <stack> [items to push]
69 # Push any number of items onto the specified stack. Pick a name that
70 # is a valid variable (i.e. stick to alphanumerics), and push as many
71 # items as you like onto the stack at once.
73 # The following code snippet will echo 5, then 4, then 3, then ...
75 # estack_push mystack 1 2 3 4 5
76 # while estack_pop mystack i ; do
81 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
82 local stack_name="_ESTACK_$1_" ; shift
83 eval ${stack_name}+=\( \"\$@\" \)
86 # @FUNCTION: estack_pop
87 # @USAGE: <stack> [variable]
89 # Pop a single item off the specified stack. If a variable is specified,
90 # the popped item is stored there. If no more items are available, return
91 # 1, else return 0. See estack_push for more info.
93 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
95 # We use the fugly _estack_xxx var names to avoid collision with
96 # passing back the return value. If we used "local i" and the
97 # caller ran `estack_pop ... i`, we'd end up setting the local
98 # copy of "i" rather than the caller's copy. The _estack_xxx
99 # garbage is preferable to using $1/$2 everywhere as that is a
100 # bit harder to read.
101 local _estack_name="_ESTACK_$1_" ; shift
102 local _estack_retvar=$1 ; shift
103 eval local _estack_i=\${#${_estack_name}\[@\]}
104 # Don't warn -- let the caller interpret this as a failure
105 # or as normal behavior (akin to `shift`)
106 [[ $(( --_estack_i )) -eq -1 ]] && return 1
108 if [[ -n ${_estack_retvar} ]] ; then
109 eval ${_estack_retvar}=\"\${${_estack_name}\[${_estack_i}\]}\"
111 eval unset \"${_estack_name}\[${_estack_i}\]\"
114 # @FUNCTION: evar_push
115 # @USAGE: <variable to save> [more vars to save]
117 # This let's you temporarily modify a variable and then restore it (including
118 # set vs unset semantics). Arrays are not supported at this time.
120 # This is meant for variables where using `local` does not work (such as
121 # exported variables, or only temporarily changing things in a func).
127 # ... do some stuff that needs LC_ALL=C set ...
130 # # You can also save/restore more than one var at a time
131 # evar_push BUTTERFLY IN THE SKY
132 # ... do stuff with the vars ...
133 # evar_pop # This restores just one var, SKY
134 # ... do more stuff ...
135 # evar_pop 3 # This pops the remaining 3 vars
140 [[ ${!var+set} == "set" ]] \
142 || val="unset_76fc3c462065bb4ca959f939e6793f94"
143 estack_push evar "${var}" "${val}"
147 # @FUNCTION: evar_push_set
148 # @USAGE: <variable to save> [new value to store]
150 # This is a handy shortcut to save and temporarily set a variable. If a value
151 # is not specified, the var will be unset.
157 2) printf -v "${var}" '%s' "$2" ;;
158 *) die "${FUNCNAME}: incorrect # of args: $*" ;;
162 # @FUNCTION: evar_pop
163 # @USAGE: [number of vars to restore]
165 # Restore the variables to the state saved with the corresponding
166 # evar_push call. See that function for more details.
171 1) isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*" ;;
172 *) die "${FUNCNAME}: only accepts one arg: $*" ;;
176 while (( cnt-- )) ; do
177 estack_pop evar val || die "${FUNCNAME}: unbalanced push"
178 estack_pop evar var || die "${FUNCNAME}: unbalanced push"
179 [[ ${val} == "unset_76fc3c462065bb4ca959f939e6793f94" ]] \
181 || printf -v "${var}" '%s' "${val}"
185 # @FUNCTION: eshopts_push
186 # @USAGE: [options to `set` or `shopt`]
188 # Often times code will want to enable a shell option to change code behavior.
189 # Since changing shell options can easily break other pieces of code (which
190 # assume the default state), eshopts_push is used to (1) push the current shell
191 # options onto a stack and (2) pass the specified arguments to set.
193 # If the first argument is '-s' or '-u', we assume you want to call `shopt`
194 # rather than `set` as there are some options only available via that.
196 # A common example is to disable shell globbing so that special meaning/care
197 # may be used with variables/arguments to custom functions. That would be:
199 # eshopts_push -o noglob
200 # for x in ${foo} ; do
201 # if ...some check... ; then
209 if [[ $1 == -[su] ]] ; then
210 estack_push eshopts "$(shopt -p)"
211 [[ $# -eq 0 ]] && return 0
212 shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*"
214 estack_push eshopts $-
215 [[ $# -eq 0 ]] && return 0
216 set "$@" || die "${FUNCNAME}: bad options to set: $*"
220 # @FUNCTION: eshopts_pop
223 # Restore the shell options to the state saved with the corresponding
224 # eshopts_push call. See that function for more details.
227 estack_pop eshopts s || die "${FUNCNAME}: unbalanced push"
228 if [[ ${s} == "shopt -"* ]] ; then
229 eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
231 set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-"
232 set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}"
236 # @FUNCTION: eumask_push
237 # @USAGE: <new umask>
239 # Set the umask to the new value specified while saving the previous
240 # value onto a stack. Useful for temporarily changing the umask.
242 estack_push eumask "$(umask)"
243 umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
246 # @FUNCTION: eumask_pop
249 # Restore the previous umask state.
251 [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options"
253 estack_pop eumask s || die "${FUNCNAME}: unbalanced push"
254 umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
258 # @USAGE: <number> [more numbers]
260 # Return true if all arguments are numbers.
264 [[ ${d:-bad} == *[!0-9]* ]] && return 1
269 # @VARIABLE: EPATCH_SOURCE
271 # Default directory to search for patches.
272 EPATCH_SOURCE="${WORKDIR}/patch"
273 # @VARIABLE: EPATCH_SUFFIX
275 # Default extension for patches (do not prefix the period yourself).
276 EPATCH_SUFFIX="patch.bz2"
277 # @VARIABLE: EPATCH_OPTS
279 # Options to pass to patch. Meant for ebuild/package-specific tweaking
280 # such as forcing the patch level (-p#) or fuzz (-F#) factor. Note that
281 # for single patch tweaking, you can also pass flags directly to epatch.
283 # @VARIABLE: EPATCH_COMMON_OPTS
285 # Common options to pass to `patch`. You probably should never need to
286 # change these. If you do, please discuss it with base-system first to
289 # -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
290 # --no-backup-if-mismatch - do not leave .orig files behind
291 # -E - automatically remove empty files
293 EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
294 # @VARIABLE: EPATCH_EXCLUDE
296 # List of patches not to apply. Note this is only file names,
297 # and not the full path. Globs accepted.
299 # @VARIABLE: EPATCH_SINGLE_MSG
301 # Change the printed message for a single patch.
303 # @VARIABLE: EPATCH_MULTI_MSG
305 # Change the printed message for multiple patches.
306 EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
307 # @VARIABLE: EPATCH_FORCE
309 # Only require patches to match EPATCH_SUFFIX rather than the extended
312 # @VARIABLE: EPATCH_USER_EXCLUDE
315 # List of patches not to apply. Note this is only file names,
316 # and not the full path. Globs accepted.
319 # @USAGE: [options] [patches] [dirs of patches]
321 # epatch is designed to greatly simplify the application of patches. It can
322 # process patch files directly, or directories of patches. The patches may be
323 # compressed (bzip/gzip/etc...) or plain text. You generally need not specify
324 # the -p option as epatch will automatically attempt -p0 to -p4 until things
325 # apply successfully.
327 # If you do not specify any patches/dirs, then epatch will default to the
328 # directory specified by EPATCH_SOURCE.
330 # Any options specified that start with a dash will be passed down to patch
331 # for this specific invocation. As soon as an arg w/out a dash is found, then
332 # arg processing stops.
334 # When processing directories, epatch will apply all patches that match:
336 # if ${EPATCH_FORCE} != "yes"
337 # ??_${ARCH}_foo.${EPATCH_SUFFIX}
341 # The leading ?? are typically numbers used to force consistent patch ordering.
342 # The arch field is used to apply patches only for the host architecture with
343 # the special value of "all" means apply for everyone. Note that using values
344 # other than "all" is highly discouraged -- you should apply patches all the
345 # time and let architecture details be detected at configure/compile time.
347 # If EPATCH_SUFFIX is empty, then no period before it is implied when searching
348 # for patches to apply.
350 # Refer to the other EPATCH_xxx variables for more customization of behavior.
352 _epatch_draw_line() {
353 # create a line of same length as input string
354 [[ -z $1 ]] && set "$(printf "%65s" '')"
358 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
360 # First process options. We localize the EPATCH_OPTS setting
361 # from above so that we can pass it on in the loop below with
362 # any additional values the user has specified.
363 local EPATCH_OPTS=( ${EPATCH_OPTS[*]} )
364 while [[ $# -gt 0 ]] ; do
366 -*) EPATCH_OPTS+=( "$1" ) ;;
372 # Let the rest of the code process one user arg at a time --
373 # each arg may expand into multiple patches, and each arg may
374 # need to start off with the default global EPATCH_xxx values
375 if [[ $# -gt 1 ]] ; then
383 local SINGLE_PATCH="no"
384 # no args means process ${EPATCH_SOURCE}
385 [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}"
387 if [[ -f $1 ]] ; then
390 # Use the suffix from the single patch (localize it); the code
391 # below will find the suffix for us
392 local EPATCH_SUFFIX=$1
394 elif [[ -d $1 ]] ; then
395 # We have to force sorting to C so that the wildcard expansion is consistent #471666.
396 evar_push_set LC_COLLATE C
397 # Some people like to make dirs of patches w/out suffixes (vim).
398 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
401 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
402 # Re-use EPATCH_SOURCE as a search dir
403 epatch "${EPATCH_SOURCE}/$1"
407 # sanity check ... if it isn't a dir or file, wtf man ?
408 [[ $# -ne 0 ]] && EPATCH_SOURCE=$1
410 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
412 eerror " ${EPATCH_SOURCE}"
413 eerror " ( ${EPATCH_SOURCE##*/} )"
415 die "Cannot find \$EPATCH_SOURCE!"
418 # Now that we know we're actually going to apply something, merge
419 # all of the patch options back in to a single variable for below.
420 EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}"
423 case ${EPATCH_SUFFIX##*\.} in
424 xz) PIPE_CMD="xz -dc" ;;
425 lzma) PIPE_CMD="lzma -dc" ;;
426 bz2) PIPE_CMD="bzip2 -dc" ;;
427 gz|Z|z) PIPE_CMD="gzip -dc" ;;
428 ZIP|zip) PIPE_CMD="unzip -p" ;;
432 [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}"
436 # If the patch dir given contains subdirs, or our EPATCH_SUFFIX
437 # didn't match anything, ignore continue on
438 [[ ! -f ${x} ]] && continue
440 local patchname=${x##*/}
442 # Apply single patches, or forced sets of patches, or
443 # patches with ARCH dependant names.
445 # Else, skip this input altogether
446 local a=${patchname#*_} # strip the ???_
447 a=${a%%_*} # strip the _foo.patch
448 if ! [[ ${SINGLE_PATCH} == "yes" || \
449 ${EPATCH_FORCE} == "yes" || \
456 # Let people filter things dynamically
457 if [[ -n ${EPATCH_EXCLUDE}${EPATCH_USER_EXCLUDE} ]] ; then
458 # let people use globs in the exclude
459 eshopts_push -o noglob
462 for ex in ${EPATCH_EXCLUDE} ; do
463 if [[ ${patchname} == ${ex} ]] ; then
464 einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ..."
470 for ex in ${EPATCH_USER_EXCLUDE} ; do
471 if [[ ${patchname} == ${ex} ]] ; then
472 einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ..."
481 if [[ ${SINGLE_PATCH} == "yes" ]] ; then
482 if [[ -n ${EPATCH_SINGLE_MSG} ]] ; then
483 einfo "${EPATCH_SINGLE_MSG}"
485 einfo "Applying ${patchname} ..."
488 einfo " ${patchname} ..."
491 # Handle aliased patch command #404447 #461568
493 eval $(alias patch 2>/dev/null | sed 's:^alias ::')
495 # most of the time, there will only be one run per unique name,
496 # but if there are more, make sure we get unique log filenames
497 local STDERR_TARGET="${T}/${patchname}.out"
498 if [[ -e ${STDERR_TARGET} ]] ; then
499 STDERR_TARGET="${T}/${patchname}-$$.out"
502 printf "***** %s *****\nPWD: %s\nPATCH TOOL: %s -> %s\nVERSION INFO:\n%s\n\n" \
506 "$(type -P "${patch}")" \
507 "$(${patch} --version)" \
510 # Decompress the patch if need be
513 if [[ -n ${PIPE_CMD} ]] ; then
514 PATCH_TARGET="${T}/$$.patch"
515 echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}"
517 if ! (${PIPE_CMD} "${x}" > "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1 ; then
519 eerror "Could not extract patch!"
520 #die "Could not extract patch!"
528 # Check for absolute paths in patches. If sandbox is disabled,
529 # people could (accidently) patch files in the root filesystem.
530 # Or trigger other unpleasantries #237667. So disallow -p0 on
532 local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }')
533 if [[ -n ${abs_paths} ]] ; then
535 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
537 # Similar reason, but with relative paths.
538 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
539 if [[ -n ${rel_paths} ]] ; then
541 eerror "Rejected Patch: ${patchname} !"
542 eerror " ( ${PATCH_TARGET} )"
544 eerror "Your patch uses relative paths '../':"
545 eerror "${rel_paths}"
547 die "you need to fix the relative paths in patch"
550 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
552 while [[ ${count} -lt 5 ]] ; do
553 patch_cmd="${patch} -p${count} ${EPATCH_OPTS}"
555 # Generate some useful debug info ...
557 _epatch_draw_line "***** ${patchname} *****"
559 echo "PATCH COMMAND: ${patch_cmd} --dry-run -f < '${PATCH_TARGET}'"
561 _epatch_draw_line "***** ${patchname} *****"
562 ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1
565 echo "patch program exited with status ${ret}"
567 ) >> "${STDERR_TARGET}"
569 if [ $? -eq 0 ] ; then
571 _epatch_draw_line "***** ${patchname} *****"
573 echo "ACTUALLY APPLYING ${patchname} ..."
574 echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'"
576 _epatch_draw_line "***** ${patchname} *****"
577 ${patch_cmd} < "${PATCH_TARGET}" 2>&1
580 echo "patch program exited with status ${ret}"
582 ) >> "${STDERR_TARGET}"
584 if [ $? -ne 0 ] ; then
586 eerror "A dry-run of patch command succeeded, but actually"
587 eerror "applying the patch failed!"
588 #die "Real world sux compared to the dreamworld!"
597 (( EPATCH_N_APPLIED_PATCHES++ ))
599 # if we had to decompress the patch, delete the temp one
600 if [[ -n ${PIPE_CMD} ]] ; then
601 rm -f "${PATCH_TARGET}"
604 if [[ ${count} -ge 5 ]] ; then
606 eerror "Failed Patch: ${patchname} !"
607 eerror " ( ${PATCH_TARGET} )"
609 eerror "Include in your bugreport the contents of:"
611 eerror " ${STDERR_TARGET}"
613 die "Failed Patch: ${patchname}!"
616 # if everything worked, delete the full debug patch log
617 rm -f "${STDERR_TARGET}"
619 # then log away the exact stuff for people to review later
620 cat <<-EOF >> "${T}/epatch.log"
629 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
630 : # everything worked
636 # Cheap replacement for when debianutils (and thus mktemp)
637 # does not exist on the users system.
640 [[ $1 == -d ]] && exe="mkdir" && shift
643 if [[ -z ${topdir} ]] ; then
649 if ! type -P mktemp > /dev/null ; then
650 # system lacks `mktemp` so we have to fake it
652 while [[ -e ${tmp} ]] ; do
653 tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}
655 ${exe} "${tmp}" || ${exe} -p "${tmp}"
658 # the args here will give slightly wierd names on BSD,
659 # but should produce a usable file on all userlands
660 if [[ ${exe} == "touch" ]] ; then
661 TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX
663 TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX
668 # @FUNCTION: edos2unix
669 # @USAGE: <file> [more files ...]
671 # A handy replacement for dos2unix, recode, fixdos, etc... This allows you
672 # to remove all of these text utilities from DEPEND variables because this
673 # is a script based solution. Just give it a list of files to convert and
674 # they will all be changed from the DOS CRLF format to the UNIX LF format.
676 [[ $# -eq 0 ]] && return 0
677 sed -i 's/\r$//' -- "$@" || die
680 # @FUNCTION: make_desktop_entry
681 # @USAGE: make_desktop_entry(<command>, [name], [icon], [type], [fields])
683 # Make a .desktop file.
686 # binary: what command does the app run with ?
687 # name: the name that will show up in the menu
688 # icon: the icon to use in the menu entry
689 # this can be relative (to /usr/share/pixmaps) or
690 # a full path to an icon
691 # type: what kind of application is this?
693 # https://specifications.freedesktop.org/menu-spec/latest/apa.html
694 # if unset, function tries to guess from package's category
695 # fields: extra fields to append to the desktop file; a printf string
697 make_desktop_entry() {
698 [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable"
701 local name=${2:-${PN}}
702 local icon=${3:-${PN}}
706 if [[ -z ${type} ]] ; then
707 local catmaj=${CATEGORY%%-*}
708 local catmin=${CATEGORY##*-}
712 accessibility) type="Utility;Accessibility";;
714 antivirus) type=System;;
715 arch) type="Utility;Archiving";;
716 backup) type="Utility;Archiving";;
717 cdr) type="AudioVideo;DiscBurning";;
718 dicts) type="Office;Dictionary";;
719 doc) type=Documentation;;
720 editors) type="Utility;TextEditor";;
721 emacs) type="Development;TextEditor";;
722 emulation) type="System;Emulator";;
723 laptop) type="Settings;HardwareSettings";;
724 office) type=Office;;
725 pda) type="Office;PDA";;
726 vim) type="Development;TextEditor";;
727 xemacs) type="Development;TextEditor";;
737 action|fps) type=ActionGame;;
738 arcade) type=ArcadeGame;;
739 board) type=BoardGame;;
740 emulation) type=Emulator;;
741 kids) type=KidsGame;;
742 puzzle) type=LogicGame;;
743 roguelike) type=RolePlaying;;
744 rpg) type=RolePlaying;;
745 simulation) type=Simulation;;
746 sports) type=SportsGame;;
747 strategy) type=StrategyGame;;
776 type="AudioVideo;${type}"
783 dialup) type=Dialup;;
784 ftp) type=FileTransfer;;
785 im) type=InstantMessaging;;
786 irc) type=IRCClient;;
790 p2p) type=FileTransfer;;
791 voip) type=Telephony;;
793 type="Network;${type}"
798 astro*) type=Astronomy;;
800 calc*) type=Calculator;;
801 chem*) type=Chemistry;;
802 elec*) type=Electronics;;
805 physics) type=Physics;;
806 visual*) type=DataVisualization;;
808 type="Education;Science;${type}"
817 client) type=WebBrowser;;
819 type="Network;${type}"
827 local slot=${SLOT%/*}
828 if [[ ${slot} == "0" ]] ; then
829 local desktop_name="${PN}"
831 local desktop_name="${PN}-${slot}"
833 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
834 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
836 # Don't append another ";" when a valid category value is provided.
837 type=${type%;}${type:+;}
839 eshopts_push -s extglob
840 if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
841 ewarn "As described in the Icon Theme Specification, icon file extensions are not"
842 ewarn "allowed in .desktop files if the value is not an absolute path."
843 icon=${icon%.@(xpm|png|svg)}
847 cat <<-EOF > "${desktop}"
851 Comment=${DESCRIPTION}
858 if [[ ${fields:-=} != *=* ]] ; then
859 # 5th arg used to be value to Path=
860 ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}"
861 fields="Path=${fields}"
863 [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}"
866 # wrap the env here so that the 'insinto' call
867 # doesn't corrupt the env of the caller
868 insinto /usr/share/applications
870 ) || die "installing desktop file failed"
873 # @FUNCTION: _eutils_eprefix_init
876 # Initialized prefix variables for EAPI<3.
877 _eutils_eprefix_init() {
878 has "${EAPI:-0}" 0 1 2 && : ${ED:=${D}} ${EPREFIX:=} ${EROOT:=${ROOT}}
881 # @FUNCTION: validate_desktop_entries
882 # @USAGE: [directories]
884 # Validate desktop entries using desktop-file-utils
885 validate_desktop_entries() {
887 if [[ -x "${EPREFIX}"/usr/bin/desktop-file-validate ]] ; then
888 einfo "Checking desktop entry validity"
890 for d in /usr/share/applications $@ ; do
891 [[ -d ${ED}${d} ]] && directories="${directories} ${ED}${d}"
893 if [[ -n ${directories} ]] ; then
894 for FILE in $(find ${directories} -name "*\.desktop" \
895 -not -path '*.hidden*' | sort -u 2>/dev/null)
897 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | \
898 sed -e "s|error: ||" -e "s|${FILE}:|--|g" )
899 [[ -n $temp ]] && elog ${temp/--/${FILE/${ED}/}:}
904 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
908 # @FUNCTION: make_session_desktop
909 # @USAGE: <title> <command> [command args...]
911 # Make a GDM/KDM Session file. The title is the file to execute to start the
912 # Window Manager. The command is the name of the Window Manager.
914 # You can set the name of the file via the ${wm} variable.
915 make_session_desktop() {
916 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
917 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
921 local desktop=${T}/${wm:-${PN}}.desktop
924 cat <<-EOF > "${desktop}"
927 Comment=This session logs you into ${title}
934 # wrap the env here so that the 'insinto' call
935 # doesn't corrupt the env of the caller
936 insinto /usr/share/xsessions
944 # Install the list of .desktop menu files into the appropriate directory
945 # (/usr/share/applications).
948 # wrap the env here so that the 'insinto' call
949 # doesn't corrupt the env of the caller
951 insinto /usr/share/applications
953 if [[ -f ${i} ]] ; then
956 elif [[ -d ${i} ]] ; then
957 for j in "${i}"/*.desktop ; do
970 # @USAGE: <menu> <newname>
972 # Like all other new* functions, install the specified menu as newname.
975 # wrap the env here so that the 'insinto' call
976 # doesn't corrupt the env of the caller
977 insinto /usr/share/applications
982 # @FUNCTION: _iconins
985 # function for use in doicon and newicon
988 # wrap the env here so that the 'insinto' call
989 # doesn't corrupt the env of the caller
990 local funcname=$1; shift
995 while [[ $# -gt 0 ]] ; do
998 if [[ ${2%%x*}x${2%%x*} == "$2" ]] ; then
1004 16|22|24|32|36|48|64|72|96|128|192|256|512)
1005 size=${size}x${size};;
1009 eerror "${size} is an unsupported icon size!"
1020 if [[ -z ${size} ]] ; then
1021 insinto /usr/share/pixmaps
1023 insinto /usr/share/icons/${theme}/${size}/${context}
1026 if [[ ${funcname} == doicon ]] ; then
1027 if [[ -f $1 ]] ; then
1029 elif [[ -d $1 ]] ; then
1031 doins "${1}"/*.{png,svg}
1034 eerror "${1} is not a valid file/directory!"
1043 if [[ ${funcname} == newicon ]] ; then
1050 # @USAGE: [options] <icons>
1052 # Install icon into the icon directory /usr/share/icons or into
1053 # /usr/share/pixmaps if "--size" is not set.
1054 # This is useful in conjunction with creating desktop/menu files.
1059 # !!! must specify to install into /usr/share/icons/... !!!
1060 # size of the icon, like 48 or 48x48
1061 # supported icon sizes are:
1062 # 16 22 24 32 36 48 64 72 96 128 192 256 512 scalable
1064 # defaults to "apps"
1066 # defaults to "hicolor"
1068 # icons: list of icons
1070 # example 1: doicon foobar.png fuqbar.svg suckbar.png
1071 # results in: insinto /usr/share/pixmaps
1072 # doins foobar.png fuqbar.svg suckbar.png
1074 # example 2: doicon -s 48 foobar.png fuqbar.png blobbar.png
1075 # results in: insinto /usr/share/icons/hicolor/48x48/apps
1076 # doins foobar.png fuqbar.png blobbar.png
1079 _iconins ${FUNCNAME} "$@"
1082 # @FUNCTION: newicon
1083 # @USAGE: [options] <icon> <newname>
1085 # Like doicon, install the specified icon as newname.
1088 # example 1: newicon foobar.png NEWNAME.png
1089 # results in: insinto /usr/share/pixmaps
1090 # newins foobar.png NEWNAME.png
1092 # example 2: newicon -s 48 foobar.png NEWNAME.png
1093 # results in: insinto /usr/share/icons/hicolor/48x48/apps
1094 # newins foobar.png NEWNAME.png
1097 _iconins ${FUNCNAME} "$@"
1100 # @FUNCTION: strip-linguas
1101 # @USAGE: [<allow LINGUAS>|<-i|-u> <directories of .po files>]
1103 # Make sure that LINGUAS only contains languages that
1104 # a package can support. The first form allows you to
1105 # specify a list of LINGUAS. The -i builds a list of po
1106 # files found in all the directories and uses the
1107 # intersection of the lists. The -u builds a list of po
1108 # files found in all the directories and uses the union
1112 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
1114 ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
1117 if [[ ${op} == "-u" ]] ; then
1122 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
1123 if [[ ${op} == "-i" ]] ; then
1124 has ${f} ${ls} && newls="${newls} ${f}"
1126 has ${f} ${ls} || newls="${newls} ${f}"
1137 for f in ${LINGUAS} ; do
1138 if has ${f} ${ls} ; then
1139 newls="${newls} ${f}"
1145 && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1146 export LINGUAS=${newls:1}
1149 # @FUNCTION: preserve_old_lib
1150 # @USAGE: <libs to preserve> [more libs]
1152 # These functions are useful when a lib in your package changes ABI SONAME.
1153 # An example might be from libogg.so.0 to libogg.so.1. Removing libogg.so.0
1154 # would break packages that link against it. Most people get around this
1155 # by using the portage SLOT mechanism, but that is not always a relevant
1156 # solution, so instead you can call this from pkg_preinst. See also the
1157 # preserve_old_lib_notify function.
1158 preserve_old_lib() {
1159 _eutils_eprefix_init
1160 if [[ ${EBUILD_PHASE} != "preinst" ]] ; then
1161 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1162 die "Invalid preserve_old_lib() usage"
1164 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1166 # let portage worry about it
1167 has preserve-libs ${FEATURES} && return 0
1170 for lib in "$@" ; do
1171 [[ -e ${EROOT}/${lib} ]] || continue
1173 dodir ${dir} || die "dodir ${dir} failed"
1174 cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed"
1175 touch "${ED}"/${lib}
1179 # @FUNCTION: preserve_old_lib_notify
1180 # @USAGE: <libs to notify> [more libs]
1182 # Spit helpful messages about the libraries preserved by preserve_old_lib.
1183 preserve_old_lib_notify() {
1184 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then
1185 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only"
1186 die "Invalid preserve_old_lib_notify() usage"
1189 # let portage worry about it
1190 has preserve-libs ${FEATURES} && return 0
1192 _eutils_eprefix_init
1195 for lib in "$@" ; do
1196 [[ -e ${EROOT}/${lib} ]] || continue
1197 if [[ ${notice} -eq 0 ]] ; then
1199 ewarn "Old versions of installed libraries were detected on your system."
1200 ewarn "In order to avoid breaking packages that depend on these old libs,"
1201 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1202 ewarn "in order to remove these old dependencies. If you do not have this"
1203 ewarn "helper program, simply emerge the 'gentoolkit' package."
1206 ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'"
1210 # @FUNCTION: built_with_use
1211 # @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1214 # Deprecated: Use EAPI 2 use deps in DEPEND|RDEPEND and with has_version calls.
1216 # A temporary hack until portage properly supports DEPENDing on USE
1217 # flags being enabled in packages. This will check to see if the specified
1218 # DEPEND atom was built with the specified list of USE flags. The
1219 # --missing option controls the behavior if called on a package that does
1220 # not actually support the defined USE flags (aka listed in IUSE).
1221 # The default is to abort (call die). The -a and -o flags control
1222 # the requirements of the USE flags. They correspond to "and" and "or"
1223 # logic. So the -a flag means all listed USE flags must be enabled
1224 # while the -o flag means at least one of the listed IUSE flags must be
1225 # enabled. The --hidden option is really for internal use only as it
1226 # means the USE flag we're checking is hidden expanded, so it won't be found
1227 # in IUSE like normal USE flags.
1229 # Remember that this function isn't terribly intelligent so order of optional
1232 _eutils_eprefix_init
1234 if [[ $1 == "--hidden" ]] ; then
1239 local missing_action="die"
1240 if [[ $1 == "--missing" ]] ; then
1243 case ${missing_action} in
1245 *) die "unknown action '${missing_action}'";;
1250 [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
1252 local PKG=$(best_version $1)
1253 [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package"
1256 local USEFILE=${EROOT}/var/db/pkg/${PKG}/USE
1257 local IUSEFILE=${EROOT}/var/db/pkg/${PKG}/IUSE
1259 # if the IUSE file doesn't exist, the read will error out, we need to handle
1261 if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]] ; then
1262 case ${missing_action} in
1265 die) die "Unable to determine what USE flags $PKG was built with";;
1269 if [[ ${hidden} == "no" ]] ; then
1270 local IUSE_BUILT=( $(<"${IUSEFILE}") )
1271 # Don't check USE_EXPAND #147237
1273 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do
1274 if [[ $1 == ${expand}_* ]] ; then
1279 if [[ -n ${expand} ]] ; then
1280 if ! has $1 ${IUSE_BUILT[@]#[-+]} ; then
1281 case ${missing_action} in
1284 die) die "$PKG does not actually support the $1 USE flag!";;
1290 local USE_BUILT=$(<${USEFILE})
1291 while [[ $# -gt 0 ]] ; do
1292 if [[ ${opt} = "-o" ]] ; then
1293 has $1 ${USE_BUILT} && return 0
1295 has $1 ${USE_BUILT} || return 1
1302 # If an overlay has eclass overrides, but doesn't actually override the
1303 # libtool.eclass, we'll have ECLASSDIR pointing to the active overlay's
1304 # eclass/ dir, but libtool.eclass is still in the main Gentoo tree. So
1305 # add a check to locate the ELT-patches/ regardless of what's going on.
1306 # Note: Duplicated in libtool.eclass.
1307 _EUTILS_ECLASSDIR_LOCAL=${BASH_SOURCE[0]%/*}
1308 eutils_elt_patch_dir() {
1309 local d="${ECLASSDIR}/ELT-patches"
1310 if [[ ! -d ${d} ]] ; then
1311 d="${_EUTILS_ECLASSDIR_LOCAL}/ELT-patches"
1316 # @FUNCTION: epunt_cxx
1317 # @USAGE: [dir to scan]
1319 # Many configure scripts wrongly bail when a C++ compiler could not be
1320 # detected. If dir is not specified, then it defaults to ${S}.
1322 # https://bugs.gentoo.org/73450
1325 [[ -z ${dir} ]] && dir=${S}
1326 ebegin "Removing useless C++ checks"
1328 while IFS= read -r -d '' f; do
1329 for p in "$(eutils_elt_patch_dir)"/nocxx/*.patch ; do
1330 if patch --no-backup-if-mismatch -p1 "${f}" "${p}" >/dev/null ; then
1335 done < <(find "${dir}" -name configure -print0)
1337 if [[ -z ${any_found} ]]; then
1338 eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt)."
1343 # @FUNCTION: make_wrapper
1344 # @USAGE: <wrapper> <target> [chdir] [libpaths] [installpath]
1346 # Create a shell wrapper script named wrapper in installpath
1347 # (defaults to the bindir) to execute target (default of wrapper) by
1348 # first optionally setting LD_LIBRARY_PATH to the colon-delimited
1349 # libpaths followed by optionally changing directory to chdir.
1351 _eutils_eprefix_init
1352 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1353 local tmpwrapper=$(emktemp)
1357 [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}"
1358 if [[ -n ${libdir} ]] ; then
1360 if [[ ${CHOST} == *-darwin* ]] ; then
1361 var=DYLD_LIBRARY_PATH
1366 if [ "\${${var}+set}" = "set" ] ; then
1367 export ${var}="\${${var}}:${EPREFIX}${libdir}"
1369 export ${var}="${EPREFIX}${libdir}"
1373 # We don't want to quote ${bin} so that people can pass complex
1374 # things as ${bin} ... "./someprog --args"
1375 printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}"
1377 chmod go+rx "${tmpwrapper}"
1379 if [[ -n ${path} ]] ; then
1382 newexe "${tmpwrapper}" "${wrapper}"
1385 newbin "${tmpwrapper}" "${wrapper}" || die
1389 # @FUNCTION: path_exists
1390 # @USAGE: [-a|-o] <paths>
1392 # Check if the specified paths exist. Works for all types of paths
1393 # (files/dirs/etc...). The -a and -o flags control the requirements
1394 # of the paths. They correspond to "and" and "or" logic. So the -a
1395 # flag means all the paths must exist while the -o flag means at least
1396 # one of the paths must exist. The default behavior is "and". If no
1397 # paths are specified, then the return value is "false".
1400 [[ ${opt} == -[ao] ]] && shift || opt="-a"
1402 # no paths -> return false
1403 # same behavior as: [[ -e "" ]]
1404 [[ $# -eq 0 ]] && return 1
1413 -a) return $(( r != 0 )) ;;
1414 -o) return $(( r == $# )) ;;
1418 # @FUNCTION: use_if_iuse
1421 # Return true if the given flag is in USE and IUSE.
1423 # Note that this function should not be used in the global scope.
1425 in_iuse $1 || return 1
1429 # @FUNCTION: prune_libtool_files
1430 # @USAGE: [--all|--modules]
1432 # Locate unnecessary libtool files (.la) and libtool static archives
1433 # (.a) and remove them from installation image.
1435 # By default, .la files are removed whenever the static linkage can
1436 # either be performed using pkg-config or doesn't introduce additional
1439 # If '--modules' argument is passed, .la files for modules (plugins) are
1440 # removed as well. This is usually useful when the package installs
1441 # plugins and the plugin loader does not use .la files.
1443 # If '--all' argument is passed, all .la files are removed without
1444 # performing any heuristic on them. You shouldn't ever use that,
1445 # and instead report a bug in the algorithm instead.
1447 # The .a files are only removed whenever corresponding .la files state
1448 # that they should not be linked to, i.e. whenever these files
1449 # correspond to plugins.
1451 # Note: if your package installs both static libraries and .pc files
1452 # which use variable substitution for -l flags, you need to add
1453 # pkg-config to your DEPEND.
1454 prune_libtool_files() {
1455 debug-print-function ${FUNCNAME} "$@"
1457 local removing_all removing_modules opt
1458 _eutils_eprefix_init
1469 die "Invalid argument to ${FUNCNAME}(): ${opt}"
1475 while IFS= read -r -d '' f; do # for all .la files
1476 local archivefile=${f/%.la/.a}
1478 # The following check is done by libtool itself.
1479 # It helps us avoid removing random files which match '*.la',
1481 if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
1485 [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed'
1486 local reason= pkgconfig_scanned=
1487 local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}")
1489 if [[ ${snotlink} == yes ]]; then
1491 # Remove static libs we're not supposed to link against.
1492 if [[ -f ${archivefile} ]]; then
1493 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)"
1494 queue+=( "${archivefile}" )
1497 # The .la file may be used by a module loader, so avoid removing it
1498 # unless explicitly requested.
1499 if [[ ${removing_modules} ]]; then
1505 # Remove .la files when:
1506 # - user explicitly wants us to remove all .la files,
1507 # - respective static archive doesn't exist,
1508 # - they are covered by a .pc file already,
1509 # - they don't provide any new information (no libs & no flags).
1511 if [[ ${removing_all} ]]; then
1513 elif [[ ! -f ${archivefile} ]]; then
1514 reason='no static archive'
1515 elif [[ ! $(sed -nre \
1516 "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" \
1518 reason='no libs & flags'
1520 if [[ ! ${pkgconfig_scanned} ]]; then
1521 # Create a list of all .pc-covered libs.
1523 if [[ ! ${removing_all} ]]; then
1525 local tf=${T}/prune-lt-files.pc
1526 local pkgconf=$(tc-getPKG_CONFIG)
1528 while IFS= read -r -d '' pc; do # for all .pc files
1531 # Use pkg-config if available (and works),
1533 if ${pkgconf} --exists "${pc}" &>/dev/null; then
1534 sed -e '/^Requires:/d' "${pc}" > "${tf}"
1535 libs=$(${pkgconf} --libs "${tf}")
1537 libs=$(sed -ne 's/^Libs://p' "${pc}")
1540 for arg in ${libs}; do
1541 if [[ ${arg} == -l* ]]; then
1542 if [[ ${arg} == '*$*' ]]; then
1543 eqawarn "${FUNCNAME}: variable substitution likely failed in ${pc}"
1544 eqawarn "(arg: ${arg})"
1545 eqawarn "Most likely, you need to add virtual/pkgconfig to DEPEND."
1548 pc_libs+=( lib${arg#-l}.la )
1551 done < <(find "${D}" -type f -name '*.pc' -print0)
1557 fi # pkgconfig_scanned
1559 has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc'
1560 fi # removal due to .pc
1562 fi # shouldnotlink==no
1564 if [[ ${reason} ]]; then
1565 einfo "Removing unnecessary ${f#${D%/}} (${reason})"
1568 done < <(find "${ED}" -xtype f -name '*.la' -print0)
1570 if [[ ${queue[@]} ]]; then
1575 # @FUNCTION: optfeature
1576 # @USAGE: <short description> <package atom to match> [other atoms]
1578 # Print out a message suggesting an optional package (or packages) which
1579 # provide the described functionality
1581 # The following snippet would suggest app-misc/foo for optional foo support,
1582 # app-misc/bar or app-misc/baz[bar] for optional bar support
1583 # and either both app-misc/a and app-misc/b or app-misc/c for alphabet support.
1585 # optfeature "foo support" app-misc/foo
1586 # optfeature "bar support" app-misc/bar app-misc/baz[bar]
1587 # optfeature "alphabet support" "app-misc/a app-misc/b" app-misc/c
1590 debug-print-function ${FUNCNAME} "$@"
1597 if has_version "${j}"; then
1604 if [[ ${flag} -eq 1 ]]; then
1608 if [[ ${flag} -eq 0 ]]; then
1614 msg="${msg:0: -4} for ${desc}"
1621 die "you no longer need this as portage supports ACCEPT_LICENSE itself"
1630 # Sleep for the specified number of seconds (default of 5 seconds). Useful when
1631 # printing a message the user should probably be reading and often used in
1632 # conjunction with the ebeep function. If the EPAUSE_IGNORE env var is set,
1633 # don't wait at all. Defined in EAPIs 0 1 and 2.
1635 [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
1639 # @USAGE: [number of beeps]
1641 # Issue the specified number of beeps (default of 5 beeps). Useful when
1642 # printing a message the user should probably be reading and often used in
1643 # conjunction with the epause function. If the EBEEP_IGNORE env var is set,
1644 # don't beep at all. Defined in EAPIs 0 1 and 2.
1647 if [[ -z ${EBEEP_IGNORE} ]] ; then
1648 for ((n=1 ; n <= ${1:-5} ; n++)) ; do
1650 sleep 0.1 &>/dev/null ; sleep 0,1 &>/dev/null
1661 ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
1665 ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
1675 # @USAGE: <USE flag> [true output] [false output] [true suffix] [false suffix]
1677 # Proxy to declare usex for package managers or EAPIs that do not provide it
1678 # and use the package manager implementation when available (i.e. EAPI >= 5).
1679 # If USE flag is set, echo [true output][true suffix] (defaults to "yes"),
1680 # otherwise echo [false output][false suffix] (defaults to "no").
1681 usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
1689 # @VARIABLE: EPATCH_USER_SOURCE
1691 # Location for user patches, see the epatch_user function.
1692 # Should be set by the user. Don't set this in ebuilds.
1693 : ${EPATCH_USER_SOURCE:=${PORTAGE_CONFIGROOT%/}/etc/portage/patches}
1695 # @FUNCTION: epatch_user
1698 # Applies user-provided patches to the source tree. The patches are
1699 # taken from /etc/portage/patches/<CATEGORY>/<P-PR|P|PN>[:SLOT]/, where the first
1700 # of these three directories to exist will be the one to use, ignoring
1701 # any more general directories which might exist as well. They must end
1702 # in ".patch" to be applied.
1704 # User patches are intended for quick testing of patches without ebuild
1705 # modifications, as well as for permanent customizations a user might
1706 # desire. Obviously, there can be no official support for arbitrarily
1707 # patched ebuilds. So whenever a build log in a bug report mentions that
1708 # user patches were applied, the user should be asked to reproduce the
1709 # problem without these.
1711 # Not all ebuilds do call this function, so placing patches in the
1712 # stated directory might or might not work, depending on the package and
1713 # the eclasses it inherits and uses. It is safe to call the function
1714 # repeatedly, so it is always possible to add a call at the ebuild
1715 # level. The first call is the time when the patches will be
1718 # Ideally, this function should be called after gentoo-specific patches
1719 # have been applied, so that their code can be modified as well, but
1720 # before calls to e.g. eautoreconf, as the user patches might affect
1721 # autotool input files as well.
1723 [[ $# -ne 0 ]] && die "epatch_user takes no options"
1725 # Allow multiple calls to this function; ignore all but the first
1726 local applied="${T}/epatch_user.log"
1727 [[ -e ${applied} ]] && return 2
1729 # don't clobber any EPATCH vars that the parent might want
1730 local EPATCH_SOURCE check
1731 for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT%/*}}; do
1732 EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CTARGET}/${check}
1733 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CHOST}/${check}
1734 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${check}
1735 if [[ -d ${EPATCH_SOURCE} ]] ; then
1736 local old_n_applied_patches=${EPATCH_N_APPLIED_PATCHES:-0}
1737 EPATCH_SOURCE=${EPATCH_SOURCE} \
1738 EPATCH_SUFFIX="patch" \
1739 EPATCH_FORCE="yes" \
1740 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
1742 echo "${EPATCH_SOURCE}" > "${applied}"
1743 if [[ ${old_n_applied_patches} -lt ${EPATCH_N_APPLIED_PATCHES} ]]; then
1744 has epatch_user_death_notice ${EBUILD_DEATH_HOOKS} || \
1745 EBUILD_DEATH_HOOKS+=" epatch_user_death_notice"
1750 echo "none" > "${applied}"
1754 # @FUNCTION: epatch_user_death_notice
1757 # Include an explicit notice in the die message itself that user patches were
1758 # applied to this build.
1759 epatch_user_death_notice() {
1760 ewarn "!!! User patches were applied to this build!"
1763 # @FUNCTION: einstalldocs
1765 # Install documentation using DOCS and HTML_DOCS.
1767 # If DOCS is declared and non-empty, all files listed in it are
1768 # installed. The files must exist, otherwise the function will fail.
1769 # In EAPI 4 and subsequent EAPIs DOCS may specify directories as well,
1770 # in other EAPIs using directories is unsupported.
1772 # If DOCS is not declared, the files matching patterns given
1773 # in the default EAPI implementation of src_install will be installed.
1774 # If this is undesired, DOCS can be set to empty value to prevent any
1775 # documentation from being installed.
1777 # If HTML_DOCS is declared and non-empty, all files and/or directories
1778 # listed in it are installed as HTML docs (using dohtml).
1780 # Both DOCS and HTML_DOCS can either be an array or a whitespace-
1781 # separated list. Whenever directories are allowed, '<directory>/.' may
1782 # be specified in order to install all files within the directory
1783 # without creating a sub-directory in docdir.
1785 # Passing additional options to dodoc and dohtml is not supported.
1786 # If you needed such a thing, you need to call those helpers explicitly.
1788 debug-print-function ${FUNCNAME} "${@}"
1791 has ${EAPI} 0 1 2 3 && dodoc_opts=
1793 if ! declare -p DOCS &>/dev/null ; then
1795 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
1796 THANKS BUGS FAQ CREDITS CHANGELOG ; do
1797 if [[ -s ${d} ]] ; then
1801 elif [[ $(declare -p DOCS) == "declare -a"* ]] ; then
1802 if [[ ${DOCS[@]} ]] ; then
1803 dodoc ${dodoc_opts} "${DOCS[@]}" || die
1806 if [[ ${DOCS} ]] ; then
1807 dodoc ${dodoc_opts} ${DOCS} || die
1811 if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]] ; then
1812 if [[ ${HTML_DOCS[@]} ]] ; then
1813 dohtml -r "${HTML_DOCS[@]}" || die
1816 if [[ ${HTML_DOCS} ]] ; then
1817 dohtml -r ${HTML_DOCS} || die
1824 # @FUNCTION: in_iuse
1827 # Determines whether the given flag is in IUSE. Strips IUSE default prefixes
1830 # Note that this function should not be used in the global scope.
1832 debug-print-function ${FUNCNAME} "${@}"
1833 [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()"
1836 local liuse=( ${IUSE} )
1838 has "${flag}" "${liuse[@]#[+-]}"