# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# Borrowed from http://forums.gentoo.org/viewtopic.php?p=1749445
# This allows for per package CFLAGS, LDFLAGS, and FEATURES
# /etc/portage/bashrc

if [ "$0" = "/usr/lib/portage/bin/ebuild.sh" ]; then
    
    if [ "${DEBUG}" != "" ]; then
	echo ----------------------------------------------------
	echo \$_=$_
	echo \$\*=$*
	echo \$@=$@
	echo \$0=$0
	
	
	echo PORTDIR=$PORTDIR
	echo CATEGORY=$CATEGORY
	echo PN=$PN
	echo PV=$PV
	echo PR=$PR
	echo PF=$PF
	echo P=$P
	
	echo USER=$USER
	echo HOME=$HOME
	echo PATH=${PATH}
	echo LD_PRELOAD=${LD_PRELOAD}
	echo ----------------------------------------------------
    fi
    
    eecho() {
	[ "$NOCOLOR" = "false" ] && echo -ne '\e[1;34m>\e[1;36m>\e[1;35m>\e[0m ' || echo -n ">>> "
	echo "$*"
    }
    
    process() {
	## ${1} = /etc/portage/package.${1} file to parse ##
	PATH=/bin:/usr/bin:/sbin:/usr/sbin
	if [ -e ${ROOT}/etc/portage/package.${1} ]; then
	    save_IFS
	    IFS=$'\n'
	    for x in $(/bin/cat ${ROOT}/etc/portage/package.${1}); do
		unset IFS
		x="$(echo $x)"
		IFS=$'\n'
		if [ "${x:0:1}" != "#" ]; then
		    PKG="${x%%[$'\t\n ']*}"
		    if [ "$PKG" == "$CATEGORY/$PN" ]; then
			ENVAR=$(echo ${1} | tr [a-z] [A-Z])
			export ${ENVAR}="${x/$PKG /}"
			eecho "Setttng ${ENVAR}=${!ENVAR} package.${1} entry for $PN"
		    fi
		fi
	    done
	    restore_IFS
	fi
    }
    
    
    case "$*"  in
	# stay really quiet here.
	depend) : ;;
	unpack)
	    # Find and Set Per Package C{XX}FLAGS, LDFLAGS, and FEATURES
	    process cflags
	    process ldflags
	    ;;
	*) 
	    ;;
    esac
fi


