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