#!/bin/bash # we need support for both pretend and setup phases [[ "${EBUILD_PHASE}" != "pretend" && \ "${EBUILD_PHASE}" != "setup" ]] && return 0 PORT_ETC="/etc/portage" my_gcc(){ [[ -n "$(awk -F "." 'NF == 2' <<< "${2}")" ]] && dep=":${2}" [[ -n "$(awk -F "." 'NF >= 3' <<< "${2}")" ]] && dep="-${2}" MY_GCC="$(find "/usr/${MACHTYPE}/gcc-bin/" -name "${2}*")" if [[ -n "${MY_GCC}" ]];then export ROOTPATH="${MY_GCC}:${ROOTPATH}" export PATH="${MY_GCC}:${PATH}" else eerror "" eerror "sys-devel/gcc${dep} not found" eerror "${3}: '${1} ${2}'" eerror "" die "sys-devel/gcc${dep} not found" fi } ########## COMPILERS ########## switch(){ while read target ver; do if [[ "${CATEGORY}/${PN}" == ${target} ]]; then my_gcc "${target}" "${ver}" "${1}" export LIBRARY_PATH="$(gcc-config -L):${LIBRARY_PATH}" fi done < "${1}" } target="`ls -d1 ${PORT_ETC}/package.compilers 2>/dev/null | grep -v "~"`" if [[ -f "${target}" ]];then switch "${target}" elif [[ -d "${target}" ]];then while read subtarget;do switch "${subtarget}" done <<< "`find ${PORT_ETC}/package.compilers/ -type f | grep -v "~"`" fi ########## COMPILERS_FULL ##### switch_full(){ while read target ver; do if [[ "${CATEGORY}/${PN}" == ${target} ]]; then my_gcc "${target}" "${ver}" "${1}" export LIBRARY_PATH="${MY_GCC}:${LIBRARY_PATH}" fi done < "${1}" } target_full="`ls -d1 ${PORT_ETC}/package.compilers-full 2>/dev/null | grep -v "~"`" if [[ -f "${target_full}" ]];then switch_full "${target_full}" elif [[ -d "${target_full}" ]];then while read subtarget_full;do switch_full "${subtarget_full}" done <<< "`find ${PORT_ETC}/package.compilers-full/ -type f | grep -v "~"`" fi