Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/prefix:master commit in: sys-devel/binutils-config/, sys-devel/binutils-config/files/
Date: Thu, 30 May 2019 09:13:51
Message-Id: 1559207614.82c2c71837628069aeb9484d295d304b3387d91c.grobian@gentoo
1 commit: 82c2c71837628069aeb9484d295d304b3387d91c
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu May 30 09:13:34 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu May 30 09:13:34 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=82c2c718
7
8 sys-devel/binutils-config: sync (remove interrevisions)
9
10 Package-Manager: Portage-2.3.62-prefix, Repoman-2.3.13
11 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
12
13 .../binutils-config/binutils-config-5-r03.5.ebuild | 77 ----
14 ...-r03.4.ebuild => binutils-config-5.1-r1.ebuild} | 6 +-
15 .../binutils-config/files/binutils-config-5.1 | 486 +++++++++++++++++++++
16 3 files changed, 489 insertions(+), 80 deletions(-)
17
18 diff --git a/sys-devel/binutils-config/binutils-config-5-r03.5.ebuild b/sys-devel/binutils-config/binutils-config-5-r03.5.ebuild
19 deleted file mode 100644
20 index a00860e6b2..0000000000
21 --- a/sys-devel/binutils-config/binutils-config-5-r03.5.ebuild
22 +++ /dev/null
23 @@ -1,77 +0,0 @@
24 -# Copyright 1999-2018 Gentoo Foundation
25 -# Distributed under the terms of the GNU General Public License v2
26 -
27 -EAPI="6"
28 -
29 -inherit eutils prefix
30 -
31 -DESCRIPTION="Utility to change the binutils version being used"
32 -HOMEPAGE="https://www.gentoo.org/"
33 -GIT_REV="edc0d44f70c27daebcc080ac5d08e8e191bccd95"
34 -WRAPPER_REV="${PV}.3.4"
35 -SRC_URI="https://gitweb.gentoo.org/repo/proj/prefix.git/plain/sys-devel/binutils-config/files/ldwrapper.c?id=${GIT_REV} -> ${PN}-ldwrapper-${WRAPPER_REV}.c"
36 -
37 -LICENSE="GPL-2"
38 -SLOT="0"
39 -KEYWORDS="~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
40 -IUSE=""
41 -
42 -# We also RDEPEND on sys-apps/findutils which is in base @system
43 -RDEPEND="sys-apps/gentoo-functions
44 - !<app-admin/eselect-1.4.5"
45 -
46 -S=${WORKDIR}
47 -
48 -# NOTE: the ld wrapper is only enabled on rpath versions of prefix.
49 -src_prepare() {
50 - cp "${FILESDIR}"/${PN}-${PV} ./${PN} || die
51 - if use prefix-guest; then
52 - epatch "${FILESDIR}/${PN}-5-ldwrapper.patch"
53 - fi
54 - eprefixify ${PN}
55 - eapply_user
56 -}
57 -
58 -src_configure() {
59 - :
60 -}
61 -
62 -src_compile() {
63 - use prefix-guest || return
64 - local args=(
65 - $(tc-getCC)
66 - ${CPPFLAGS}
67 - ${CFLAGS}
68 - -o ldwrapper "${DISTDIR}"/${PN}-ldwrapper-${WRAPPER_REV}.c
69 - -DEPREFIX=\"${EPREFIX}\"
70 - -DCHOST=\"${CHOST}\"
71 - ${LDFLAGS}
72 - )
73 - echo ${args[*]}
74 - "${args[@]}" || die
75 -}
76 -
77 -src_install() {
78 - dobin ${PN}
79 - use prefix && eprefixify "${ED}"/usr/bin/${PN}
80 - sed -i "s:@PV@:${PVR}:g" "${ED}"/usr/bin/${PN} || die
81 - doman "${FILESDIR}"/${PN}.8
82 -
83 - dodir /usr/$(get_libdir)/misc/binutils-config
84 - mv "${S}"/ldwrapper "${ED}"/usr/$(get_libdir)/misc/binutils-config/
85 -
86 - insinto /usr/share/eselect/modules
87 - doins "${FILESDIR}"/binutils.eselect
88 -}
89 -
90 -pkg_preinst() {
91 - # Force a refresh when upgrading from an older version that symlinked
92 - # in all the libs & includes that binutils-libs handles. #528088
93 - if has_version "<${CATEGORY}/${PN}-5" ; then
94 - local bc current
95 - bc="${ED}/usr/bin/binutils-config"
96 - if current=$("${bc}" -c) ; then
97 - "${bc}" "${current}"
98 - fi
99 - fi
100 -}
101
102 diff --git a/sys-devel/binutils-config/binutils-config-5-r03.4.ebuild b/sys-devel/binutils-config/binutils-config-5.1-r1.ebuild
103 similarity index 96%
104 rename from sys-devel/binutils-config/binutils-config-5-r03.4.ebuild
105 rename to sys-devel/binutils-config/binutils-config-5.1-r1.ebuild
106 index a00860e6b2..5cae4a9223 100644
107 --- a/sys-devel/binutils-config/binutils-config-5-r03.4.ebuild
108 +++ b/sys-devel/binutils-config/binutils-config-5.1-r1.ebuild
109 @@ -1,14 +1,14 @@
110 -# Copyright 1999-2018 Gentoo Foundation
111 +# Copyright 1999-2019 Gentoo Authors
112 # Distributed under the terms of the GNU General Public License v2
113
114 -EAPI="6"
115 +EAPI=6
116
117 inherit eutils prefix
118
119 DESCRIPTION="Utility to change the binutils version being used"
120 HOMEPAGE="https://www.gentoo.org/"
121 GIT_REV="edc0d44f70c27daebcc080ac5d08e8e191bccd95"
122 -WRAPPER_REV="${PV}.3.4"
123 +WRAPPER_REV="${PV%%.*}.3.4"
124 SRC_URI="https://gitweb.gentoo.org/repo/proj/prefix.git/plain/sys-devel/binutils-config/files/ldwrapper.c?id=${GIT_REV} -> ${PN}-ldwrapper-${WRAPPER_REV}.c"
125
126 LICENSE="GPL-2"
127
128 diff --git a/sys-devel/binutils-config/files/binutils-config-5.1 b/sys-devel/binutils-config/files/binutils-config-5.1
129 new file mode 100644
130 index 0000000000..f55d529c93
131 --- /dev/null
132 +++ b/sys-devel/binutils-config/files/binutils-config-5.1
133 @@ -0,0 +1,486 @@
134 +#!/bin/bash
135 +# Copyright 1999-2019 Gentoo Authors
136 +# Distributed under the terms of the GNU General Public License v2
137 +
138 +# Format of /etc/env.d/binutils/:
139 +# config-TARGET: CURRENT=version for TARGET
140 +# TARGET-VER: has a TARGET and VER variable
141 +
142 +EPREFIX="@GENTOO_PORTAGE_EPREFIX@"
143 +if [[ ${EPREFIX} == "@"GENTOO_PORTAGE_EPREFIX"@" ]] ; then
144 + EPREFIX=""
145 +fi
146 +
147 +: ${ROOT:=/}
148 +[[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
149 +[[ ${ROOT} != /* ]] && ROOT="${PWD%/}/${ROOT}"
150 +
151 +EROOT="${ROOT%/}${EPREFIX}/"
152 +
153 +cd "${EPREFIX}/"
154 +
155 +trap ":" INT QUIT TSTP
156 +
157 +argv0=${0##*/}
158 +FUNCTIONS_SH="${EPREFIX}/lib/gentoo/functions.sh"
159 +source ${FUNCTIONS_SH} || {
160 + echo "${argv0}: Could not source ${FUNCTIONS_SH}!" 1>&2
161 + exit 1
162 +}
163 +esyslog() { :; }
164 +die() { eerror "${argv0}: $*"; exit 1; }
165 +umask 022
166 +
167 +usage() {
168 +cat << USAGE_END
169 +Usage: ${HILITE}binutils-config${NORMAL} ${GOOD}[options]${NORMAL} ${BRACKET}[binutils profile]${NORMAL}
170 +
171 +${HILITE}General Options:${NORMAL}
172 + ${GOOD}-c, --get-current-profile${NORMAL} Print current profile
173 + ${GOOD}-l, --list-profiles${NORMAL} Print a list of available profiles
174 + ${GOOD}-u, --uninstall${NORMAL} Remove all signs of specified target
175 + ${GOOD}-d, --debug${NORMAL} Execute with debug output
176 +
177 +${HILITE}General Cruft:${NORMAL}
178 + ${GOOD}--linker${NORMAL} <linker> Switch to specified linker (if supported)
179 +
180 +Profile names are of the form: ${BRACKET}<CTARGET>-<binutils version>${NORMAL}
181 +For example: ${BRACKET}i686-pc-linux-gnu-2.15.92.0.2${NORMAL}
182 +
183 +For more info, please see ${HILITE}binutils-config${NORMAL}(8).
184 +USAGE_END
185 +
186 + exit ${1:-1}
187 +}
188 +
189 +mv_if_diff() {
190 + if cmp -s "$1" "$2" ; then
191 + rm -f "$1"
192 + else
193 + mv -f "$1" "$2"
194 + fi
195 +}
196 +atomic_ln() {
197 + local target=$1 linkdir=$2 linkname=$3 linktmp linkfull
198 + linktmp="${linkdir}/.binutils-config.tmp.${linkname}"
199 + linkfull="${linkdir}/${linkname}"
200 + if [[ -d ${linkfull} ]] ; then
201 + # if linking to a dir, we need a little magic to
202 + # make it atomic since `mv -T` is not portable
203 + rm -rf "${linktmp}"
204 + mkdir -p "${linktmp}"
205 + ln -sf "${target}" "${linktmp}/${linkname}"
206 + mv "${linktmp}/${linkname}" "${linktmp}/../"
207 + rmdir "${linktmp}"
208 + else
209 + # `ln` will expand into unlink();symlink(); which
210 + # is not atomic for a small amount of time, but
211 + # `mv` is a single rename() call
212 + ln -sf "${target}" "${linktmp}"
213 + mv "${linktmp}" "${linkfull}"
214 + fi
215 +}
216 +
217 +setup_env() {
218 + unset TARGET VER LIBPATH
219 + source "${ENV_D}/${PROFILE}"
220 + if [[ -z ${TARGET} ]] ; then
221 + eerror "${PROFILE} is invalid (no \$TARGET defined) :("
222 + return 1
223 + fi
224 + if [[ -z ${VER} ]] ; then
225 + eerror "${PROFILE} is invalid (no \$VER defined) :("
226 + return 1
227 + fi
228 +
229 + #
230 + # Generate binary symlinks
231 + #
232 + BINPATH=""
233 + BINPATH_LINKS=""
234 + if [[ ${TARGET} != ${HOST} ]] ; then
235 + #
236 + # Newer paths: /usr/${HOST}/${TARGET}/...
237 + # Older paths: /usr/${TARGET}/...
238 + #
239 + if [[ -d "${EROOT}"/usr/${HOST}/${TARGET}/binutils-bin/${VER} ]] ; then
240 + BINPATH="${EPREFIX}"/usr/${HOST}/${TARGET}/binutils-bin/${VER}
241 + BINPATH_LINKS="${EPREFIX}"/usr/libexec/gcc/${TARGET}
242 + fi
243 + fi
244 + if [[ -z ${BINPATH} ]] ; then
245 + BINPATH="${EPREFIX}"/usr/${TARGET}/binutils-bin/${VER}
246 + BINPATH_LINKS="${EPREFIX}"/usr/${TARGET}/bin
247 + fi
248 +}
249 +
250 +# Lists of headers that various versions have installed.
251 +HEADERS=(
252 + ansidecl.h bfd.h bfdlink.h demangle.h dis-asm.h dyn-string.h
253 + fibheap.h hashtab.h libiberty.h objalloc.h plugin-api.h
254 + splay-tree.h symcat.h
255 +)
256 +
257 +switch_profile() {
258 + local x
259 +
260 + ebegin "Switching to ${PROFILE}"
261 +
262 + setup_env || return 1
263 +
264 + cd "${ROOT}/${BINPATH}" || exit 1
265 + mkdir -p "${ROOT}/${BINPATH_LINKS}" "${EROOT}/usr/bin"
266 + for x in * ; do
267 + atomic_ln "${BINPATH}/${x}" "${ROOT}/${BINPATH_LINKS}" "${x}"
268 + atomic_ln "${BINPATH_LINKS}/${x}" "${EROOT}/usr/bin" "${TARGET}-${x}"
269 + if [[ ${TARGET} == ${HOST} ]] ; then
270 + atomic_ln "${TARGET}-${x}" "${EROOT}/usr/bin" "${x}"
271 + fi
272 + done
273 +
274 + #
275 + # Generate library / ldscripts symlinks
276 + #
277 + : ${LIBPATH:=${EPREFIX}/usr/lib/binutils/${TARGET}/${VER}}
278 + cd "${ROOT}/${LIBPATH}" || exit 1
279 + if [[ ${TARGET} == ${HOST} ]] ; then
280 + dstlib=${EROOT}/usr/${HOST}/lib
281 + else
282 + dstlib=${EROOT}/usr/${HOST}/${TARGET}/lib
283 + fi
284 + # When upgrading, we need to clean up ldscripts and libs.
285 + # Don't symlink back in the libs -- the binutils-lib package handles
286 + # these now.
287 + # TODO: Stop requiring even the ldscripts symlink.
288 + mkdir -p "${dstlib}"
289 + rm -rf "${ROOT}/${BINPATH_LINKS}"/ldscripts
290 + atomic_ln "${LIBPATH}/ldscripts" "${dstlib}" "ldscripts"
291 + # PREFIX LOCAL: we have gcc under dstlib here, and wiping symlinks
292 + # is a very bad idea there, or our symlinked sonames disappear!
293 + #find -L "${dstlib}" -xtype l -name 'lib*' -delete
294 + find -L "${dstlib}"/ldscripts -xtype l -name 'lib*' -delete
295 + # END PREFIX LOCAL
296 + # Detect older binutils w/broken rpaths. #562460
297 + # We can hardcode the "/lib" part since that's what the binutils
298 + # configure scripts have. They did not include any other path.
299 + if [[ $(scanelf -qF '%r#F' "${ROOT}/${BINPATH}/as") == */lib ]] ; then
300 + ewarn "Old cross-binutils detected; please re-emerge to fix (see bug #562460)."
301 + for x in lib* ; do
302 + atomic_ln "${LIBPATH}/${x}" "${dstlib}" "${x}"
303 + done
304 + fi
305 +
306 + #
307 + # Clean out old generated include symlinks
308 + #
309 + INCPATH=${LIBPATH}/include
310 + if [[ -d ${ROOT}/${INCPATH} ]] ; then
311 + cd "${ROOT}/${INCPATH}" || exit 1
312 + if [[ ${HOST} != ${TARGET} ]] ; then
313 + # Clean out old path -- cannot use '-exec {} +' syntax here
314 + find . -type f -exec rm -f "${EROOT}/usr/${TARGET}/usr/include/{}" \;
315 + rmdir "${EROOT}/usr/${TARGET}/usr/include" >& /dev/null
316 + rmdir "${EROOT}/usr/${TARGET}/usr" >& /dev/null
317 + rmdir "${EROOT}/usr/${TARGET}" >& /dev/null
318 + fi
319 + fi
320 +
321 + #
322 + # Make sure proper paths get updated
323 + #
324 + local env_update_flag="--no-ldconfig"
325 + if [[ ${TARGET} == ${HOST} ]] ; then
326 + # Delete old config now that binutils-libs installs these files.
327 + # Note: This skips ldconfig update if env.d had LDPATH, but meh.
328 + # Most people have upgraded to ld.so.conf.d, and someone else will
329 + # eventually re-run ldconfig for us.
330 + x="${EROOT}"/etc/ld.so.conf.d/05binutils.conf
331 + if [[ -e ${x} ]]; then
332 + rm -f "${x}"
333 + env_update_flag=""
334 + fi
335 +
336 + DATAPATH="${EPREFIX}"/usr/share/binutils-data/${TARGET}/${VER}
337 + local e="${EROOT}"/etc/env.d/05binutils
338 + local ee="${e}.tmp"
339 + rm -f "${ee}"
340 + [[ -d ${ROOT}/${DATAPATH}/man ]] && echo "MANPATH=${DATAPATH}/man" >> "${ee}"
341 + [[ -d ${ROOT}/${DATAPATH}/info ]] && echo "INFOPATH=${DATAPATH}/info" >> "${ee}"
342 + mv_if_diff "${ee}" "${e}"
343 + fi
344 +
345 + local c="${ENV_D}/config-${TARGET}"
346 + local cc="${c}.tmp"
347 + echo "CURRENT=${VER}" > "${cc}"
348 + mv_if_diff "${cc}" "${c}"
349 +
350 + eend 0
351 +
352 + #
353 + # Regen env.d if need/can be
354 + #
355 + if [[ ${ROOT} == "/" ]] && [[ ${TARGET} == ${HOST} ]] ; then
356 + env-update ${env_update_flag}
357 + echo
358 + ewarn "Please remember to run:"
359 + echo
360 + ewarn " # . ${EPREFIX}/etc/profile"
361 + echo
362 + fi
363 +
364 + return 0
365 +}
366 +
367 +uninstall_target() {
368 + : ${TARGET:=${UARG}}
369 +
370 + if [[ ${TARGET} == ${HOST} ]] ; then
371 + die "refusing to uninstall native binutils"
372 + fi
373 +
374 + shopt -s nullglob
375 + PROFILE=""
376 +
377 + for PROFILE in "${ENV_D}"/${TARGET}-* ; do
378 + ewarn "Removing all signs of ${PROFILE##*/}"
379 + rm -f "${ENV_D}"/${PROFILE}
380 + done
381 + if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
382 + die "no profiles exist for '${TARGET}'"
383 + fi
384 +
385 + rm -f "${ENV_D}"/config-${TARGET}
386 +
387 + local x
388 + for x in \
389 + addr2line ar as c++filt dwp elf2flt elfedit flthdr gprof \
390 + ld ld.{bfd,gold,real} \
391 + nm objcopy objdump ranlib readelf size strings strip
392 + do
393 + x=(
394 + "${EROOT}"/usr/bin/${TARGET}-${x}
395 + "${EROOT}"/usr/{${HOST}/,}${TARGET}/bin/${x}
396 + "${EROOT}"/usr/libexec/gcc/${TARGET}/${x}
397 + )
398 + rm -f "${x[@]}"
399 + done
400 + for x in "${HEADERS[@]}" ; do
401 + rm -f "${EROOT}"/usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
402 + done
403 + for x in bfd iberty opcodes ; do
404 + rm -f "${EROOT}"/usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
405 + done
406 + # Delete broken symlinks
407 + local destdir="${EROOT}/usr/${HOST}/${TARGET}"
408 + rm -f "${destdir}"/lib/ldscripts
409 + find -L "${destdir}"/lib -type l -exec rm {} +
410 + rmdir \
411 + "${destdir}"/{bin,include,lib,usr} \
412 + "${destdir}" \
413 + "${EROOT}"/var/db/pkg/cross-${TARGET} \
414 + "${EROOT}"/usr/{${HOST}/,}${TARGET}/bin \
415 + "${EROOT}"/usr/libexec/gcc/${TARGET} \
416 + 2>/dev/null
417 +
418 + rm -f "${ENV_D}"/${TARGET}-*
419 +}
420 +
421 +set_current_profile() {
422 + if [[ ! -f ${ENV_D}/config-${TARGET} ]] ; then
423 + eerror "${argv0}: unable to locate a profile for target: ${TARGET}"
424 + return 1
425 + fi
426 +
427 + source "${ENV_D}/config-${TARGET}"
428 +
429 + if [[ -z ${CURRENT} ]] ; then
430 + eerror "${argv0}: no binutils profile is active!"
431 + return 1
432 + fi
433 +
434 + echo "${TARGET}-${CURRENT}"
435 +
436 + return 0
437 +}
438 +get_current_profile() { echo "${PROFILE}" ; }
439 +
440 +list_profiles() {
441 + local x i target
442 +
443 + if [[ ${ROOT} != / ]] ; then
444 + echo "Using binutils-config info in ${ROOT}"
445 + fi
446 +
447 + set -- "${ENV_D}"/*
448 + target=
449 + i=1
450 +
451 + for x ; do
452 + # skip broken links and config files
453 + [[ -f ${x} ]] || continue
454 + [[ ${x} == */config-* ]] && continue
455 +
456 + source "${x}"
457 + if [[ ${target} != ${TARGET} ]] ; then
458 + [[ -n ${target} ]] && echo
459 + target=${TARGET}
460 + fi
461 +
462 + x=${x##*/}
463 + if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
464 + source "${ENV_D}/config-${TARGET}"
465 + if [[ ${VER} == ${CURRENT} ]] ; then
466 + [[ ${TARGET} == ${HOST} ]] \
467 + && x="${x} ${GOOD}*${NORMAL}" \
468 + || x="${x} ${HILITE}*${NORMAL}"
469 + fi
470 + fi
471 +
472 + # We would align the [...] field like so:
473 + #printf ' [%*ss] %s\n' ${##} "${i}" "${x}"
474 + # but this breaks simple scripting: `binutils -l | awk '{print $2}'`
475 +
476 + # Or we could align the target col like so:
477 + #printf ' [%s]%*s %s\n' "${i}" $(( ${##} - ${#i} )) "" "${x}"
478 + # but i'm not sold that it looks better
479 +
480 + # So keep it simple ... only makes a diff anyways for crazy people
481 + # like me which have 100+ binutils packages installed ...
482 + echo " [$i] ${x}"
483 + ((++i))
484 + done
485 +}
486 +
487 +switch_linker() {
488 + local bpath ld=$1
489 +
490 + case ${ld} in
491 + ld.*) ;;
492 + *) die "not supported: linker must start with 'ld.'" ;;
493 + esac
494 +
495 + setup_env || return 1
496 + bpath="${ROOT}/${BINPATH}"
497 +
498 + # does this binutils even support the requested linker ?
499 + if [[ ! -e ${bpath}/${ld} ]] ; then
500 + die "sorry, but ${PROFILE} doesn't support the ${ld} linker"
501 + fi
502 +
503 + # switch it up
504 + ebegin "Setting default linker to ${ld} for ${PROFILE}"
505 + atomic_ln ${ld} "${bpath}" ld
506 + eend $?
507 +}
508 +
509 +set_HOST() {
510 + # Set HOST to CHOST if it isn't already set
511 + : ${HOST:=${CHOST:-$(portageq envvar CHOST)}}
512 +}
513 +
514 +ENV_D="${EROOT}etc/env.d/binutils"
515 +
516 +DEBUG="no"
517 +NEED_ACTION="yes"
518 +DOIT="switch_profile"
519 +PROFILE="current"
520 +HOST=""
521 +TARGET=""
522 +unset UARG
523 +
524 +select_action() {
525 + if [[ ${NEED_ACTION} != "no" ]] ; then
526 + NEED_ACTION="no"
527 + DOIT=$1
528 + else
529 + die "one action at a time!"
530 + fi
531 +}
532 +
533 +while [[ $# -gt 0 ]] ; do
534 + x=$1
535 + shift
536 + case ${x} in
537 + -c|--get-current-profile) select_action get_current_profile ;;
538 + -l|--list|--list-profiles) select_action list_profiles ;;
539 + -u|--uninstall) select_action uninstall_target ;;
540 + --linker) select_action "switch_linker $1"; shift ;;
541 + -d|--debug) DEBUG="yes" ;;
542 + -h|--help) usage 0 ;;
543 + -V|--version)
544 + ver="@PV@"
545 + echo "binutils-config-${ver/@'PV'@/git}"
546 + exit 0
547 + ;;
548 + -*)
549 + die "invalid switch! Try '--help'."
550 + ;;
551 + *)
552 + if [[ ${UARG+set} == "set" ]] ; then
553 + die "only one profile/target at a time please"
554 + fi
555 + NEED_ACTION="maybe"
556 + UARG=${x}
557 + ;;
558 + esac
559 +done
560 +
561 +[[ ${NEED_ACTION} == "yes" ]] && usage 1
562 +[[ ${DEBUG} == "yes" ]] && set -x
563 +
564 +# All operations need to know the current HOST to figure out
565 +# what is a native target and what is a cross target
566 +set_HOST
567 +
568 +# All operations need to know the profile the user wants
569 +case ${DOIT} in
570 +switch_profile|switch_linker_*)
571 + # decode user's profile choice
572 + x=${UARG:-$(TARGET=${HOST} set_current_profile)}
573 + PROFILE=""
574 + if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
575 + # User gave us a # representing the profile
576 + i=1
577 + for y in "${ENV_D}"/* ; do
578 + [[ ${y/config-} != ${y} ]] && continue
579 +
580 + if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
581 + PROFILE=${y##*/}
582 + break
583 + fi
584 + ((++i))
585 + done
586 + fi
587 +
588 + if [[ -z ${PROFILE} ]] ; then
589 + # User gave us a full HOST-ver
590 + x=${x##*/}
591 + if [[ -f ${ENV_D}/${x} ]] ; then
592 + # Valid HOST-ver yeah!
593 + PROFILE=${x}
594 + else
595 + # Not a valid HOST-ver ...
596 + if [[ ! -f ${ENV_D}/config-${x} ]] ; then
597 + # Maybe they just gave us a ver ...
598 + if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
599 + x=${HOST}-${x}
600 + else
601 + die "could not locate '$x' in '${ENV_D}/'!"
602 + fi
603 + PROFILE=${x}
604 + else
605 + # Maybe they just gave us a target ... pick active profile
606 + PROFILE=$(TARGET=${x} set_current_profile)
607 + fi
608 + fi
609 + fi
610 + ;;
611 +*)
612 + # lookup current profile as the user gave us a target
613 + PROFILE=$(TARGET=${UARG:-${HOST}} set_current_profile) || exit 1
614 + ;;
615 +esac
616 +
617 +eval ${DOIT}
618 +
619 +# vim:ts=4