# Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ # - /etc/portage/bashrc # -solar 2004-2006 # - updated last Jul 29 2006 hasq() { local x local me=$1 shift # All the TTY checks really only help out depend. Which is nice. # Logging kills all this anyway. Everything becomes a pipe. --NJ for x in "$@"; do if [ "${x}" == "${me}" ]; then return 0 fi done return 1 } has() { if hasq "$@"; then return 0 fi return 1 } eecho() { case "x${NOCOLOR}" in x[y,Y][e,E][s,S]|x-[t,T][r,R][u,U][e,E]|x) echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ';; x*) echo -n ">>> ";; esac echo "$*" } has-sandbox() { #echo LD_PRELOAD="${LD_PRELOAD}" for PRELOAD in $(echo ${LD_PRELOAD} | /bin/tr : ' '); do #echo PRELOAD=$PRELOAD - BASE_PRELOAD=${PRELOAD##*/} [ "${PRELOAD##*/}" = "libsandbox.so" ] && return 0 done return 1 } package-distdir-clean() { local a x for a in ${FEATURES} ; do if [ "$a" = "distclean" ]; then for x in ${SRC_URI}; do x=$(/bin/basename $x) dx=$(readlink -f ${DISTDIR}/${x}) if [[ -f $dx ]]; then size="$(/bin/ls -lh ${dx} | /bin/awk '{print $5}')" eecho "All done with ${x} Removing it to save ${size}" /bin/rm ${dx} fi done fi done } append-cflags() { export CFLAGS="${CFLAGS} $*" export CXXFLAGS="${CXXFLAGS} $*" return 0 } package-cflags() { local target flags flag i; # bail if file does not exist or is not readable. [ -r ${ROOT}/etc/portage/package.cflags ] || return 0 # need bash >= 3 if [ "${BASH_VERSINFO[0]}" -le 2 ]; then eecho "Need bash3 for this bashrc script to work" return 0 fi while read -a target; do if [[ ${target[@]%%#*} ]]; then # valid syntax no >=" ]]; then skip=0 if [[ ${target} != ${CATEGORY} ]] ; then if [[ ${target} != ${CATEGORY}/${PN} ]] ; then skip=1 fi fi if [ "${skip}" == 0 ] ; then flags=(${target[@]:1}) if [[ ${flags[@]} =~ 'CFLAGS' ]]; then for (( i = 0; i < ${#flags[@]}; i++ )); do if [[ ${flags[$i]} =~ 'CFLAGS' ]]; then append-cflags $(eval echo "${flags[$i]}") unset flags[$i] fi done fi for flag in ${flags[@]}; do if [[ ${CFLAGS} =~ ${flag} ]]; then continue 1 else append-cflags "${flag}" fi done export -n C{,XX}FLAGS #eecho "Using package.cflags entry for target ${target} for ${CATEGORY}/${PN}" fi fi fi done < ${ROOT}/etc/portage/package.cflags } verify_needed() { local x files needed orphans for x in scanelf q; do if ! type -p ${x} 2>&1 > /dev/null; then return 0 fi done # make sure we have app-portage/portage-utils-0.1.20 or later. q file -Ch | grep -q -- --orphans [[ $? != 0 ]] && return 0 files="$(q list -Co $1)" needed=$(echo "${files}" | scanelf -Bqn -f - -F '%n#F' | tr , '\n' | sort -u | tr '\n' ' ') [[ $needed == "" ]] && return 0 orphans=$(q file -Co ${needed} | tr '\n' ' ') [[ $orphans == "" ]] && return 0 eecho '!!! '"ELF DT_NEEDED orphans: $1" # TODO: lookup orphan file owner. for x in ${orphans}; do echo "!!! $x : "$(echo "${files}" | scanelf -Bq -f - -F '%F#N' -N ${x} | tr '\n' ' ') done } PATH=$PATH:/usr/sbin:/usr/bin:/bin:/sbin /bin/mkdir -p /var/tmp/portage/PORT_LOGDIR/ /dev/shm/portage case "$EBUILD_PHASE" in # try to stay quiet here. #depend) : auto_overlay ;; depend) : ;; prerm|postrm|clean) : ;; setup|unpack|postinst|compile) if has-sandbox ; then [ "$NOCOLOR" = "false" ] && i=$(echo -ne '\e[1;32m+\e[0m') || i="+" else [ "$NOCOLOR" = "false" ] && i=$(echo -ne '\e[1;31m-\e[0m') || i="-" fi eecho "$USER ${i}sandbox($EBUILD_PHASE)" package-cflags if [ "`hasq debug ${FEATURES}`" != "" -a "$EBUILD_PHASE" = "setup" ]; then DEBUG="yes" RESTRICT="$RESTRICT nostrip" export CFLAGS="${CFLAGS/-fomit-frame-pointer/} -g3" export CXXFLAGS="${CXXFLAGS/-fomit-frame-pointer/} -g3" export LDFLAGS="${LDFLAGS} -ggdb" fi if [ "$EBUILD_PHASE" = "postinst" ];then package-distdir-clean verify_needed "${CATEGORY}/${PF}" if [ "${ROOT}" == "/" ] || [ "${ROOT}" == "" ] && [ "${FEATURES/*genpkgindex*/}" != "$FEATURES" ]; then [ -x ${PORTDIR}/local/bin/genpkgindex ] && ${PORTDIR}/local/bin/genpkgindex fi fi ;; esac restrict_maybe() { local x local RESTRICT_STRICTER="pam distlibc ppp zip unzip valgrind" for x in ${RESTRICT_STRICTER}; do if [ $x == $1 ]; then eecho "Restricting stricter on $x" return 1 fi done return 0 } if [ "${FEATURES/*stricter*/}" != "$FEATURES" ] && (restrict_maybe $PN); then export FEATURES="${FEATURES/stricter/}" fi if [[ $AUTOPATCH != "" ]] && [[ $EBUILD_PHASE == compile ]]; then [[ ! -d "$PATCH_OVERLAY" ]] && eecho "PATCH_OVERLAY=$PATCH_OVERLAY is not a dir" if [ ! -r /etc/portage/bashrc.autopatch ]; then eecho "bashrc.autopatch is not readable" else eecho "Checking for auto patches" source /etc/portage/bashrc.autopatch fi fi :