| 1 |
#! @GENTOO_PORTAGE_EPREFIX@/bin/bash
|
| 2 |
# Copyright 1999-2007 Gentoo Foundation
|
| 3 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
# $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-1.9,v 1.10 2007/05/06 09:04:01 vapier Exp $
|
| 5 |
|
| 6 |
# Format of /etc/env.d/binutils/:
|
| 7 |
# config-TARGET: CURRENT=version for TARGET
|
| 8 |
# TARGET-VER: has a TARGET and VER variable
|
| 9 |
|
| 10 |
VERSION="@VERSION@"
|
| 11 |
BPREFIX="@GENTOO_PORTAGE_EPREFIX@"
|
| 12 |
CFLAGS="@CFLAGS@"
|
| 13 |
BUILD_CC="@CC@"
|
| 14 |
[[ -z ${EPREFIX} ]] && EPREFIX=${BPREFIX}
|
| 15 |
|
| 16 |
[[ -z ${ROOT} ]] && ROOT="/"
|
| 17 |
[[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
|
| 18 |
EROOT="${ROOT%/}${EPREFIX}/"
|
| 19 |
export ROOT EPREFIX
|
| 20 |
|
| 21 |
cd "${EROOT}"
|
| 22 |
|
| 23 |
trap ":" INT QUIT TSTP
|
| 24 |
|
| 25 |
argv0=${0##*/}
|
| 26 |
source "${BPREFIX}"/etc/init.d/functions.sh || {
|
| 27 |
echo "${argv0}: Could not source ${BPREFIX}/etc/init.d/functions.sh!" 1>&2
|
| 28 |
exit 1
|
| 29 |
}
|
| 30 |
esyslog() { :; }
|
| 31 |
umask 022
|
| 32 |
|
| 33 |
usage() {
|
| 34 |
cat << USAGE_END
|
| 35 |
|
| 36 |
Usage: ${HILITE}binutils-config${NORMAL} ${GOOD}[options]${NORMAL} ${BRACKET}[binutils profile]${NORMAL}
|
| 37 |
|
| 38 |
${HILITE}General Options:${NORMAL}
|
| 39 |
${GOOD}-B, --get-bin-path${NORMAL} Print current linker bin path
|
| 40 |
${GOOD}-c, --get-current-profile${NORMAL} Print current profile
|
| 41 |
${GOOD}-l, --list-profiles${NORMAL} Print a list of available profiles
|
| 42 |
${GOOD}-u, --uninstall${NORMAL} Remove all signs of specified target
|
| 43 |
${GOOD}-d, --debug${NORMAL} Execute with debug output
|
| 44 |
|
| 45 |
${HILITE}Arch Specific Cruft:${NORMAL}
|
| 46 |
${GOOD}--amd64${NORMAL} Install extra amd64 links (x86_64)
|
| 47 |
${GOOD}--arm${NORMAL} Install extra arm links (arm/armeb)
|
| 48 |
${GOOD}--mips${NORMAL} Install extra mips links (mips/mipsel)
|
| 49 |
${GOOD}--x86${NORMAL} Install extra x86 links (i[3-6]86)
|
| 50 |
|
| 51 |
Profile names are of the form: ${BRACKET}<CTARGET>-<binutils version>${NORMAL}
|
| 52 |
For example: ${BRACKET}i686-pc-linux-gnu-2.15.92.0.2${NORMAL}
|
| 53 |
|
| 54 |
For more info, please see ${HILITE}binutils-config${NORMAL}(8).
|
| 55 |
USAGE_END
|
| 56 |
}
|
| 57 |
|
| 58 |
switch_profile() {
|
| 59 |
unset TARGET VER LIBPATH FAKE_TARGETS
|
| 60 |
source "${ENV_D}/${PROFILE}"
|
| 61 |
if [[ -z ${TARGET} ]] ; then
|
| 62 |
eerror "${PROFILE} is invalid (no \$TARGET defined) :("
|
| 63 |
return 1
|
| 64 |
fi
|
| 65 |
if [[ -z ${VER} ]] ; then
|
| 66 |
eerror "${PROFILE} is invalid (no \$VER defined) :("
|
| 67 |
return 1
|
| 68 |
fi
|
| 69 |
|
| 70 |
#
|
| 71 |
# Older installs don't have 'FAKE_TARGETS' defined, so lets
|
| 72 |
# update these env.d entries so that we don't force the poor
|
| 73 |
# user to re-emerge their binutils just for 1 envvar :/
|
| 74 |
#
|
| 75 |
if [[ ${FAKE_TARGETS-poor user} == "poor user" ]] ; then
|
| 76 |
local targ=${TARGET/-*}
|
| 77 |
local FAKE_TARGETS=${TARGET}
|
| 78 |
case ${targ} in
|
| 79 |
mips|powerpc|sparc)
|
| 80 |
FAKE_TARGETS="${FAKE_TARGETS} ${TARGET/-/64-}";;
|
| 81 |
mips64|powerpc64|sparc64)
|
| 82 |
FAKE_TARGETS="${FAKE_TARGETS} ${TARGET/64-/-}";;
|
| 83 |
esac
|
| 84 |
echo "FAKE_TARGETS=\"${FAKE_TARGETS}\"" >> "${ENV_D}/${PROFILE}"
|
| 85 |
fi
|
| 86 |
local fake_targ_append="${TARGET#*-}"
|
| 87 |
FAKE_TARGETS="${FAKE_TARGETS} ${FAKE_TARGETS_USER// /-${fake_targ_append} }"
|
| 88 |
|
| 89 |
ebegin "Switching to ${PROFILE}"
|
| 90 |
|
| 91 |
# Find the bin wrapper
|
| 92 |
local wrapper
|
| 93 |
for wrapper in lib lib64 lib32 ; do
|
| 94 |
wrapper="${EROOT}usr/${wrapper}/misc/binutils-config-${VERSION}"
|
| 95 |
[[ -e ${wrapper}/libbinutils-config.a ]] && break
|
| 96 |
done
|
| 97 |
|
| 98 |
#
|
| 99 |
# Generate binary symlinks
|
| 100 |
# On systems that do 32bit/64bit, we need to fake an
|
| 101 |
# extra set of binary names (${FAKE_TARGETS})
|
| 102 |
#
|
| 103 |
BINPATH=""
|
| 104 |
BINPATH_LINKS=""
|
| 105 |
if [[ ${TARGET} != ${HOST} ]] ; then
|
| 106 |
#
|
| 107 |
# Newer paths: /usr/${HOST}/${TARGET}/...
|
| 108 |
# Older paths: /usr/${TARGET}/...
|
| 109 |
#
|
| 110 |
if [[ -d ${EROOT}usr/${HOST}/${TARGET}/binutils-bin/${VER} ]] ; then
|
| 111 |
BINPATH=usr/${HOST}/${TARGET}/binutils-bin/${VER}
|
| 112 |
BINPATH_LINKS=usr/libexec/gcc/${TARGET}
|
| 113 |
fi
|
| 114 |
fi
|
| 115 |
if [[ -z ${BINPATH} ]] ; then
|
| 116 |
BINPATH=usr/${TARGET}/binutils-bin/${VER}
|
| 117 |
BINPATH_LINKS=usr/${TARGET}/bin
|
| 118 |
fi
|
| 119 |
cd "${EROOT}${BINPATH}" || exit 1
|
| 120 |
mkdir -p "${EROOT}${BINPATH_LINKS}" "${EROOT}usr/bin"
|
| 121 |
for x in * ; do
|
| 122 |
case ${x} in
|
| 123 |
ld|ld64)
|
| 124 |
# remove symlink first if exists, to avoid overwriting
|
| 125 |
# the target in the cp that follows
|
| 126 |
local oldumask=$(umask)
|
| 127 |
umask 077
|
| 128 |
local ctargetfile="${TMPDIR:-${BPREFIX}/tmp}"/ctarget-$$.c
|
| 129 |
rm -f "${ctargetfile}"
|
| 130 |
(
|
| 131 |
plugins=
|
| 132 |
echo "#include <ldplugin.h>"
|
| 133 |
echo "char const *CTARGET=\"${TARGET}\";"
|
| 134 |
if [[ ${TARGET} != ${HOST} ]]; then
|
| 135 |
# cross linker
|
| 136 |
plugins="${plugins} gnu"
|
| 137 |
# allow debugging any plugin
|
| 138 |
[[ -z ${LDPLUGINS} ]] || plugins=${LDPLUGINS}
|
| 139 |
else
|
| 140 |
case ${TARGET} in
|
| 141 |
*-darwin*) plugins="${plugins} darwin" ;;
|
| 142 |
*-aix*) plugins="${plugins} aix" ;;
|
| 143 |
*-hpux*) plugins="${plugins} hpux" ;;
|
| 144 |
*-linux* | *-solaris*) plugins="${plugins} gnu" ;;
|
| 145 |
*) eerror "unknown platform ${CTARGET}"
|
| 146 |
exit 1
|
| 147 |
;;
|
| 148 |
esac
|
| 149 |
fi
|
| 150 |
for plugin in ${plugins}; do
|
| 151 |
echo "#include <${plugin}plugin.h>"
|
| 152 |
done
|
| 153 |
echo "LdPluginFct const* LDPLUGINS() {"
|
| 154 |
echo " static const LdPluginFct plugins[] = {"
|
| 155 |
for plugin in ${plugins}; do
|
| 156 |
echo " ${plugin}plugin,"
|
| 157 |
done
|
| 158 |
echo " 0 };"
|
| 159 |
echo " return plugins; };"
|
| 160 |
echo -n "int DEBUG(void) { return "
|
| 161 |
[[ ${DEBUG} == yes ]] && echo "1; }" || echo "0; }"
|
| 162 |
) > "${ctargetfile}" || return 1
|
| 163 |
umask ${oldumask} || return 1
|
| 164 |
local cc=$(type -p "${CC}")
|
| 165 |
[[ -z ${cc} ]] && set_BUILD
|
| 166 |
[[ -z ${cc} ]] && [[ ${HOST} == ${BUILD} ]] && cc=$(type -p "${BUILD_CC}")
|
| 167 |
[[ -z ${cc} ]] && cc=$(type -p "${HOST}-gcc")
|
| 168 |
[[ -z ${cc} ]] && cc=$(type -p "${HOST}-cc")
|
| 169 |
if [[ -z ${cc} && ${HOST} == ${BUILD} ]]; then
|
| 170 |
[[ -z ${cc} ]] && cc=$(type -p gcc)
|
| 171 |
[[ -z ${cc} ]] && cc=$(type -p cc)
|
| 172 |
fi
|
| 173 |
if [[ -z ${cc} ]]; then
|
| 174 |
echo -n "Cannot find compiler for ${HOST} (try setting CC)"
|
| 175 |
return 1
|
| 176 |
fi
|
| 177 |
rm -f "${EROOT}${BINPATH_LINKS}/${x}.new" > /dev/null || return 1
|
| 178 |
"${cc}" -o "${EROOT}${BINPATH_LINKS}/${x}.new" "${ctargetfile}" \
|
| 179 |
"-I${wrapper}" "${wrapper}/libbinutils-config.a" ${CFLAGS} || return 1
|
| 180 |
[[ ${DEBUG} == yes ]] || rm -f "${ctargetfile}" || return 1
|
| 181 |
mv -f "${EROOT}${BINPATH_LINKS}/${x}"{.new,} || return 1
|
| 182 |
touch -r "${EROOT}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
|
| 183 |
;;
|
| 184 |
*)
|
| 185 |
ln -sf "${EPREFIX}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
|
| 186 |
;;
|
| 187 |
esac
|
| 188 |
ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${TARGET}-${x} || return 1
|
| 189 |
for fake in ${FAKE_TARGETS} ; do
|
| 190 |
[[ -f ${ENV_D}/config-${fake} ]] && continue
|
| 191 |
ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${fake}-${x} || return 1
|
| 192 |
done
|
| 193 |
if [[ ${TARGET} == ${HOST} ]] ; then
|
| 194 |
ln -sf ${TARGET}-${x} "${EROOT}"usr/bin/${x} || return 1
|
| 195 |
fi
|
| 196 |
done
|
| 197 |
|
| 198 |
#
|
| 199 |
# Generate library / ldscripts symlinks
|
| 200 |
#
|
| 201 |
LIBPATH=$(echo "${LIBPATH}" | sed -e "s|^${EPREFIX}/|/|g" )
|
| 202 |
LIBPATH=${LIBPATH:-usr/lib/binutils/${TARGET}/${VER}}
|
| 203 |
cd "${EROOT}${LIBPATH}" || exit 1
|
| 204 |
if [[ ${TARGET} == ${HOST} ]] ; then
|
| 205 |
dstlib="${EROOT}"usr/${HOST}/lib
|
| 206 |
else
|
| 207 |
dstlib="${EROOT}"usr/${HOST}/${TARGET}/lib
|
| 208 |
# Clean out old path
|
| 209 |
rm -rf "${EROOT}"usr/${TARGET}/lib/ldscripts
|
| 210 |
rmdir "${EROOT}"usr/${TARGET}/lib >& /dev/null
|
| 211 |
fi
|
| 212 |
# When upgrading, we need to clean up ldscripts and libs
|
| 213 |
rm -rf "${dstlib}/ldscripts" "${EROOT}${BINPATH_LINKS}"/ldscripts
|
| 214 |
mkdir -p "${dstlib}"
|
| 215 |
ln -sf "${EPREFIX}/${LIBPATH}/ldscripts" "${dstlib}"/ldscripts
|
| 216 |
find -L "${dstlib}" -type l -exec rm {} \;
|
| 217 |
for x in lib* ; do
|
| 218 |
ln -sf "${EPREFIX}/${LIBPATH}/${x}" "${dstlib}/${x}"
|
| 219 |
done
|
| 220 |
|
| 221 |
#
|
| 222 |
# Generate include symlinks
|
| 223 |
#
|
| 224 |
INCPATH=${LIBPATH}/include
|
| 225 |
if [[ -d ${EROOT}${INCPATH} ]] ; then
|
| 226 |
cd "${EROOT}${INCPATH}" || exit 1
|
| 227 |
if [[ ${HOST} == ${TARGET} ]] ; then
|
| 228 |
mkdir -p "${EROOT}usr/include"
|
| 229 |
for x in * ; do
|
| 230 |
ln -sf "${EPREFIX}/${INCPATH}/${x}" "${EROOT}usr/include/${x}"
|
| 231 |
done
|
| 232 |
else
|
| 233 |
# Clean out old path
|
| 234 |
find . -type f -exec rm -f "${EROOT}usr/${TARGET}/usr/include/{}" \;
|
| 235 |
rmdir "${EROOT}usr/${TARGET}/usr/include" >& /dev/null
|
| 236 |
rmdir "${EROOT}usr/${TARGET}/usr" >& /dev/null
|
| 237 |
rmdir "${EROOT}usr/${TARGET}" >& /dev/null
|
| 238 |
fi
|
| 239 |
fi
|
| 240 |
|
| 241 |
#
|
| 242 |
# Make sure proper paths get updated
|
| 243 |
#
|
| 244 |
if [[ ${TARGET} == ${HOST} ]] ; then
|
| 245 |
echo "PATH=${EPREFIX}${BINPATH}" > "${EROOT}"etc/env.d/05binutils
|
| 246 |
echo "ROOTPATH=${EPREFIX}${BINPATH}" >> "${EROOT}"etc/env.d/05binutils
|
| 247 |
DATAPATH="${EPREFIX}"/usr/share/binutils-data/${TARGET}/${VER}
|
| 248 |
[[ -d ${DATAPATH}/man ]] && \
|
| 249 |
echo "MANPATH=${DATAPATH}/man" >> "${EROOT}"etc/env.d/05binutils
|
| 250 |
[[ -d ${DATAPATH}/info ]] && \
|
| 251 |
echo "INFOPATH=${DATAPATH}/info" >> "${EROOT}"etc/env.d/05binutils
|
| 252 |
# hmm, `ld` has this in SEARCH_DIR(), but ld.so does not ...
|
| 253 |
echo "LDPATH=${EPREFIX}/usr/${TARGET}/lib" >> "${EROOT}"etc/env.d/05binutils
|
| 254 |
fi
|
| 255 |
|
| 256 |
eend 0
|
| 257 |
|
| 258 |
echo "CURRENT=${VER}" > "${ENV_D}/config-${TARGET}"
|
| 259 |
echo "FAKE_TARGETS=\"${FAKE_TARGETS}\"" >> "${ENV_D}/config-${TARGET}"
|
| 260 |
|
| 261 |
#
|
| 262 |
# Regen env.d if need/can be
|
| 263 |
#
|
| 264 |
if [[ ${EROOT%/} == ${BPREFIX} ]] && [[ ${TARGET} == ${HOST} ]] ; then
|
| 265 |
env-update
|
| 266 |
echo
|
| 267 |
ewarn "Please remember to run:"
|
| 268 |
echo
|
| 269 |
ewarn " (bash) # source ${EPREFIX}/etc/profile"
|
| 270 |
ewarn "or"
|
| 271 |
ewarn " (tcsh) # source ${EPREFIX}/etc/csh.login"
|
| 272 |
echo
|
| 273 |
fi
|
| 274 |
|
| 275 |
return 0
|
| 276 |
}
|
| 277 |
|
| 278 |
uninstall_target() {
|
| 279 |
if [[ -z ${EPREFIX} && ${TARGET} == ${HOST} ]] ; then
|
| 280 |
eerror "${argv0}: Refusing to uninstall native binutils"
|
| 281 |
exit 1
|
| 282 |
fi
|
| 283 |
|
| 284 |
shopt -s nullglob
|
| 285 |
PROFILE=""
|
| 286 |
|
| 287 |
for PROFILE in "${ENV_D}"/${TARGET}-* ; do
|
| 288 |
ewarn "Removing all signs of ${PROFILE##*/}"
|
| 289 |
rm -f "${ENV_D}"/${PROFILE}
|
| 290 |
done
|
| 291 |
if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
|
| 292 |
eerror "${argv0}: No profiles exist for '${TARGET}'"
|
| 293 |
exit 1
|
| 294 |
fi
|
| 295 |
|
| 296 |
unset FAKE_TARGETS
|
| 297 |
source "${ENV_D}"/config-${TARGET}
|
| 298 |
|
| 299 |
for target in ${TARGET} ${FAKE_TARGETS}; do
|
| 300 |
for x in addr2line ar as c++filt elf2flt flthdr gprof ld ld.real \
|
| 301 |
nm objcopy objdump ranlib readelf size strings strip ; do
|
| 302 |
rm -f "${EROOT}"usr/bin/${target}-${x}
|
| 303 |
rm -f "${EROOT}"usr/{${HOST}/,}${target}/bin/${x}
|
| 304 |
rm -f "${EROOT}"usr/libexec/gcc/${target}/${x}
|
| 305 |
done
|
| 306 |
done
|
| 307 |
for x in ansidecl.h bfd.h bfdlink.h dis-asm.h symcat.h ; do
|
| 308 |
rm -f "${EROOT}"usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
|
| 309 |
done
|
| 310 |
for x in bfd iberty opcodes ; do
|
| 311 |
rm -f "${EROOT}"usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
|
| 312 |
done
|
| 313 |
# Delete broken symlinks
|
| 314 |
local destdir="${EROOT}usr/${HOST}/${TARGET}"
|
| 315 |
rm -f "${destdir}"/lib/ldscripts
|
| 316 |
find -L "${destdir}"/lib -type l -exec rm {} \;
|
| 317 |
rmdir "${destdir}"/lib "${destdir}" 2>/dev/null
|
| 318 |
rmdir "${destdir}"/{bin,include,lib,usr} "${destdir}" 2>/dev/null
|
| 319 |
rmdir "${EROOT}"var/db/pkg/cross-${TARGET} 2>/dev/null
|
| 320 |
|
| 321 |
rm -f "${ENV_D}"/config-${TARGET}
|
| 322 |
rm -f "${ENV_D}"/${TARGET}-*
|
| 323 |
}
|
| 324 |
|
| 325 |
get_bin_path() {
|
| 326 |
if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
|
| 327 |
eerror "${argv0}: No binutils profile is active!"
|
| 328 |
return 1
|
| 329 |
fi
|
| 330 |
|
| 331 |
source "${ENV_D}/config-${PROFILE}"
|
| 332 |
|
| 333 |
if [[ -z ${CURRENT} ]] ; then
|
| 334 |
eerror "${argv0}: No binutils profile is active!"
|
| 335 |
return 1
|
| 336 |
fi
|
| 337 |
|
| 338 |
unset TARGET VER
|
| 339 |
source "${ENV_D}/${PROFILE}-${CURRENT}"
|
| 340 |
if [[ -z ${TARGET} ]] ; then
|
| 341 |
eerror "${PROFILE}-${CURRENT} is invalid (no \$TARGET defined) :("
|
| 342 |
return 1
|
| 343 |
fi
|
| 344 |
if [[ -z ${VER} ]] ; then
|
| 345 |
eerror "${PROFILE}-${CURRENT} is invalid (no \$VER defined) :("
|
| 346 |
return 1
|
| 347 |
fi
|
| 348 |
|
| 349 |
if [[ ${TARGET} == ${HOST} ]]; then
|
| 350 |
echo "${BPREFIX}/usr/${TARGET}/binutils-bin/${VER}"
|
| 351 |
else
|
| 352 |
echo "${BPREFIX}/usr/${HOST}/${TARGET}/binutils-bin/${VER}"
|
| 353 |
fi
|
| 354 |
|
| 355 |
return 0
|
| 356 |
}
|
| 357 |
|
| 358 |
get_current_profile() {
|
| 359 |
if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
|
| 360 |
eerror "${argv0}: No binutils profile is active!"
|
| 361 |
return 1
|
| 362 |
fi
|
| 363 |
|
| 364 |
source "${ENV_D}/config-${PROFILE}"
|
| 365 |
|
| 366 |
if [[ -z ${CURRENT} ]] ; then
|
| 367 |
eerror "${argv0}: No binutils profile is active!"
|
| 368 |
return 1
|
| 369 |
fi
|
| 370 |
|
| 371 |
echo "${PROFILE}-${CURRENT}"
|
| 372 |
|
| 373 |
return 0
|
| 374 |
}
|
| 375 |
|
| 376 |
list_profiles() {
|
| 377 |
local i=1 x
|
| 378 |
|
| 379 |
set_HOST
|
| 380 |
|
| 381 |
if [[ ${EROOT} != ${BPREFIX}/ ]] ; then
|
| 382 |
echo "Using binutils-config info in ${EROOT}"
|
| 383 |
fi
|
| 384 |
target=
|
| 385 |
for x in "${ENV_D}"/* ; do
|
| 386 |
if [[ -f ${x} ]] && [[ ${x##*/} != config-* ]] ; then
|
| 387 |
source "${x}"
|
| 388 |
if [[ ${target} != ${TARGET} ]] ; then
|
| 389 |
[[ -n ${target} ]] && echo
|
| 390 |
target=${TARGET}
|
| 391 |
fi
|
| 392 |
|
| 393 |
x=${x##*/}
|
| 394 |
if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
|
| 395 |
source "${ENV_D}/config-${TARGET}"
|
| 396 |
if [[ ${VER} == ${CURRENT} ]] ; then
|
| 397 |
[[ ${TARGET} == ${HOST} ]] \
|
| 398 |
&& x="${x} ${GOOD}*${NORMAL}" \
|
| 399 |
|| x="${x} ${HILITE}*${NORMAL}"
|
| 400 |
fi
|
| 401 |
fi
|
| 402 |
echo " [${i}] ${x}"
|
| 403 |
((++i))
|
| 404 |
fi
|
| 405 |
done
|
| 406 |
}
|
| 407 |
|
| 408 |
set_HOST() {
|
| 409 |
[[ -n ${HOST} ]] && return 0
|
| 410 |
|
| 411 |
if [[ -z ${CHOST} ]] ; then
|
| 412 |
HOST=$(portageq envvar CHOST)
|
| 413 |
else
|
| 414 |
HOST=${CHOST}
|
| 415 |
fi
|
| 416 |
}
|
| 417 |
|
| 418 |
set_BUILD() {
|
| 419 |
[[ -n ${BUILD} ]] && return 0
|
| 420 |
|
| 421 |
if [[ -z ${CBUILD} ]] ; then
|
| 422 |
BUILD=$(env -i "${BPREFIX}"/usr/bin/portageq envvar CBUILD)
|
| 423 |
else
|
| 424 |
BUILD=${CBUILD}
|
| 425 |
fi
|
| 426 |
}
|
| 427 |
|
| 428 |
ENV_D="${EROOT}etc/env.d/binutils"
|
| 429 |
|
| 430 |
DEBUG="no"
|
| 431 |
NEED_ACTION="yes"
|
| 432 |
DOIT="switch_profile"
|
| 433 |
PROFILE=""
|
| 434 |
FAKE_TARGETS_USER=""
|
| 435 |
HOST=""
|
| 436 |
|
| 437 |
while [[ $# -gt 0 ]] ; do
|
| 438 |
x=$1
|
| 439 |
shift
|
| 440 |
case ${x} in
|
| 441 |
-B|--get-bin-path)
|
| 442 |
DOIT="get_bin_path"
|
| 443 |
NEED_ACTION="no"
|
| 444 |
;;
|
| 445 |
-c|--get-current-profile)
|
| 446 |
if [[ ${NEED_ACTION} == "yes" ]] ; then
|
| 447 |
NEED_ACTION="no"
|
| 448 |
DOIT="get_current_profile"
|
| 449 |
fi
|
| 450 |
;;
|
| 451 |
-d|--debug)
|
| 452 |
DEBUG="yes"
|
| 453 |
;;
|
| 454 |
-l|--list-profiles)
|
| 455 |
if [[ ${NEED_ACTION} == "yes" ]] ; then
|
| 456 |
NEED_ACTION="no"
|
| 457 |
DOIT="list_profiles"
|
| 458 |
fi
|
| 459 |
;;
|
| 460 |
-u|--uninstall)
|
| 461 |
if [[ ${NEED_ACTION} == "yes" ]] ; then
|
| 462 |
NEED_ACTION="no"
|
| 463 |
DOIT="uninstall_target"
|
| 464 |
TARGET=$1
|
| 465 |
shift
|
| 466 |
fi
|
| 467 |
;;
|
| 468 |
-h|--help)
|
| 469 |
usage
|
| 470 |
exit 0
|
| 471 |
;;
|
| 472 |
-V|--version)
|
| 473 |
cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-1.9,v 1.10 2007/05/06 09:04:01 vapier Exp $"
|
| 474 |
cvsver=${cvsver##*binutils-config-}
|
| 475 |
bver=${cvsver%%,v *}
|
| 476 |
cvsver=${cvsver#* }
|
| 477 |
echo "binutils-config-${bver} (r${cvsver%% *})"
|
| 478 |
exit 0
|
| 479 |
;;
|
| 480 |
--amd64|--arm|--mips|--x86)
|
| 481 |
if [[ ${NEED_ACTION} == "yes" ]] ; then
|
| 482 |
# Make sure we have a space after each target
|
| 483 |
NEED_ACTION="no"
|
| 484 |
[[ -z ${PROFILE} ]] && PROFILE="current"
|
| 485 |
case ${x} in
|
| 486 |
--amd64) FAKE_TARGETS_USER="x86_64 ";;
|
| 487 |
--arm) FAKE_TARGETS_USER="arm armeb ";;
|
| 488 |
--x86) FAKE_TARGETS_USER="i386 i486 i586 i686 ";;
|
| 489 |
--mips) FAKE_TARGETS_USER="mips mips64 mipsel mipsel64 ";;
|
| 490 |
esac
|
| 491 |
fi
|
| 492 |
;;
|
| 493 |
-*)
|
| 494 |
eerror "${0##*/}: Invalid switch! Try '--help'."
|
| 495 |
exit 1
|
| 496 |
;;
|
| 497 |
*)
|
| 498 |
if [[ -n ${PROFILE} ]] && [[ ${PROFILE} != "current" ]] ; then
|
| 499 |
eerror "${argv0}: Too many arguments! Run ${argv0} without parameters for help."
|
| 500 |
exit 1
|
| 501 |
fi
|
| 502 |
|
| 503 |
if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
|
| 504 |
# User gave us a # representing the profile
|
| 505 |
i=1
|
| 506 |
for y in "${ENV_D}"/* ; do
|
| 507 |
[[ ${y/config-} != ${y} ]] && continue
|
| 508 |
|
| 509 |
if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
|
| 510 |
PROFILE=${y##*/}
|
| 511 |
NEED_ACTION="no"
|
| 512 |
break
|
| 513 |
fi
|
| 514 |
((++i))
|
| 515 |
done
|
| 516 |
fi
|
| 517 |
|
| 518 |
if [[ -z ${PROFILE} ]] ; then
|
| 519 |
# User gave us a full HOST-ver
|
| 520 |
x=${x##*/}
|
| 521 |
if [[ ! -f ${ENV_D}/${x} ]] && [[ ! -f ${ENV_D}/config-${x} ]] ; then
|
| 522 |
# Maybe they just gave us a ver ...
|
| 523 |
set_HOST
|
| 524 |
if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
|
| 525 |
x=${HOST}-${x}
|
| 526 |
else
|
| 527 |
eerror "${argv0}: Could not locate '$x' in '${ENV_D}/'!"
|
| 528 |
exit 1
|
| 529 |
fi
|
| 530 |
fi
|
| 531 |
PROFILE=${x}
|
| 532 |
NEED_ACTION="no"
|
| 533 |
fi
|
| 534 |
;;
|
| 535 |
esac
|
| 536 |
done
|
| 537 |
|
| 538 |
[[ ${NEED_ACTION} == "yes" ]] && usage && exit 1
|
| 539 |
[[ ${DEBUG} == "yes" ]] && { PS4='($LINENO) +'; set -x; }
|
| 540 |
|
| 541 |
[[ ${DOIT} != "list_profiles" ]] && set_HOST
|
| 542 |
[[ -z ${PROFILE} ]] && PROFILE=${HOST}
|
| 543 |
[[ ${PROFILE} == "current" ]] && PROFILE=$(PROFILE=${HOST} get_current_profile)
|
| 544 |
eval ${DOIT}
|
| 545 |
|
| 546 |
# vim:ts=4
|