2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
7 export _E_EXEDESTTREE_=""
8 export _E_DOCDESTTREE_=""
9 export INSOPTIONS="-m0644"
10 export EXEOPTIONS="-m0755"
11 export LIBOPTIONS="-m0644"
12 export DIROPTIONS="-m0755"
14 declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
15 declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
18 if [ "$1" == "/" ]; then
22 [[ " ${USE} " == *" prefix "* ]] || \
23 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
24 if [ ! -d "${ED}${DESTTREE}" ]; then
25 install -d "${ED}${DESTTREE}"
27 if [[ $ret -ne 0 ]] ; then
28 helpers_die "${FUNCNAME[0]} failed"
36 if [ "$1" == "/" ]; then
40 [[ " ${USE} " == *" prefix "* ]] || \
41 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
42 if [ ! -d "${ED}${INSDESTTREE}" ]; then
43 install -d "${ED}${INSDESTTREE}"
45 if [[ $ret -ne 0 ]] ; then
46 helpers_die "${FUNCNAME[0]} failed"
54 if [ "$1" == "/" ]; then
55 export _E_EXEDESTTREE_=""
57 export _E_EXEDESTTREE_="$1"
58 [[ " ${USE} " == *" prefix "* ]] || \
59 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
60 if [ ! -d "${ED}${_E_EXEDESTTREE_}" ]; then
61 install -d "${ED}${_E_EXEDESTTREE_}"
63 if [[ $ret -ne 0 ]] ; then
64 helpers_die "${FUNCNAME[0]} failed"
72 if [ "$1" == "/" ]; then
73 export _E_DOCDESTTREE_=""
75 export _E_DOCDESTTREE_="$1"
76 [[ " ${USE} " == *" prefix "* ]] || \
77 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
78 if [ ! -d "${ED}usr/share/doc/${PF}/${_E_DOCDESTTREE_}" ]; then
79 install -d "${ED}usr/share/doc/${PF}/${_E_DOCDESTTREE_}"
81 if [[ $ret -ne 0 ]] ; then
82 helpers_die "${FUNCNAME[0]} failed"
90 export INSOPTIONS="$@"
92 # `install` should never be called with '-s' ...
93 has -s ${INSOPTIONS} && die "Never call insopts() with -s"
97 export DIROPTIONS="$@"
101 export EXEOPTIONS="$@"
103 # `install` should never be called with '-s' ...
104 has -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
108 export LIBOPTIONS="$@"
110 # `install` should never be called with '-s' ...
111 has -s ${LIBOPTIONS} && die "Never call libopts() with -s"
115 has "${EAPI}" 0 1 2 3 && die "'docompress' not supported in this EAPI"
118 if [[ $1 = "-x" ]]; then
121 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
122 [[ ${f:0:1} = / ]] || f="/${f}"
123 for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
124 [[ ${f} = "${g}" ]] && continue 2
126 PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
130 f=$(strip_duplicate_slashes "${f}"); f=${f%/}
131 [[ ${f:0:1} = / ]] || f="/${f}"
132 for g in "${PORTAGE_DOCOMPRESS[@]}"; do
133 [[ ${f} = "${g}" ]] && continue 2
135 PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
140 # adds ".keep" files so that dirs aren't auto-cleaned
144 [[ " ${USE} " == *" prefix "* ]] || \
145 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
146 if [ "$1" == "-R" ] || [ "$1" == "-r" ]; then
148 find "$@" -type d -printf "${ED}%p/.keep_${CATEGORY}_${PN}-${SLOT}\n" \
150 while read -r -d $'\0' ; do
152 die "Failed to recursively create .keep files"
156 >> "${ED}${x}/.keep_${CATEGORY}_${PN}-${SLOT}" || \
157 die "Failed to create .keep in ${ED}${x}"
164 has $EBUILD_PHASE prerm postrm || eqawarn \
165 "QA Notice: The 'useq' function is deprecated (replaced by 'use')"
181 # if we got something like '!flag', then invert the return value
182 if [[ ${u:0:1} == "!" ]] ; then
187 if [[ $EBUILD_PHASE = depend ]] ; then
188 # TODO: Add a registration interface for eclasses to register
189 # any number of phase hooks, so that global scope eclass
190 # initialization can by migrated to phase hooks in new EAPIs.
191 # Example: add_phase_hook before pkg_setup $ECLASS_pre_pkg_setup
192 #if [[ -n $EAPI ]] && ! has "$EAPI" 0 1 2 3 ; then
193 # die "use() called during invalid phase: $EBUILD_PHASE"
197 # Make sure we have this USE flag in IUSE
198 elif [[ -n $PORTAGE_IUSE && -n $EBUILD_PHASE ]] ; then
199 [[ $u =~ $PORTAGE_IUSE ]] || \
200 eqawarn "QA Notice: USE Flag '${u}' not" \
201 "in IUSE for ${CATEGORY}/${PF}"
204 if has ${u} ${USE} ; then
213 echo "!!! use_with() called without a parameter." >&2
214 echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
218 if ! has "${EAPI:-0}" 0 1 2 3 ; then
219 local UW_SUFFIX=${3+=$3}
221 local UW_SUFFIX=${3:+=$3}
226 echo "--with-${UWORD}${UW_SUFFIX}"
228 echo "--without-${UWORD}"
235 echo "!!! use_enable() called without a parameter." >&2
236 echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
240 if ! has "${EAPI:-0}" 0 1 2 3 ; then
241 local UE_SUFFIX=${3+=$3}
243 local UE_SUFFIX=${3:+=$3}
248 echo "--enable-${UWORD}${UE_SUFFIX}"
250 echo "--disable-${UWORD}"
260 local eapi=${EAPI:-0}
261 [ -z "$*" ] && die "Nothing passed to the 'unpack' command"
264 vecho ">>> Unpacking ${x} to ${PWD}"
268 if [[ ${x} == "./"* ]] ; then
270 elif [[ ${x} == ${DISTDIR%/}/* ]] ; then
271 die "Arguments to unpack() cannot begin with \${DISTDIR}."
272 elif [[ ${x} == "/"* ]] ; then
273 die "Arguments to unpack() cannot be absolute"
277 [[ ! -s ${srcdir}${x} ]] && die "${x} does not exist"
280 if [ "${y}" == "tar" ]; then
281 $1 -c -- "$srcdir$x" | tar xof -
282 assert_sigpipe_ok "$myfail"
284 local cwd_dest=${x##*/}
285 cwd_dest=${cwd_dest%.*}
286 $1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "$myfail"
290 myfail="failure unpacking ${x}"
293 tar xof "$srcdir$x" || die "$myfail"
296 tar xozf "$srcdir$x" || die "$myfail"
299 ${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "$srcdir$x" | tar xof -
300 assert_sigpipe_ok "$myfail"
303 # unzip will interactively prompt under some error conditions,
304 # as reported in bug #336285
305 ( while true ; do echo n || break ; done ) | \
306 unzip -qo "${srcdir}${x}" || die "$myfail"
309 _unpack_tar "gzip -d"
312 _unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
316 my_output="$(7z x -y "${srcdir}${x}")"
317 if [ $? -ne 0 ]; then
318 echo "${my_output}" >&2
323 unrar x -idq -o+ "${srcdir}${x}" || die "$myfail"
326 lha xfq "${srcdir}${x}" || die "$myfail"
329 ar x "${srcdir}${x}" || die "$myfail"
332 # Unpacking .deb archives can not always be done with
333 # `ar`. For instance on AIX this doesn't work out. If
334 # we have `deb2targz` installed, prefer it over `ar` for
335 # that reason. We just make sure on AIX `deb2targz` is
337 if type -P deb2targz > /dev/null; then
339 local created_symlink=0
340 if [ ! "$srcdir$x" -ef "$y" ] ; then
341 # deb2targz always extracts into the same directory as
342 # the source file, so create a symlink in the current
343 # working directory if necessary.
344 ln -sf "$srcdir$x" "$y" || die "$myfail"
347 deb2targz "$y" || die "$myfail"
348 if [ $created_symlink = 1 ] ; then
349 # Clean up the symlink so the ebuild
350 # doesn't inadvertently install it.
353 mv -f "${y%.deb}".tar.gz data.tar.gz || die "$myfail"
355 ar x "$srcdir$x" || die "$myfail"
359 _unpack_tar "lzma -d"
362 if has $eapi 0 1 2 ; then
363 vecho "unpack ${x}: file format not recognized. Ignoring."
369 vecho "unpack ${x}: file format not recognized. Ignoring."
373 # Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
374 # should be preserved.
375 find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
376 ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
382 [[ " ${USE} " == *" prefix "* ]] || \
383 case "$EAPI" in 0|1|2) local EPREFIX= ;; esac
388 for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
392 _hasgq() { _hasg "$@" >/dev/null ; }
394 local phase_func=$(_ebuild_arg_to_phase "$EAPI" "$EBUILD_PHASE")
395 if [[ -n $phase_func ]] ; then
396 if has "$EAPI" 0 1 ; then
397 [[ $phase_func != src_compile ]] && \
398 eqawarn "QA Notice: econf called in" \
399 "$phase_func instead of src_compile"
401 [[ $phase_func != src_configure ]] && \
402 eqawarn "QA Notice: econf called in" \
403 "$phase_func instead of src_configure"
408 if [ -x "${ECONF_SOURCE}/configure" ]; then
409 if [[ -n $CONFIG_SHELL && \
410 "$(head -n1 "$ECONF_SOURCE/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
411 sed -e "1s:^#![[:space:]]*/bin/sh:#!$CONFIG_SHELL:" -i "$ECONF_SOURCE/configure" || \
412 die "Substition of shebang in '$ECONF_SOURCE/configure' failed"
414 if [ -e "${EPREFIX}"/usr/share/gnuconfig/ ]; then
415 find "${WORKDIR}" -type f '(' \
416 -name config.guess -o -name config.sub ')' -print0 | \
417 while read -r -d $'\0' x ; do
418 vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
419 cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}"
423 # EAPI=4 adds --disable-dependency-tracking to econf
424 if ! has "$EAPI" 0 1 2 3 3_pre2 && \
425 "${ECONF_SOURCE}/configure" --help 2>/dev/null | \
426 grep -q disable-dependency-tracking ; then
427 set -- --disable-dependency-tracking "$@"
430 # if the profile defines a location to install libs to aside from default, pass it on.
431 # if the ebuild passes in --libdir, they're responsible for the conf_libdir fun.
432 local CONF_LIBDIR LIBDIR_VAR="LIBDIR_${ABI}"
433 if [[ -n ${ABI} && -n ${!LIBDIR_VAR} ]] ; then
434 CONF_LIBDIR=${!LIBDIR_VAR}
436 if [[ -n ${CONF_LIBDIR} ]] && ! _hasgq --libdir=\* "$@" ; then
437 export CONF_PREFIX=$(_hasg --exec-prefix=\* "$@")
438 [[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(_hasg --prefix=\* "$@")
439 : ${CONF_PREFIX:=${EPREFIX}/usr}
440 CONF_PREFIX=${CONF_PREFIX#*=}
441 [[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
442 [[ ${CONF_LIBDIR} != /* ]] && CONF_LIBDIR="/${CONF_LIBDIR}"
443 set -- --libdir="$(strip_duplicate_slashes ${CONF_PREFIX}${CONF_LIBDIR})" "$@"
447 --prefix="${EPREFIX}"/usr \
448 ${CBUILD:+--build=${CBUILD}} \
450 ${CTARGET:+--target=${CTARGET}} \
451 --mandir="${EPREFIX}"/usr/share/man \
452 --infodir="${EPREFIX}"/usr/share/info \
453 --datadir="${EPREFIX}"/usr/share \
454 --sysconfdir="${EPREFIX}"/etc \
455 --localstatedir="${EPREFIX}"/var/lib \
458 vecho "${ECONF_SOURCE}/configure" "$@"
460 if ! "${ECONF_SOURCE}/configure" "$@" ; then
462 if [ -s config.log ]; then
464 echo "!!! Please attach the following file when seeking support:"
465 echo "!!! ${PWD}/config.log"
469 elif [ -f "${ECONF_SOURCE}/configure" ]; then
470 die "configure is not executable"
472 die "no configure script found"
477 # CONF_PREFIX is only set if they didn't pass in libdir above.
478 local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
479 [[ " ${USE} " == *" prefix "* ]] || \
480 case "$EAPI" in 0|1|2) local ED=${D} ;; esac
481 LIBDIR_VAR="LIBDIR_${ABI}"
482 if [ -n "${ABI}" -a -n "${!LIBDIR_VAR}" ]; then
483 CONF_LIBDIR="${!LIBDIR_VAR}"
486 if [ -n "${CONF_LIBDIR}" ] && [ "${CONF_PREFIX:+set}" = set ]; then
487 EI_DESTLIBDIR="${D}/${CONF_PREFIX}/${CONF_LIBDIR}"
488 EI_DESTLIBDIR="$(strip_duplicate_slashes ${EI_DESTLIBDIR})"
489 LOCAL_EXTRA_EINSTALL="libdir=${EI_DESTLIBDIR} ${LOCAL_EXTRA_EINSTALL}"
493 if [ -f ./[mM]akefile -o -f ./GNUmakefile ] ; then
494 if [ "${PORTAGE_DEBUG}" == "1" ]; then
495 ${MAKE:-make} -n prefix="${ED}usr" \
496 datadir="${ED}usr/share" \
497 infodir="${ED}usr/share/info" \
498 localstatedir="${ED}var/lib" \
499 mandir="${ED}usr/share/man" \
500 sysconfdir="${ED}etc" \
501 ${LOCAL_EXTRA_EINSTALL} \
502 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
505 ${MAKE:-make} prefix="${ED}usr" \
506 datadir="${ED}usr/share" \
507 infodir="${ED}usr/share/info" \
508 localstatedir="${ED}var/lib" \
509 mandir="${ED}usr/share/man" \
510 sysconfdir="${ED}etc" \
511 ${LOCAL_EXTRA_EINSTALL} \
512 ${MAKEOPTS} ${EXTRA_EMAKE} -j1 \
513 "$@" install || die "einstall failed"
515 die "no Makefile found"
519 _eapi0_pkg_nofetch() {
520 [ -z "${SRC_URI}" ] && return
522 elog "The following are listed in SRC_URI for ${PN}:"
524 for x in $(echo ${SRC_URI}); do
529 _eapi0_src_unpack() {
530 [[ -n ${A} ]] && unpack ${A}
533 _eapi0_src_compile() {
534 if [ -x ./configure ] ; then
541 # Since we don't want emake's automatic die
542 # support (EAPI 4 and later), and we also don't
543 # want the warning messages that it produces if
544 # we call it in 'nonfatal' mode, we use emake_cmd
545 # to emulate the desired parts of emake behavior.
546 local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
547 if $emake_cmd -j1 check -n &> /dev/null; then
548 vecho ">>> Test phase [check]: ${CATEGORY}/${PF}"
549 if ! $emake_cmd -j1 check; then
550 has test $FEATURES && die "Make check failed. See above for details."
551 has test $FEATURES || eerror "Make check failed. See above for details."
553 elif $emake_cmd -j1 test -n &> /dev/null; then
554 vecho ">>> Test phase [test]: ${CATEGORY}/${PF}"
555 if ! $emake_cmd -j1 test; then
556 has test $FEATURES && die "Make test failed. See above for details."
557 has test $FEATURES || eerror "Make test failed. See above for details."
560 vecho ">>> Test phase [none]: ${CATEGORY}/${PF}"
564 _eapi1_src_compile() {
569 _eapi2_src_configure() {
570 if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
575 _eapi2_src_compile() {
576 if [ -f Makefile ] || [ -f GNUmakefile ] || [ -f makefile ]; then
577 emake || die "emake failed"
581 _eapi4_src_install() {
582 if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
583 emake DESTDIR="${D}" install
586 if ! declare -p DOCS &>/dev/null ; then
588 for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
589 THANKS BUGS FAQ CREDITS CHANGELOG ; do
590 [[ -s "${d}" ]] && dodoc "${d}"
592 elif [[ $(declare -p DOCS) == "declare -a "* ]] ; then
599 # @FUNCTION: has_version
600 # @USAGE: <DEPEND ATOM>
602 # Return true if given package is installed. Otherwise return false.
603 # Callers may override the ROOT variable in order to match packages from an
610 [[ " ${USE} " == *" prefix "* ]] && \
611 eroot=${ROOT%/}${EPREFIX}/ || eroot=${ROOT}
614 eroot=${ROOT%/}${EPREFIX}/
617 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
618 "$PORTAGE_BIN_PATH"/ebuild-ipc has_version "${eroot}" "$1"
620 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
621 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" has_version "${eroot}" "$1"
629 die "unexpected portageq exit code: ${retval}"
634 # @FUNCTION: best_version
635 # @USAGE: <DEPEND ATOM>
637 # Returns the best/most-current match.
638 # Callers may override the ROOT variable in order to match packages from an
645 [[ " ${USE} " == *" prefix "* ]] && \
646 eroot=${ROOT%/}${EPREFIX}/ || eroot=${ROOT}
649 eroot=${ROOT%/}${EPREFIX}/
652 if [[ -n $PORTAGE_IPC_DAEMON ]] ; then
653 "$PORTAGE_BIN_PATH"/ebuild-ipc best_version "${eroot}" "$1"
655 PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
656 "${PORTAGE_PYTHON:-/usr/bin/python}" "${PORTAGE_BIN_PATH}/portageq" best_version "${eroot}" "$1"
664 die "unexpected portageq exit code: ${retval}"