aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'binutils-config')
-rw-r--r--binutils-config333
1 files changed, 204 insertions, 129 deletions
diff --git a/binutils-config b/binutils-config
index bbb8f8d..5f21878 100644
--- a/binutils-config
+++ b/binutils-config
@@ -1,7 +1,7 @@
#!/bin/bash
-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-2,v 1.3 2011/04/03 21:44:42 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.11 2013/05/05 05:20:42 vapier Exp $
# Format of /etc/env.d/binutils/:
# config-TARGET: CURRENT=version for TARGET
@@ -9,7 +9,7 @@
: ${ROOT:=/}
[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
-[[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
+[[ ${ROOT} != /* ]] && ROOT="${PWD%/}/${ROOT}"
cd /
@@ -21,11 +21,11 @@ source /etc/init.d/functions.sh || {
exit 1
}
esyslog() { :; }
+die() { eerror "${argv0}: $*"; exit 1; }
umask 022
usage() {
cat << USAGE_END
-
Usage: ${HILITE}binutils-config${NORMAL} ${GOOD}[options]${NORMAL} ${BRACKET}[binutils profile]${NORMAL}
${HILITE}General Options:${NORMAL}
@@ -34,6 +34,9 @@ ${HILITE}General Options:${NORMAL}
${GOOD}-u, --uninstall${NORMAL} Remove all signs of specified target
${GOOD}-d, --debug${NORMAL} Execute with debug output
+${HILITE}General Cruft:${NORMAL}
+ ${GOOD}--linker${NORMAL} <linker> Switch to specified linker (if supported)
+
${HILITE}Arch Specific Cruft:${NORMAL}
${GOOD}--amd64${NORMAL} Install extra amd64 links (x86_64)
${GOOD}--arm${NORMAL} Install extra arm links (arm/armeb)
@@ -56,8 +59,28 @@ mv_if_diff() {
mv -f "$1" "$2"
fi
}
+atomic_ln() {
+ local target=$1 linkdir=$2 linkname=$3 linktmp linkfull
+ linktmp="${linkdir}/.binutils-config.tmp.${linkname}"
+ linkfull="${linkdir}/${linkname}"
+ if [[ -d ${linkfull} ]] ; then
+ # if linking to a dir, we need a little magic to
+ # make it atomic since `mv -T` is not portable
+ rm -rf "${linktmp}"
+ mkdir -p "${linktmp}"
+ ln -sf "${target}" "${linktmp}/${linkname}"
+ mv "${linktmp}/${linkname}" "${linktmp}/../"
+ rmdir "${linktmp}"
+ else
+ # `ln` will expand into unlink();symlink(); which
+ # is not atomic for a small amount of time, but
+ # `mv` is a single rename() call
+ ln -sf "${target}" "${linktmp}"
+ mv "${linktmp}" "${linkfull}"
+ fi
+}
-switch_profile() {
+setup_env() {
unset TARGET VER LIBPATH FAKE_TARGETS
source "${ENV_D}/${PROFILE}"
if [[ -z ${TARGET} ]] ; then
@@ -88,8 +111,6 @@ switch_profile() {
local fake_targ_append="${TARGET#*-}"
FAKE_TARGETS="${FAKE_TARGETS} ${FAKE_TARGETS_USER// /-${fake_targ_append} }"
- ebegin "Switching to ${PROFILE}"
-
#
# Generate binary symlinks
# On systems that do 32bit/64bit, we need to fake an
@@ -111,17 +132,24 @@ switch_profile() {
BINPATH=/usr/${TARGET}/binutils-bin/${VER}
BINPATH_LINKS=/usr/${TARGET}/bin
fi
+}
+
+switch_profile() {
+ ebegin "Switching to ${PROFILE}"
+
+ setup_env || return 1
+
cd "${ROOT}/${BINPATH}" || exit 1
mkdir -p "${ROOT}/${BINPATH_LINKS}" "${ROOT}/usr/bin"
for x in * ; do
- ln -sf "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}/${x}"
- ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${TARGET}-${x}
+ atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}"
+ atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin/" "${TARGET}-${x}"
for fake in ${FAKE_TARGETS} ; do
[[ -f ${ENV_D}/config-${fake} ]] && continue
- ln -sf "${BINPATH_LINKS}/${x}" "${ROOT}"/usr/bin/${fake}-${x}
+ atomic_ln "${BINPATH_LINKS}/${x}" "${ROOT}/usr/bin" "${fake}-${x}"
done
if [[ ${TARGET} == ${HOST} ]] ; then
- ln -sf ${TARGET}-${x} "${ROOT}"/usr/bin/${x}
+ atomic_ln "${TARGET}-${x}" "${ROOT}/usr/bin" "${x}"
fi
done
@@ -134,17 +162,14 @@ switch_profile() {
dstlib=${ROOT}/usr/${HOST}/lib
else
dstlib=${ROOT}/usr/${HOST}/${TARGET}/lib
- # Clean out old path
- rm -rf "${ROOT}"/usr/${TARGET}/lib/ldscripts
- rmdir "${ROOT}"/usr/${TARGET}/lib >& /dev/null
fi
# When upgrading, we need to clean up ldscripts and libs
- rm -rf "${dstlib}/ldscripts" "${ROOT}/${BINPATH_LINKS}"/ldscripts
mkdir -p "${dstlib}"
- ln -sf "${LIBPATH}/ldscripts" "${dstlib}"/ldscripts
- find -L "${dstlib}" -type l -exec rm {} +
+ rm -rf "${ROOT}/${BINPATH_LINKS}"/ldscripts
+ atomic_ln "${LIBPATH}/ldscripts" "${dstlib}" "ldscripts"
+ find -L "${dstlib}" -type l -exec rm -v {} +
for x in lib* ; do
- ln -sf "${LIBPATH}/${x}" "${dstlib}/${x}"
+ atomic_ln "${LIBPATH}/${x}" "${dstlib}" "${x}"
done
#
@@ -156,7 +181,7 @@ switch_profile() {
if [[ ${HOST} == ${TARGET} ]] ; then
mkdir -p "${ROOT}/usr/include"
for x in * ; do
- ln -sf "${INCPATH}/${x}" "${ROOT}/usr/include/${x}"
+ atomic_ln "${INCPATH}/${x}" "${ROOT}/usr/include" "${x}"
done
else
# Clean out old path -- cannot use '-exec {} +' syntax here
@@ -212,9 +237,10 @@ switch_profile() {
}
uninstall_target() {
+ : ${TARGET:=${UARG}}
+
if [[ ${TARGET} == ${HOST} ]] ; then
- eerror "${argv0}: Refusing to uninstall native binutils"
- exit 1
+ die "refusing to uninstall native binutils"
fi
shopt -s nullglob
@@ -225,18 +251,24 @@ uninstall_target() {
rm -f "${ENV_D}"/${PROFILE}
done
if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
- eerror "${argv0}: No profiles exist for '${TARGET}'"
- exit 1
+ die "no profiles exist for '${TARGET}'"
fi
rm -f "${ENV_D}"/config-${TARGET} "${ROOT}"/etc/ld.so.conf.d/05binutils.conf
# XXX: we still leave behind FAKE_TARGETS in /usr/bin ...
- for x in addr2line ar as c++filt elf2flt flthdr gprof ld ld.real \
- nm objcopy objdump ranlib readelf size strings strip ; do
- rm -f "${ROOT}"/usr/bin/${TARGET}-${x}
- rm -f "${ROOT}"/usr/{${HOST}/,}${TARGET}/bin/${x}
- rm -f "${ROOT}"/usr/libexec/gcc/${TARGET}/${x}
+ local x
+ for x in \
+ addr2line ar as c++filt elf2flt elfedit flthdr gprof \
+ ld ld.{bfd,gold,real} \
+ nm objcopy objdump ranlib readelf size strings strip
+ do
+ x=(
+ "${ROOT}"/usr/bin/${TARGET}-${x}
+ "${ROOT}"/usr/{${HOST}/,}${TARGET}/bin/${x}
+ "${ROOT}"/usr/libexec/gcc/${TARGET}/${x}
+ )
+ rm -f "${x[@]}"
done
for x in ansidecl.h bfd.h bfdlink.h dis-asm.h symcat.h ; do
rm -f "${ROOT}"/usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
@@ -252,69 +284,104 @@ uninstall_target() {
"${destdir}"/{bin,include,lib,usr} \
"${destdir}" \
"${ROOT}"/var/db/pkg/cross-${TARGET} \
+ "${ROOT}"/usr/{${HOST}/,}${TARGET}/bin \
+ "${ROOT}"/usr/libexec/gcc/${TARGET} \
2>/dev/null
rm -f "${ENV_D}"/${TARGET}-*
}
-get_current_profile() {
- if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
- eerror "${argv0}: No binutils profile is active!"
+set_current_profile() {
+ if [[ ! -f ${ENV_D}/config-${TARGET} ]] ; then
+ eerror "${argv0}: unable to locate a profile for target: ${TARGET}"
return 1
fi
- source "${ENV_D}/config-${PROFILE}"
+ source "${ENV_D}/config-${TARGET}"
if [[ -z ${CURRENT} ]] ; then
- eerror "${argv0}: No binutils profile is active!"
+ eerror "${argv0}: no binutils profile is active!"
return 1
fi
- echo "${PROFILE}-${CURRENT}"
+ echo "${TARGET}-${CURRENT}"
return 0
}
+get_current_profile() { echo "${PROFILE}" ; }
list_profiles() {
- local i=1
-
- set_HOST
+ local x i target
if [[ ${ROOT} != / ]] ; then
echo "Using binutils-config info in ${ROOT}"
fi
+
+ set -- "${ENV_D}"/*
target=
- for x in "${ENV_D}"/* ; do
- if [[ -f ${x} ]] && [[ ${x/\/config-} == ${x} ]] ; then
- source "${x}"
- if [[ ${target} != ${TARGET} ]] ; then
- [[ -n ${target} ]] && echo
- target=${TARGET}
- fi
+ i=1
- x=${x##*/}
- if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
- source "${ENV_D}/config-${TARGET}"
- if [[ ${VER} == ${CURRENT} ]] ; then
- [[ ${TARGET} == ${HOST} ]] \
- && x="${x} ${GOOD}*${NORMAL}" \
- || x="${x} ${HILITE}*${NORMAL}"
- fi
+ for x ; do
+ # skip broken links and config files
+ [[ -f ${x} ]] || continue
+ [[ ${x} == */config-* ]] && continue
+
+ source "${x}"
+ if [[ ${target} != ${TARGET} ]] ; then
+ [[ -n ${target} ]] && echo
+ target=${TARGET}
+ fi
+
+ x=${x##*/}
+ if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
+ source "${ENV_D}/config-${TARGET}"
+ if [[ ${VER} == ${CURRENT} ]] ; then
+ [[ ${TARGET} == ${HOST} ]] \
+ && x="${x} ${GOOD}*${NORMAL}" \
+ || x="${x} ${HILITE}*${NORMAL}"
fi
- echo " [${i}] ${x}"
- ((++i))
fi
+
+ # We would align the [...] field like so:
+ #printf ' [%*ss] %s\n' ${##} "${i}" "${x}"
+ # but this breaks simple scripting: `binutils -l | awk '{print $2}'`
+
+ # Or we could align the target col like so:
+ #printf ' [%s]%*s %s\n' "${i}" $(( ${##} - ${#i} )) "" "${x}"
+ # but i'm not sold that it looks better
+
+ # So keep it simple ... only makes a diff anyways for crazy people
+ # like me which have 100+ binutils packages installed ...
+ echo " [$i] ${x}"
+ ((++i))
done
}
-set_HOST() {
- [[ -n ${HOST} ]] && return 0
+switch_linker() {
+ local bpath ld=$1
- if [[ -z ${CHOST} ]] ; then
- HOST=$(portageq envvar CHOST)
- else
- HOST=${CHOST}
+ case ${ld} in
+ ld.*) ;;
+ *) die "not supported: linker must start with 'ld.'" ;;
+ esac
+
+ setup_env || return 1
+ bpath="${ROOT}/${BINPATH}"
+
+ # does this binutils even support the requested linker ?
+ if [[ ! -e ${bpath}/${ld} ]] ; then
+ die "sorry, but ${PROFILE} doesn't support the ${ld} linker"
fi
+
+ # switch it up
+ ebegin "Setting default linker to ${ld} for ${PROFILE}"
+ atomic_ln ${ld} "${bpath}" ld
+ eend $?
+}
+
+set_HOST() {
+ # Set HOST to CHOST if it isn't already set
+ : ${HOST:=${CHOST:-$(portageq envvar CHOST)}}
}
ENV_D="${ROOT}etc/env.d/binutils"
@@ -322,43 +389,34 @@ ENV_D="${ROOT}etc/env.d/binutils"
DEBUG="no"
NEED_ACTION="yes"
DOIT="switch_profile"
-PROFILE=""
+PROFILE="current"
FAKE_TARGETS_USER=""
HOST=""
+TARGET=""
+unset UARG
+
+select_action() {
+ if [[ ${NEED_ACTION} != "no" ]] ; then
+ NEED_ACTION="no"
+ DOIT=$1
+ else
+ die "one action at a time!"
+ fi
+}
while [[ $# -gt 0 ]] ; do
x=$1
shift
case ${x} in
- -c|--get-current-profile)
- if [[ ${NEED_ACTION} == "yes" ]] ; then
- NEED_ACTION="no"
- DOIT="get_current_profile"
- fi
- ;;
- -d|--debug)
- DEBUG="yes"
- ;;
- -l|--list-profiles)
- if [[ ${NEED_ACTION} == "yes" ]] ; then
- NEED_ACTION="no"
- DOIT="list_profiles"
- fi
- ;;
- -u|--uninstall)
- if [[ ${NEED_ACTION} == "yes" ]] ; then
- NEED_ACTION="no"
- DOIT="uninstall_target"
- TARGET=$1
- shift
- fi
- ;;
- -h|--help)
- usage 0
- ;;
+ -c|--get-current-profile) select_action get_current_profile ;;
+ -l|--list|--list-profiles) select_action list_profiles ;;
+ -u|--uninstall) select_action uninstall_target ;;
+ --linker) select_action "switch_linker $1"; shift ;;
+ -d|--debug) DEBUG="yes" ;;
+ -h|--help) usage 0 ;;
-V|--version)
unset Header
- cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-2,v 1.3 2011/04/03 21:44:42 vapier Exp $"
+ cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-3,v 1.11 2013/05/05 05:20:42 vapier Exp $"
cvsver=${cvsver##*binutils-config-}
bver=${cvsver%%,v *}
cvsver=${cvsver#* }
@@ -369,7 +427,6 @@ while [[ $# -gt 0 ]] ; do
if [[ ${NEED_ACTION} == "yes" ]] ; then
# Make sure we have a space after each target
NEED_ACTION="no"
- [[ -z ${PROFILE} ]] && PROFILE="current"
case ${x} in
--amd64) FAKE_TARGETS_USER="x86_64 ";;
--arm) FAKE_TARGETS_USER="arm armeb ";;
@@ -379,46 +436,14 @@ while [[ $# -gt 0 ]] ; do
fi
;;
-*)
- eerror "${0##*/}: Invalid switch! Try '--help'."
- exit 1
+ die "invalid switch! Try '--help'."
;;
*)
- if [[ -n ${PROFILE} ]] && [[ ${PROFILE} != "current" ]] ; then
- eerror "${argv0}: Too many arguments! Run ${argv0} without parameters for help."
- exit 1
- fi
-
- if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
- # User gave us a # representing the profile
- i=1
- for y in "${ENV_D}"/* ; do
- [[ ${y/config-} != ${y} ]] && continue
-
- if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
- PROFILE=${y##*/}
- NEED_ACTION="no"
- break
- fi
- ((++i))
- done
- fi
-
- if [[ -z ${PROFILE} ]] ; then
- # User gave us a full HOST-ver
- x=${x##*/}
- if [[ ! -f ${ENV_D}/${x} ]] && [[ ! -f ${ENV_D}/config-${x} ]] ; then
- # Maybe they just gave us a ver ...
- set_HOST
- if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
- x=${HOST}-${x}
- else
- eerror "${argv0}: Could not locate '$x' in '${ENV_D}/'!"
- exit 1
- fi
- fi
- PROFILE=${x}
- NEED_ACTION="no"
+ if [[ ${UARG+set} == "set" ]] ; then
+ die "only one profile/target at a time please"
fi
+ NEED_ACTION="maybe"
+ UARG=${x}
;;
esac
done
@@ -426,9 +451,59 @@ done
[[ ${NEED_ACTION} == "yes" ]] && usage 1
[[ ${DEBUG} == "yes" ]] && set -x
-[[ ${DOIT} != "list_profiles" ]] && set_HOST
-[[ -z ${PROFILE} ]] && PROFILE=${HOST}
-[[ ${PROFILE} == "current" ]] && PROFILE=$(PROFILE=${HOST} get_current_profile)
+# All operations need to know the current HOST to figure out
+# what is a native target and what is a cross target
+set_HOST
+
+# All operations need to know the profile the user wants
+case ${DOIT} in
+switch_profile|switch_linker_*)
+ # decode user's profile choice
+ x=${UARG:-$(TARGET=${HOST} set_current_profile)}
+ PROFILE=""
+ if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
+ # User gave us a # representing the profile
+ i=1
+ for y in "${ENV_D}"/* ; do
+ [[ ${y/config-} != ${y} ]] && continue
+
+ if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
+ PROFILE=${y##*/}
+ break
+ fi
+ ((++i))
+ done
+ fi
+
+ if [[ -z ${PROFILE} ]] ; then
+ # User gave us a full HOST-ver
+ x=${x##*/}
+ if [[ -f ${ENV_D}/${x} ]] ; then
+ # Valid HOST-ver yeah!
+ PROFILE=${x}
+ else
+ # Not a valid HOST-ver ...
+ if [[ ! -f ${ENV_D}/config-${x} ]] ; then
+ # Maybe they just gave us a ver ...
+ if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
+ x=${HOST}-${x}
+ else
+ die "could not locate '$x' in '${ENV_D}/'!"
+ fi
+ PROFILE=${x}
+ else
+ # Maybe they just gave us a target ... pick active profile
+ PROFILE=$(TARGET=${x} set_current_profile)
+ fi
+ fi
+ fi
+ ;;
+*)
+ # lookup current profile as the user gave us a target
+ PROFILE=$(TARGET=${UARG:-${HOST}} set_current_profile) || exit 1
+ ;;
+esac
+
eval ${DOIT}
# vim:ts=4