#!/bin/bash # Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License, v2 or later # $Header: /home/cvsroot/gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.4.1,v 1.1 2003/04/06 22:18:42 zwelch Exp $ # Original Author: Martin Schlemmer # Present Maintainter: Zach Welch # Cross-compiling toolchain contributions by: # Zach Welch and James Boddington # Other contributions listed in ChangeLog source /etc/init.d/functions.sh || { echo "$0: Could not source /etc/init.d/functions.sh!" exit 1 } GCCC_VERBOSE=1 GCCC_PRETEND="" gccc_echo() { [ -z "${GCCC_QUIET}" -a -n "${GCCC_VERBOSE}" ] && echo "$*" } die() { eerror "$*" exit 1 } usage() { cat << "USAGE_END" Usage: gcc-config [Option] [CC Profile] gcc-config version @VERSION@ Change the current cc/gcc profile, or give info about profiles. Options: -O, --use-old Use the old profile if one was selected. -P, --use-portage-chost Only set to given profile if its CHOST is the same as that set for portage in /etc/make.conf (or one of other portage config files...). -c, --get-current-profile Print current used gcc profile for (optional) CHOST. -l, --list-profiles Print a list of available profiles. -E, --print-environ Print environment that can be used to setup things for current gcc profile, or specified one ... -B, --get-bin-path Print path where binaries of given/current profile are located. -L, --get-lib-path Print path where libraries of given/current profile are located. -X, --get-stdcxx-incdir Print path to g++ include files of given/current profile. --install-toolchain Install a new cross-compiling toolchain (that does not appear in the list of available profiles) and create the specified profile. --remove-toolchain Remove a cross-compiling toolchain. The profile name is in the form of: - For example: i686-pc-linux-gnu-3.2.2 USAGE_END exit 1 } if [ "$#" -lt 1 ] then usage fi HAVE_WHICH="no" if [ -n "$(which which 2> /dev/null)" ] then HAVE_WHICH="yes" fi CC_COMP="" CC_HOST="" CC_VERS="" find_path() { [ -z "$1" ] && return 0 if [ "${HAVE_WHICH}" = "yes" ] then local fullpath="$(which $1 2> /dev/null)" if [ -x "${fullpath}" ] then echo "${fullpath}" return 0 fi fi for x in /bin /sbin /usr/bin /usr/sbin \ /usr/local/bin /usr/local/sbin do if [ -x "${x}/$1" -a -r "${x}/$1" ] then echo "${x}/$1" return 0 fi done return 0 } EMERGE="$(find_path emerge)" cmd_setup() { # Sourcing /etc/env.d/gcc/${CC_COMP} is going to mess up # PATH among things... CP="$(find_path cp)" RM="$(find_path rm)" MV="$(find_path mv)" LN="$(find_path ln)" CAT="$(find_path cat)" AWK="$(find_path gawk)" GREP="$(find_path grep)" FIND="$(find_path find)" CHMOD="$(find_path chmod)" TOUCH="$(find_path touch)" ENV_UPDATE="$(find_path env-update)" } get_portage_dirs() { PORTDIR="$(portageq portdir 2>/dev/null)" PORTDIR_OVERLAY="$(portageq portdir_overlay 2>/dev/null)" } # =============================================================== CC_ARCH="" get_arch() { [ -n "${CC_ARCH}" ] && return 0 CC_ARCH="$(echo ${CC_HOST} | awk -F '-' '{print $1}' | \ sed -e 's/arm.*/arm/;s/powerpc/ppc/')" [ -n "${CC_ARCH}" ] || die "unable to determine CC_ARCH" } REAL_CHOST="" get_real_chost() { [ -n "${REAL_CHOST}" ] && return 0 # CBUILD is our real 'native' CHOST REAL_CHOST="$(portageq envvar CBUILD 2>/dev/null)" [ -n "${REAL_CHOST}" ] && return 0 # but portage has CHOST confused with CBUILD REAL_CHOST="$(portageq envvar CHOST 2>/dev/null)" [ -n "${REAL_CHOST}" ] && return 0 die "$0: Could not get portage CBUILD or CHOST!" } is_native_config() { [ -z "${REAL_CHOST}" ] && get_real_chost [ -z "${CC_HOST}" -o "${CC_HOST}" = "${REAL_CHOST}" ] } get_config_filename() { is_native_config && \ echo "config" || \ echo "config-${CC_HOST}" } # =============================================================== USER_ID="" is_super_user() { if [ -z "${USER_ID}" ]; then USER_ID="$(id -u)" [ -z "${USER_ID}" ] && die "Unable to get user id" fi [ "${USER_ID}" -eq 0 ] } USER_NAME="" get_user_name() { if [ -z "${USER_NAME}" ]; then USER_NAME="$(id -un)" [ -z "${USER_NAME}" ] && die "Unable to get user name" fi echo "${USER_NAME}" } USER_HOME="" get_user_home_dir() { [ -z "${USER_HOME}" ] && \ USER_HOME="${HOME}" [ -z "${USER_HOME}" ] && die "\${HOME} is not set" echo "${USER_HOME}" } USER_CONF_DIR="" get_user_config_dir() { [ -z "${USER_CONF_DIR}" ] && \ USER_CONF_DIR="$(get_user_home_dir)/.gcc-config" echo "${USER_CONF_DIR}" } USER_CONFIG="" get_user_config_file() { [ -z "${USER_CONFIG}" ] && \ USER_CONFIG="$(get_user_config_dir)/$(get_config_filename)" echo "${USER_CONFIG}" } USER_ENV_FILE="" get_user_env_file() { [ -z "${USER_ENV_FILE}" ] && \ USER_ENV_FILE="$(get_user_home_dir)/.gcc-current" echo "${USER_ENV_FILE}" } # =============================================================== GCCC_ENVD="/etc/env.d" GCCC_CONFD="/etc/env.d/gcc" get_sys_config_dir() { echo "${GCCC_CONFD}" } SYS_CONFIG="" get_sys_config_file() { [ -z "${SYS_CONFIG}" ] && \ SYS_CONFIG="$(get_sys_config_dir)/$(get_config_filename)" echo "${SYS_CONFIG}" } get_sys_env_file() { # root affects the whole system echo "${GCCC_ENVD}/05gcc" } # =============================================================== # config file hackery - we might do better with sub-shell sourcing get_var_from_config() { awk -F'=' '/^'"${1}"'=['\''"]?([^"'\'']*)['\''"]?$/ { print $2 }' ${2} | sed 's,^["'\'']\([^"'\'']*\)["'\'']$,\1,' } get_current_from_config() { get_var_from_config 'CURRENT' "${1}" } # =============================================================== # the following functions manage the distcc symlinks # they allow the user or other scripts (namely gcc-config) to # automatically update distcc's links when upgrading toolchains # gccc_remove_link() { local t="/usr/bin/${1}" if [ -f ${t} ]; then gccc_echo "Removing ${t}..." rm -f "${t}" fi } gccc_install_link() { # first be sure any old link is removed GCCC_VERBOSE="" gccc_remove_link "${1}" # then create the new link local t="/usr/bin/${1}" gccc_echo "Installing wrapper: ${t}..." cp -f /usr/lib/gcc-config/wrapper "${t}" } # gccc_update_links {install,remove} [CHOST] gccc_links() { local a for a in gcc cc c++ g++ ; do [ -n "${2}" ] && a="${2}-${a}" eval "gccc_${1}_link" "${a}" done # now update distcc and ccache's wrappers using their scripts [ -x /usr/bin/distcc-config ] && \ DCCC_QUIET=1 /usr/bin/distcc-config "--${1}-links" ${2} [ -x /usr/bin/ccache-config ] && \ CC_QUIET=1 /usr/bin/ccache-config "--${1}-links" ${2} } install_wrappers() { rm -f /lib/cpp && cp -f /usr/lib/gcc-config/wrapper /lib/cpp is_native_config && gccc_links 'install' gccc_links 'install' "${CC_HOST}" } remove_wrappers() { rm -f /lib/cpp is_native_config && gccc_links 'remove' gccc_links 'remove' "${CC_HOST}" } # =============================================================== check_config_file() { local CONFIG="" if ! is_super_user; then CONFIG="$(get_user_config_dir)/${1}" [ -r "${CONFIG}" ] || CONFIG="" fi [ -z "${CONFIG}" ] && CONFIG="${GCCC_CONFD}/${1}" [ -r "${CONFIG}" ] || CONFIG="" echo "${CONFIG}" } # get_all_chosts searches the system config directory for supported CHOSTs get_all_chosts() { find ${GCCC_CONFD}/* | grep -v config | sed 's,\(.*\)-.*$,\1,;s,^.*/\(.*\),\1,g' | sort -u } get_all_configs() { local ALL_CONFIGS="" local ALL_CHOSTS="$(get_all_chosts)" local x # add main config file ALL_CONFIGS="$(check_config_file 'config')" get_real_chost eval "ALL_CHOSTS=\${ALL_CHOSTS/${REAL_CHOST}}" # add remaining config files local CONFIG CONFIGNAME for x in ${ALL_CHOSTS}; do CONFIGNAME="config-${x}" CONFIG="$(check_config_file ${CONFIGNAME})" [ -z "${CONFIG}" ] && continue ALL_CONFIGS="${ALL_CONFIGS} ${CONFIG}" done echo "${ALL_CONFIGS}" } get_gccc_profiles() { local GCCC_PROFILES="" local ALL_CURRENT="" local CURRENT local x ALL_CURRENT="$(awk -F'=' '{ print $2 }' $(get_all_configs))" for CURRENT in ${ALL_CURRENT}; do # CURRENT="$(get_current_from_config ${x})" [ -z "${GCCC_PROFILES}" ] && \ GCCC_PROFILES="${CURRENT}" || \ GCCC_PROFILES="${GCCC_PROFILES}:${CURRENT}" done [ -n "${GCCC_PROFILES}" ] || die "$0: no active profiles available!" echo "${GCCC_PROFILES}" } # =============================================================== switch_profile() { # print nice messege to the user local CC_WHO="" is_super_user && \ CC_WHO="settings for $(get_user_name)" || \ CC_WHO="system default settings" local CC_TYPE="" is_native_config && \ CC_TYPE="native compilers to ${CC_COMP}" || \ CC_TYPE="${CC_HOST} cross-compilers to ${CC_VERS}" ebegin "Switching ${CC_WHO} for ${CC_TYPE}" # locate system (and user) gcc-config settings directories local SYS_CONFIG_DIR="$(get_sys_config_dir)" local CONFIG_DIR="" is_super_user && \ CONFIG_DIR="${SYS_CONFIG_DIR}" || \ CONFIG_DIR="$(get_user_config_dir)" mkdir -p "${CONFIG_DIR}" || die "$0: can't create ${CONFIG_DIR}" # locate sytem (and user) environment file(s) local SYS_ENV_FILE="$(get_sys_env_file)" local ENV_FILE="" is_super_user && \ ENV_FILE="${SYS_ENV_FILE}" || \ ENV_FILE="$(get_user_env_file)" # locate system (and user) configuration file(s) local OLD_CC_COMP="" local SYS_CONFIG="$(get_sys_config_file)" local CONFIG="" is_super_user && \ CONFIG="${SYS_CONFIG}" || \ CONFIG="$(get_user_config_file)" # locate old config for this CC_HOST [ -r ${CONFIG} ] && OLD_CC_COMP="$(get_current_from_config ${CONFIG})" if [ -z "${OLD_CC_COMP}" -a "${CONFIG}" != "${SYS_CONFIG}" ]; then [ -r ${SYS_CONFIG} ] && OLD_CC_COMP="$(get_current_from_config ${SYS_CONFIG})" fi # Order our profiles to have the active profile first... # We do this so that we can have them ordered with default # first in /etc/ld.so.conf, as the logical is that all # compilers for default CHOST will be used to compile stuff, # and thus we want all their lib paths in /etc/ld.so.conf ... local GCC_PROFILES="" GCC_PROFILES="$(find ${GCCC_CONFD}/ -name "${CC_HOST}-*")" GCC_PROFILES="${GCC_PROFILES/\/etc\/env.d\/gcc\/${CC_COMP}}" GCC_PROFILES="${GCCC_CONFD}/${CC_COMP} ${GCC_PROFILES}" # Extract all LDPATH's for our CHOST local MY_LDPATH="" local PROFILE_LDPATH="" for x in ${GCC_PROFILES} do if [ -f "${x}" ] then PROFILE_LDPATH="$(get_var_from_config 'LDPATH' ${x})" if [ -z "${PROFILE_LDPATH}" ]; then ewarn "\${LDPATH} not found in ${x}" continue fi if [ ! -d "${PROFILE_LDPATH}" ]; then ewarn "${LDPATH} in ${x} cannot be found" continue fi [ -z "${MY_LDPATH}" ] && \ MY_LDPATH="${PROFILE_LDPATH}" || \ MY_LDPATH="${MY_LDPATH}:${PROFILE_LDPATH}" fi done # Setup our profile config file echo "CURRENT=${CC_COMP}" > ${SYS_CONFIG} || die # Setup environment file rm -f "${ENV_FILE}" { # Copy most of the spec file intact # skip PATH, LDPATH, and STDCXX_INCDIR awk '!/^PATH=|^LDPATH=|^STDCXX_INCDIR=/ {print $0}' \ "${GCCC_CONFD}/${CC_COMP}" && # Add our custom LDPATH -- not anymore - wild any crazy # echo "LDPATH=\"${MY_LDPATH}\"" && # Make sure we do not recreate /lib/cpp and /usr/bin/cc ... # echo "DISABLE_GEN_GCC_WRAPPERS=\"yes\"" >> ${ENV_FILE} # set GCCC_PROFILES for per-session support echo "GCCC_PROFILES=$(get_gccc_profiles)" } > ${ENV_FILE} || die "Unable to create ${ENV_FILE}" if is_super_user; then # These might not be installed, and we want to update the mtime # for ccache and distcc anyhow ... (ztw - ?!?) # update main linkes GCCC_QUIET=1 install_wrappers /usr/sbin/env-update &> /dev/null fi eend 0 if [ "${OLD_CC_COMP}" != "${CC_COMP}" ] then echo ewarn "If you intend to use the gcc from the new profile in an already" ewarn "running shell, please remember to do the following:" echo ewarn " # source /etc/profile" echo fi return 0 } get_current_profile() { local SYS_CONFIG="$(get_sys_config_file)" local CURRENT="" local CONFIG="" is_super_user && \ CONFIG="${SYS_CONFIG}" || \ CONFIG="$(get_user_config_file)" # locate config for this CC_HOST [ -r ${CONFIG} ] && \ CURRENT="$(get_current_from_config ${CONFIG})" if [ -z "${CURRENT}" -a "${CONFIG}" != "${SYS_CONFIG}" ]; then [ -r ${SYS_CONFIG} ] && CURRENT="$(get_current_from_config ${SYS_CONFIG})" fi [ -z "${CURRENT}" ] && die "$0: No gcc profile is active!" echo "${CURRENT}" return 0 } list_profiles() { local i=1 if [ ! -f /etc/env.d/gcc/config ] then eerror "$0: No gcc profile is active!" return 1 fi for x in /etc/env.d/gcc/* do if [ -f "${x}" -a "${x}" = "${x/config}" ] then echo "[${i}] ${x##*/}" i=$((i + 1)) fi done } print_environ() { local NEWPATH local NEWCC local NEWCXX NEWPATH="$(get_var_from_config 'PATH' ${GCCC_CONFD}/${CC_COMP})" NEWCC="$(get_var_from_config 'CC' ${GCCC_CONFD}/${CC_COMP})" NEWCXX="$(get_var_from_config 'CXX' ${GCCC_CONFD}/${CC_COMP})" echo "export PATH=\"${NEWPATH}:${PATH}\"" # if [ -z "${LD_LIBRARY_PATH}" ] # then # echo "export LD_LIBRARY_PATH=\"${LDPATH}\"" # else # echo "export LD_LIBRARY_PATH=\"${LDPATH}:${LD_LIBRARY_PATH}\"" # fi echo "export CC=\"${NEWCC}\"" echo "export CXX=\"${NEWCXX}\"" } get_bin_path() { echo "$(get_var_from_config 'PATH' ${GCCC_CONFD}/${CC_COMP})" return 0 } get_lib_path() { echo "$(get_var_from_config 'LDPATH' ${GCCC_CONFD}/${CC_COMP})" return 0 } get_stdcxx_incdir() { local PTH DIR PTH="$(get_lib_path)" [ -z "${PTH}" ] && die "$0: unable to get LDPATH for ${CC_COMP}" DIR="$(get_var_from_config 'STDCXX_INCDIR' ${GCCC_CONFD}/${CC_COMP})" echo "${PTH}/include/${DIR}" return 0 } # =============================================================== # cross-compiler install portions install_toolchain() { local CC_DIR PCC_DIR is_super_user || \ die "You must be root to install a new toolchain." is_native_config && \ die "gcc-config should not be used to build a native toolchain" get_portage_dirs [ -z "${PORTDIR_OVERLAY}" ] && die "PORTDIR_OVERLAY must be defnied" [ -f "/etc/env.d/gcc/${CC_COMP}" -a -z "${FORCE_INSTALL}" ] && \ die "Toolchain is already installed, use --force" ebegin "Installing cross-compiling toolchain for ${CC_HOST}-${CC_VERS}" get_arch CC_DIR="arch-${CC_HOST}" CC_HDRS="${CC_ARCH}" einfo "Looking for ${CC_ARCH}-headers..." [ ! -d "${PORTDIR}/sys-kernel/${CC_ARCH}-headers" -a \ ! -d "${PORTDIR_OVERLAY}/sys-kernel/${CC_ARCH}-headers" ] && \ CC_HDRS="linux" einfo "Using ${CC_HDRS}-headers..." # create the portage arch directory, if it doesn't exist # YES!! - WE KNOW THIS IS A TERRIBLE HACK -- IT'S UNFORTUNATE!!! PCC_DIR="${PORTDIR_OVERLAY}/${CC_DIR}" if [ ! -d "${PCC_DIR}" ]; then einfo "Creating ${PCC_DIR} symlinks..." mkdir "${PCC_DIR}" || die "Can't create ${PCC_DIR}" ( cd "${PCC_DIR}" && local x for x in 'sys-devel/binutils' 'sys-devel/gcc' \ 'sys-libs/glibc' "sys-kernel/${CC_HDRS}-headers" do [ -d "${PORTDIR_OVERLAY}/${x}" ] && \ ln -s "${PORTDIR_OVERLAY}/${x}" || \ ln -s "${PORTDIR}/${x}" done ) || die "$0: Unable to create symlinks in ${PCC_DIR}" fi ACCEPT_KEYWORDS="${CC_ARCH}" ARCH="${CC_ARCH}" CCHOST="${CC_HOST}" \ USE="build ${CC_ARCH}" ${EMERGE} \ "${CC_DIR}/binutils" "${CC_DIR}/${CC_HDRS}-headers" \ ">=${CC_DIR}/gcc-${CC_VERS}*" || \ die "$0: Unable to merge cross toolchain for ${CC_HOST}" if [ -z "${GCCC_PRETEND}" ]; then # install wrappers to get /usr/bin/${CC_HOST}-gcc gccc_links 'install' "${CC_HOST}" # set the default version of the system echo "CURRENT=${CC_COMP}" > "$(get_sys_config_file)" fi ACCEPT_KEYWORDS="${CC_ARCH}" ARCH="${CC_ARCH}" CCHOST="${CC_HOST}" \ USE="-nls build ${CC_ARCH}" ${EMERGE} "${CC_DIR}/glibc" || \ die "$0: Unable to merge cross toolchain for ${CC_HOST}" ACCEPT_KEYWORDS="${CC_ARCH}" CCHOST="${CC_HOST}" ARCH="${CC_ARCH}" \ USE="${CC_ARCH}" ${EMERGE} \ ">=${CC_DIR}/gcc-${CC_VERS}*" || \ die "$0: Unable to merge cross toolchain for ${CC_HOST}" if [ -z "${GCCC_PRETEND}" ]; then # reinstall wrappers to get new languages gccc_links 'install' "${CC_HOST}" fi eend 0 } remove_toolchain() { get_arch local CC_DIR="arch-${CC_HOST}" local CC_HDRS local CC_PKGS is_super_user || \ die "You must be root to remove a toolchain." is_native_config && \ die "gcc-config should not be used to remove a native toolchain!! ARE YOU INSANE?!?!" get_portage_dirs [ -z "${PORTDIR_OVERLAY}" ] && die "PORTDIR_OVERLAY must be defnied" # the presense of the arch-ARCH dir in the overlay is used # to tell if the if [ ! -d ${PORTDIR_OVERLAY}/${CC_DIR} ]; then echo A compiler for $1 is not installed return fi # set CC_HDRS for the appropriate arch headers (or not) # then build the list of packages to unmerge [ -d "${PORTDIR_OVERLAY}/${CC_DIR}/${CC_ARCH}-headers" ] && \ CC_HDRS="${CC_ARCH}" || \ CC_HDRS="linux" CC_PKGS="${CC_DIR}/binutils ${CC_DIR}/${CC_HDRS}-headers \ ${CC_DIR}/glibc ${CC_DIR}/gcc" # unmerge the specified packages ACCEPT_KEYWORDS="${CC_ARCH}" ARCH="${CC_ARCH}" CCHOST=${1} \ ${EMERGE} unmerge ${CC_PKGS} || \ ewarn "$0: Errors unmerging parts of the toolchain..." # and remove the arch directory # BUG BUG -- should only be removed if *last* version is unmerged if [ -z "${GCCC_PRETEND}" ]; then gccc_links 'remove' "${CC_HOST}" local x i for i in ${CC_PKGS}; do x="${PORTDIR_OVERLAY}/${i}" [ -L "${x}" ] && rm -f "${x}" done rmdir "${PORTDIR_OVERLAY}/${CC_DIR}" fi } # =============================================================== # Main program begins here NEED_ACTION="yes" DOIT="switch_profile" CHECK_CHOST="no" check_cc_comp() { if [ -n "`echo ${x} | gawk '/^[[:digit:]]*$/ { print }'`" ] then local i=1 for y in /etc/env.d/gcc/* do # skip configuration files [ "${y/config}" != "${y}" ] && continue if [ -f "${y}" -a "${x}" -eq "${i}" ] then CC_COMP="${y##*/}" break else i=$((i + 1)) fi done else CC_COMP="${x}" fi } check_action() { if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="${1}" else echo "${1} ignored due to previous ${DOIT}" fi } for x in $* do case "${x}" in # Only use specified compiler if one is not already selected. -O|--use-old) if get_current_profile &> /dev/null then CC_COMP="$(get_current_profile)" fi ;; -P|--use-portage-chost) CHECK_CHOST="yes" ;; -c|--get-current-profile) check_action get_current_profile ;; -A|--get-all-profiles) check_action get_all_profiles ;; -l|--list-profiles) check_action list_profiles ;; -E|--print-environ) check_action print_environ ;; -B|--get-bin-path) check_action get_bin_path ;; -L|--get-lib-path) check_action get_lib_path ;; -X|--get-stdcxx-incdir) check_action get_stdcxx_incdir ;; -G|--get-gccc-profiles) check_action get_gccc_profiles ;; --install-wrappers) check_action install_wrappers ;; --remove-wrappers) check_action remove_wrappers ;; --install-toolchain) check_action install_toolchain ;; --remove-toolchain) check_action remove_toolchain ;; -p|--pretend) GCCC_PRETEND=1 EMERGE="${EMERGE} -vp" ;; --force) FORCE_INSTALL=1 ;; -*) eerror "$0: Unknown switch: ${x}\n Run $0 without parameters for help." exit 1 ;; *) if [ -z "${CC_COMP}" ] then check_cc_comp "${x}" fi esac done if [ \( "${DOIT}" = "install_toolchain" -o \ "${DOIT}" = "switch_profile" \) -a \ -z "${CC_COMP}" ] then usage fi # if no CC_COMP was specified, default to the current native profile if [ -z "${CC_COMP}" ] then if ! get_current_profile &> /dev/null then die "$0: No default profile setup!" fi CC_COMP="$(get_current_profile)" fi split_cc_comp() { # split CC_COMP into its component parts CC_HOST="${CC_COMP%-*}" CC_VERS="${CC_COMP##*-}" if [ -z "${CC_HOST}" -o -z "${CC_VERS}" -o \ -z "$(echo ${CC_HOST} | awk -F'-' '{ print $4 }')" ]; then die "${CC_COMP} does not appear to be a valid specification" fi return 0 } check_cc_comp_exists() { split_cc_comp if [ ! -d "/usr/lib/gcc-lib/${CC_HOST}/${CC_VERS}" -o \ ! -f "/etc/env.d/gcc/${CC_COMP}" ] then die "$0: Profile does not exist!" fi return 0 } get_cc_comp_from_config() { CC_COMP="$(get_var_from_config 'CURRENT' ${1})" [ -z "${CC_COMP}" ] && die "$0: unable to find CURRENT in ${1}" split_cc_comp } check_chost_exists() { [ ! -d "/usr/lib/gcc-lib/${CC_COMP}" ] && return 1 CC_HOST="${CC_COMP}" is_super_user || CC_CONFIG="$(get_user_config_file)" [ -r "${CC_CONFIG}" ] || CC_CONFIG="$(get_sys_config_file)" [ -r "${CC_CONFIG}" ] || unset CC_HOST # if we found a config file [ -n "${CC_HOST}" ] && get_cc_comp_from_config "${CC_CONFIG}" # return success if still CC_HOST still set [ -n "${CC_HOST}" ] } case "${DOIT}" in install_toolchain|remove_toolchain) split_cc_comp ;; install_wrappers|remove_wrappers|get_current_profile|get_bin_path|get_lib_path|get_stdcxx_incdir) # user can pass chost or cc_comp check_chost_exists || check_cc_comp_exists ;; *) check_cc_comp_exists ;; esac if [ "${CHECK_CHOST}" = "yes" ] then # Chosen CHOST are not the same as the real CHOST according to # make.conf, and --use-portage-chost option was given, so do nothing get_real_chost is_native_config || exit 0 fi eval ${DOIT} # vim:ts=4