diff options
-rwxr-xr-x | gcc-config | 185 |
1 files changed, 150 insertions, 35 deletions
@@ -2,7 +2,7 @@ # Copyright 1999-2002 Gentoo Foundation # Distributed under the terms of the GNU General Public License # Author: Martin Schlemmer <azarah@gentoo.org> -# $Header: gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.0,v 1.1 2002/10/27 22:38:11 azarah Exp $ +# $Header: gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.1,v 1.1 2002/11/10 11:58:19 azarah Exp $ source /etc/init.d/functions.sh || { @@ -17,59 +17,55 @@ then fi usage() { -cat << "FOO" -usage: gcc-config <CHOST>-<gcc version> +cat << "USAGE_END" +Usage: gcc-config [Option] <CHOST>-<gcc version> +Options: + [--use-old] + [--get-current-profile] + [--get-bin-path] + [--get-lib-path] + [--get-stdcxx-incdir] + +USAGE_END -FOO exit 1 } -if [ "$#" -ne 1 ] && [ "$#" -eq 2 -a "$1" != "--use-old" ] +if [ "$#" -lt 1 ] then usage fi -GCC_COMP="" - -# Only use specified compiler if one is not already selected. -if [ "$1" = "--use-old" ] -then - shift +find_path() { + [ -z "$1" ] && return 0 - if [ -f /etc/env.d/gcc/config ] - then - source /etc/env.d/gcc/config - if [ -n "${CURRENT}" ] + for x in /bin /sbin /usr/bin /usr/sbin + do + if [ -x ${x}/$1 -a -r ${x}/$1 ] then - GCC_COMP="${CURRENT}" + echo "${x}/$1" + break fi - fi + done +} - if [ -z "${GCC_COMP}" ] - then - GCC_COMP="$1" - fi -else - GCC_COMP="$1" -fi -if [ ! -d /usr/lib/gcc-lib/${GCC_COMP%-*}/${GCC_COMP##*-} -o \ - ! -f /etc/env.d/gcc/${GCC_COMP} ] -then - usage -else +GCC_COMP="" + +switch_profile() { ebegin "Switching to ${GCC_COMP} compiler" # Sourcing /etc/env.d/gcc/${GCC_COMP} is going to mess up # PATH among things... - CP="$(which cp)" - RM="$(which rm)" - MV="$(which mv)" - LN="$(which ln)" - ENV_UPDATE="$(which env-update)" + CP="$(find_path cp)" + RM="$(find_path rm)" + MV="$(find_path mv)" + LN="$(find_path ln)" + GREP="$(find_path grep)" + ENV_UPDATE="$(find_path env-update)" source /etc/env.d/gcc/${GCC_COMP} - ${CP} -f /etc/env.d/gcc/${GCC_COMP} /etc/env.d/05gcc + ${GREP} -v 'STDCXX_INCDIR' /etc/env.d/gcc/${GCC_COMP} > /etc/env.d/05gcc if [ -d /usr/include/${STDCXX_INCDIR} -a ! -L /usr/include/${STDCXX_INCDIR} ] then @@ -92,7 +88,126 @@ else ${ENV_UPDATE} &> /dev/null eend 0 + + return 0 +} + +get_current_profile() { + if [ ! -f /etc/env.d/gcc/config ] + then + eerror "$0: No gcc profile is active!" + return 1 + fi + + source /etc/env.d/gcc/config + + if [ -z "${CURRENT}" ] + then + eerror "$0: No gcc profile is active!" + return 1 + fi + + echo "${CURRENT}" + + return 0 +} + +get_bin_path() { + source /etc/env.d/gcc/${GCC_COMP} + + echo "${PATH}" + + return 0 +} + +get_lib_path() { + source /etc/env.d/gcc/${GCC_COMP} + + echo "${LDPATH}" + + return 0 +} + +get_stdcxx_incdir() { + source /etc/env.d/gcc/${GCC_COMP} + + echo "${LDPATH}/include/${STDCXX_INCDIR}" + + return 0 +} + +NEED_ACTION="yes" +DOIT="switch_profile" + +for x in $* +do + case ${x} in + # Only use specified compiler if one is not already selected. + --use-old) + if get_current_profile &> /dev/null + then + GCC_COMP="$(get_current_profile)" + fi + ;; + --get-current-profile) + if [ "${NEED_ACTION}" = "yes" ] + then + NEED_ACTION="no" + DOIT="get_current_profile" + fi + ;; + --get-bin-path) + if [ "${NEED_ACTION}" = "yes" ] + then + NEED_ACTION="no" + DOIT="get_bin_path" + fi + ;; + --get-lib-path) + if [ "${NEED_ACTION}" = "yes" ] + then + NEED_ACTION="no" + DOIT="get_lib_path" + fi + ;; + --get-stdcxx-incdir) + if [ "${NEED_ACTION}" = "yes" ] + then + NEED_ACTION="no" + DOIT="get_stdcxx_incdir" + fi + ;; + *) + if [ -z "${GCC_COMP}" ] + then + GCC_COMP="${x}" + fi + ;; + esac +done + +if [ "${DOIT}" = "switch_profile" -a -z "${GCC_COMP}" ] +then + usage +fi + +if [ -z "${GCC_COMP}" ] +then + if get_current_profile &> /dev/null + then + GCC_COMP="$(get_current_profile)" + else + usage + fi fi +if [ ! -d /usr/lib/gcc-lib/${GCC_COMP%-*}/${GCC_COMP##*-} -o \ + ! -f /etc/env.d/gcc/${GCC_COMP} ] +then + usage +fi + +eval ${DOIT} + # vim:ts=4 |