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