/[gentoo-x86]/sys-devel/gcc-config/files/gcc-config-1.4.1
Gentoo

Contents of /sys-devel/gcc-config/files/gcc-config-1.4.1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Wed Dec 7 05:42:19 2011 UTC (3 years, 3 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +4 -4 lines
Fix multilib support with @GENTOO_LIBDIR@.

(Portage version: 2.2.0_alpha79/cvs/Linux x86_64)

1 #!/bin/bash
2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/sys-devel/gcc-config/files/gcc-config-1.4.1,v 1.11 2011/03/07 12:48:15 vapier Exp $
5
6 trap ":" INT QUIT TSTP
7
8 argv0=${0##*/}
9 source /etc/init.d/functions.sh || {
10 echo "${argv0}: Could not source /etc/init.d/functions.sh!"
11 exit 1
12 }
13 esyslog() { :; }
14 umask 022
15
16 # *BSD are plain stupid ... copy a GNU extension but don't just copy it,
17 # change it so it works differently. Wish Darwin did selective evolution
18 # on software developers.
19 SED=$(type -P gsed)
20 SED=${SED:-$(type -P sed)}
21
22 GENTOO_LIBDIR="@GENTOO_LIBDIR@"
23 [[ ${GENTOO_LIBDIR} == @*@ ]] && GENTOO_LIBDIR="lib"
24
25 usage() {
26 cat << "USAGE_END"
27 Usage: gcc-config [options] [CC Profile]
28 Change the current cc/gcc profile, or give info about profiles.
29
30 Options:
31 -C, --nocolor Disable color output
32 -O, --use-old Use the old profile if one was selected.
33 -f, --force Make sure all config files are regenerated.
34 -P, --use-portage-chost Only set to given profile if its CHOST is the
35 same as that set for portage in /etc/make.conf
36 (or one of other portage config files...).
37 -c, --get-current-profile Print current used gcc profile.
38 -l, --list-profiles Print a list of available profiles.
39 -S, --split-profile Split profiles into their components
40 -E, --print-environ Print environment that can be used to setup the
41 current gcc profile, or a specified one.
42 -B, --get-bin-path Print path where binaries of the given/current
43 profile are located.
44 -L, --get-lib-path Print path where libraries of the given/current
45 profile are located.
46 -X, --get-stdcxx-incdir Print path where g++ include files of the
47 given/current profile are located.
48
49 Profile names are of the form: <CHOST>-<gcc version>
50 For example: i686-pc-linux-gnu-3.2.1
51 USAGE_END
52 exit $1
53 }
54 [[ $# -lt 1 ]] && usage 1
55
56 try_real_hard_to_find_CHOST() {
57 #
58 # First we read make.conf
59 #
60
61 local varname=${1:-CHOST}
62 local conf=${ROOT}/etc/make.conf
63 local ret=$(source "${conf}" 2>/dev/null ; echo ${!varname})
64 if [[ -z ${ret} ]] ; then
65 # newer portage supports spaces between the var and =
66 # CHOST = "this-is-retarded"
67 ret=$(eval $(
68 sed -n \
69 -e 's:[[:space:]]::g' \
70 -e "/^${varname}=/p" \
71 "${conf}"
72 ) ; echo ${!varname}
73 )
74 fi
75
76 if [[ -n ${ret} ]] ; then
77 echo ${ret}
78 return 0
79 fi
80
81 #
82 # Then we try /etc/env.d/gcc/config-${CTARGET}
83 #
84 if [[ -s ${ROOT}/etc/env.d/gcc/config-${CTARGET} ]] ; then
85 ret=$(split_gcc_ver $(eval $(<"${ROOT}"/etc/env.d/gcc/config-${CTARGET}) ; echo ${CURRENT}))
86 echo ${ret% *}
87 fi
88 }
89
90 get_real_chost() {
91 [[ -n ${REAL_CHOST} ]] && return 0
92
93 # shortcut for switching compilers in a cross chroot
94 if [[ -n ${CHOST} && ${ROOT} != "/" ]] ; then
95 REAL_CHOST=${CHOST}
96 return 0
97 fi
98
99 # make sure portage isnt broken
100 if python -V &>/dev/null ; then
101 export REAL_CHOST=$(env -i portageq envvar CHOST 2>/dev/null)
102 else
103 ewarn "Python seems to be broken, attempting to locate CHOST ourselves ..."
104 export REAL_CHOST=$(try_real_hard_to_find_CHOST)
105 fi
106
107 if [[ -z ${REAL_CHOST} ]] ; then
108 eerror "${argv0}: Could not get portage CHOST!"
109 eerror "${argv0}: You should verify that CHOST is set in one of these places:"
110 eerror "${argv0}: - ${ROOT}/etc/make.conf"
111 eerror "${argv0}: - active environment"
112 exit 1
113 fi
114 }
115
116 is_cross_compiler() {
117 get_real_chost
118 [[ ${CC_COMP/${REAL_CHOST}} == ${CC_COMP} ]]
119 }
120
121 # bool files_exists(search_path, files)
122 # Return shell true if the specified files exist.
123 # Files with relative paths are searched for in search_path.
124 # Both lists are : delimited.
125 files_exist() {
126 local p f ret old_IFS
127 local paths=$1 files=$2
128
129 old_IFS=${IFS}
130 export IFS=":"
131
132 ret=0
133 for f in ${files} ; do
134 if [[ ${f} == /* ]] ; then
135 [[ ! -f ${f} ]] && ret=1 && break
136 else
137 # make sure the file exists in at least
138 # one of the specified paths
139 ret=1
140 for p in ${paths} ; do
141 [[ -f ${p}/${f} ]] && ret=0 && break
142 done
143 [[ ${ret} == 1 ]] && break
144 fi
145 done
146
147 export IFS=${old_IFS}
148 if [[ ${ret} == 1 ]] ; then
149 ewarn "Could not locate '${f}' in '${paths}'"
150 fi
151 return ${ret}
152 }
153
154 switch_profile() {
155 local MY_LDPATH=
156 local GCC_PROFILES=
157 local OLD_CC_COMP=
158 local GCC_PATH=
159
160 if [[ $(id -u) != "0" ]] ; then
161 eerror "${argv0}: Must be root."
162 exit 1
163 fi
164
165 if is_cross_compiler ; then
166 ebegin "Switching cross-compiler to ${CC_COMP}"
167 else
168 ebegin "Switching native-compiler to ${CC_COMP}"
169 fi
170
171 if ! is_cross_compiler ; then
172 # Order our profiles to have the default first ...
173 # We do this so that we can have them ordered with default
174 # first in /etc/ld.so.conf, as the logical is that all
175 # compilers for default CHOST will be used to compile stuff,
176 # and thus we want all their lib paths in /etc/ld.so.conf ...
177 get_real_chost
178 GCC_PROFILES=$(LC_ALL="C" ls -r ${GCC_ENV_D}/${REAL_CHOST}-*)
179 GCC_PROFILES="${GCC_ENV_D}/${CC_COMP} ${GCC_PROFILES}"
180
181 # Extract all LDPATH's for our CHOST
182 MY_LDPATH=""
183 for x in ${GCC_PROFILES} ; do
184 if [[ -f ${x} ]] ; then
185 LDPATH=$(source "${x}"; echo ${LDPATH})
186
187 # Handle LDPATH's that have multiple directories
188 local old_IFS=${IFS}
189 export IFS=":"
190 local sub_ldpath=
191 for sub_ldpath in ${LDPATH} ; do
192 if [[ -d ${sub_ldpath} ]] ; then
193 if [[ ${MY_LDPATH/:${sub_ldpath}} == ${MY_LDPATH} ]] ; then
194 MY_LDPATH="${MY_LDPATH}:${sub_ldpath}"
195 fi
196 fi
197 done
198 export IFS=${old_IFS}
199 fi
200 done
201 MY_LDPATH="${MY_LDPATH:1}" # trim leading :
202 fi
203
204 # Translate old PATH/ROOTPATH to GCC_PATH
205 cp -p "${GCC_ENV_D}/${CC_COMP}" "${GCC_ENV_D}/${CC_COMP}.gcc-config-ref" || return 1
206 GCC_PATH=$(
207 unset GCC_PATH PATH ROOTPATH
208 source "${GCC_ENV_D}/${CC_COMP}"
209 echo ${GCC_PATH:-${PATH:-${ROOTPATH}}}
210 )
211 ${SED} -i \
212 -e '/^PATH=/d' \
213 -e '/^ROOTPATH=/d' \
214 -e '/^GCC_PATH=/d' \
215 "${GCC_ENV_D}/${CC_COMP}" || return 1
216 echo "GCC_PATH=\"${GCC_PATH}\"" >> "${GCC_ENV_D}/${CC_COMP}" || return 1
217 touch -r "${GCC_ENV_D}/${CC_COMP}.gcc-config-ref" "${GCC_ENV_D}/${CC_COMP}" || return 1
218 rm -f "${GCC_ENV_D}/${CC_COMP}.gcc-config-ref" || return 1
219
220 # Setup things properly again for this profile
221 unset GCC_SPECS LDPATH
222 source "${GCC_ENV_D}/${CC_COMP}"
223 OLD_CC_COMP=$(get_current_profile)
224
225 # What kind of env.d entry are we going to generate ?
226 if is_cross_compiler ; then
227 echo "PATH=\"${GCC_PATH}\"" > "${ENV_D}/05gcc-${CTARGET}"
228 echo "ROOTPATH=\"${GCC_PATH}\"" >> "${ENV_D}/05gcc-${CTARGET}"
229 echo "CURRENT=${CC_COMP}" > "${GCC_ENV_D}/config-${CTARGET}"
230 else
231 # Pass all by default
232 awk '!/^(STDCXX_INCDIR|LDPATH|CC|CXX|CTARGET|GCCBITS|GCC_SPECS|GCC_PATH)=/ {print $0}' \
233 "${GCC_ENV_D}/${CC_COMP}" > "${ENV_D}/05gcc-${CTARGET}"
234 echo "LDPATH=\"${MY_LDPATH}\"" >> "${ENV_D}/05gcc-${CTARGET}"
235 echo "PATH=\"${GCC_PATH}\"" >> "${ENV_D}/05gcc-${CTARGET}"
236 echo "ROOTPATH=\"${GCC_PATH}\"" >> "${ENV_D}/05gcc-${CTARGET}"
237 if [[ -n ${GCC_SPECS} ]] ; then
238 if files_exist ${MY_LDPATH} ${GCC_SPECS} ; then
239 echo "GCC_SPECS=\"${GCC_SPECS}\"" >> "${ENV_D}/05gcc-${CTARGET}"
240 else
241 echo
242 ewarn "Your GCC spec configurations are broken."
243 ewarn "Please re-emerge gcc."
244 echo
245 fi
246 else
247 # People need to rebuild their gcc or setting GCC_SPECS to
248 # "" will cause issues again :(
249 if [[ ${ROOT} != "/" ]] ; then
250 echo "GCC_SPECS=\"\"" >> "${ENV_D}/05gcc-${CTARGET}"
251 else
252 if ! GCC_SPECS="" /usr/bin/gcc -v &>/dev/null ; then
253 echo
254 ewarn "Your gcc has a bug with GCC_SPECS."
255 ewarn "Please re-emerge gcc."
256 ewarn "http://bugs.gentoo.org/68395"
257 echo
258 else
259 echo "GCC_SPECS=\"\"" >> "${ENV_D}/05gcc-${CTARGET}"
260 fi
261 fi
262 fi
263
264 echo "CURRENT=${CC_COMP}" > "${GCC_ENV_D}/config-${CTARGET}"
265
266 # Help out the gcc wrapper
267 rm -f "${GCC_ENV_D}/NATIVE" "${GCC_ENV_D}/.NATIVE"
268 ln -sf ${CC_COMP} "${GCC_ENV_D}/.NATIVE"
269
270 # Punt old files
271 rm -f "${ENV_D}/05gcc"
272 rm -f "${ENV_D}/05gcc-${CTARGET}"-*
273 rm -f "${GCC_ENV_D}/config"
274 rm -f "${GCC_ENV_D}/config-${CTARGET}"-*
275 fi
276
277 # Find the bin wrapper
278 local wrapper
279 for wrapper in ${GENTOO_LIBDIR} lib lib64 lib32 lib ; do
280 wrapper="${ROOT}usr/${wrapper}/misc/gcc-config"
281 [[ -e ${wrapper} ]] && break
282 done
283
284 # Update the wrappers for this profile
285 for x in {,${CTARGET}-}{cpp,cc,gcc,c++,g++,f77,g77,gcj,gcjh,gcov,gdc,gdmd,gfortran} ; do
286 # Obviously don't want to touch native stuff for cross-compilers
287 [[ ${x} != ${CTARGET}-* ]] && is_cross_compiler && continue
288
289 # Make sure we have no stale wrappers
290 rm -f "${ROOT}/usr/bin/${x}"
291 [[ ${x:${#x}-3} == "gcc" || ${x:${#x}-3} == "g++" ]] \
292 && rm -f "${ROOT}/usr/bin/${x}"{32,64}
293
294 # Only install a wrapper if the binary exists ...
295 # We want to figure out the 'reference file' for each
296 # wrapper (the binary we're 'wrapping') so that we can
297 # sync mtimes together. This makes things like ccache
298 # happy. See Bug #70548 for more info.
299 local ref
300 case ${x} in
301 cc) ref=${ROOT}/${GCC_PATH}/gcc;;
302 f77) ref=${ROOT}/${GCC_PATH}/g77;;
303 *) ref=${ROOT}/${GCC_PATH}/${x};;
304 esac
305 if [[ -x ${ref} ]] ; then
306 cp -f "${wrapper}" "${ROOT}/usr/bin/${x}"
307 touch -r "${ref}" "${ROOT}/usr/bin/${x}"
308
309 # Install 32bit and 64bit wrappers if need be
310 # This should probably get folded back into the wrapper ...
311 if [[ ${x:${#x}-3} == "gcc" ]] || [[ ${x:${#x}-3} == "g++" ]] ; then
312 for bits in ${GCCBITS} ; do
313 cp -f "${wrapper}" "${ROOT}/usr/bin/${x}${bits}"
314 done
315 fi
316 fi
317 done
318 # legacy cruft, make sure we dont leave it laying around #143205
319 rm -f "${ROOT}/usr/bin/${CTARGET}-cc"
320 # Only install cpp if switching to a native one
321 if ! is_cross_compiler && [[ ${CTARGET} != *-solaris* ]] ; then
322 rm -f "${ROOT}/lib/cpp"
323 cp -f "${wrapper}" "${ROOT}/lib/cpp"
324 fi
325
326 # Relocate random crap
327 if ! is_cross_compiler ; then
328 if [[ -e ${ROOT}/usr/${GENTOO_LIBDIR}/pkgconfig/libgcj-${CC_COMP_VERSION}.pc ]] ; then
329 local mver=${CC_COMP_VERSION:0:3}
330 for x in "" "-${mver}" ; do
331 x="${ROOT}/usr/lib/pkgconfig/libgcj${x}.pc"
332 rm -f "${x}"
333 ln -s libgcj-${CC_COMP_VERSION}.pc "${x}"
334 done
335 fi
336 fi
337
338 # We need to make sure that libgcc_s.so / libunwind.so make it into /lib.
339 # On many systems (x86/amd64/etc...), this will probably never matter,
340 # but on other systems (arm/mips/etc...), this is quite critical.
341 # http://bugs.gentoo.org/60190
342 #
343 # The funky move magic is required for proper updating of in-use files.
344 if ! is_cross_compiler ; then
345 # Need to cut out extra paths in multilib case and pray the first path
346 # is the "root" multilib path ... maybe some day change this to use
347 # `gcc -print-file-name` ...
348 LDPATH=${LDPATH%%:*}
349 for multilib in $("${ROOT}/${GCC_PATH}"/gcc -print-multi-lib); do
350 multiarg=${multilib#*;}
351 multiarg=${multiarg/@/-}
352 multilibdir=${multilib%;*}
353 libdir="lib/"$("${ROOT}/${GCC_PATH}"/gcc ${multiarg} -print-multi-os-directory)
354 if mkdir -p "${ROOT}/${libdir}"/.gcc.config.new ; then
355 for gcclib in gcc_s unwind ; do
356 if [[ -n $(ls "${ROOT}/${LDPATH}/${multilibdir}"/lib${gcclib}.so.* 2>/dev/null) ]]; then
357 cp -pP "${ROOT}/${LDPATH}/${multilibdir}"/lib${gcclib}.so.* "${ROOT}/${libdir}"/.gcc.config.new/
358 # no need to sanity remove this as the `mv` should take
359 # care of it. we also need this step to be completly atomic
360 # for systems that have even `mv` linked against libgcc_s.so.
361 # http://bugs.gentoo.org/150257
362 #rm -f "${ROOT}/${libdir}"/lib${gcclib}.so*
363 mv -f "${ROOT}/${libdir}"/.gcc.config.new/* "${ROOT}/${libdir}"/
364 fi
365 done
366 rmdir "${ROOT}/${libdir}"/.gcc.config.new
367 fi
368 done
369 unset multilib
370 unset multilibdir
371 unset multiarg
372 unset libdir
373 fi
374
375 if [[ ${ROOT} == "/" ]] && [[ ${OLD_CC_COMP} != ${CC_COMP} || ${FORCE} == "yes" ]] ; then
376 # in case python is broken ...
377 if ! env-update ; then
378 echo ""
379 ewarn "env-update failed to work properly; making sure ld.so.conf paths"
380 ewarn "are setup properly. Please rerun gcc-config with the -f option."
381 echo ""
382 grep -h ^LDPATH= "${ROOT}"/etc/env.d/05gcc-${CTARGET} \
383 | sed -e 's:^LDPATH=::' -e 's:"::g' -e 's|:|\n|g' \
384 >> /etc/ld.so.conf
385 ldconfig
386 fi
387 fi
388
389 eend 0
390
391 if [[ ${ROOT} == "/" ]] && [[ ${OLD_CC_COMP} != ${CC_COMP} ]] ; then
392 echo
393 ewarn "If you intend to use the gcc from the new profile in an already"
394 ewarn "running shell, please remember to do:"
395 echo
396 ewarn " . /etc/profile"
397 echo
398 fi
399
400 return 0
401 }
402
403 get_current_profile() {
404 local conf="${GCC_ENV_D}/config"
405 if [[ ! -f ${conf} ]] ; then
406 conf="${GCC_ENV_D}/config-${CTARGET}"
407 elif [[ -n ${CC_COMP} ]] && is_cross_compiler ; then
408 conf="${conf}-${CC_COMP}"
409 fi
410
411 if [[ ! -f ${conf} ]] ; then
412 eerror "${argv0}: No gcc profile is active!"
413 return 1
414 fi
415
416 CURRENT=$(source "${conf}"; echo ${CURRENT})
417
418 if [[ -z ${CURRENT} ]] ; then
419 eerror "${argv0}: No gcc profile is active!"
420 return 1
421 elif [[ ! -f ${GCC_ENV_D}/${CURRENT} ]] ; then
422 eerror "${argv0}: Active gcc profile is invalid!"
423 return 1
424 fi
425
426 echo "${CURRENT}"
427
428 return 0
429 }
430
431 list_profiles() {
432 local i=0
433 local filter=
434
435 if [[ ${ROOT} != "/" ]] ; then
436 echo "Using gcc-config info in ${ROOT}"
437 fi
438
439 if [[ ! -f ${GCC_ENV_D}/config-${CTARGET} ]] ; then
440 if ! is_cross_compiler && [[ -e ${GCC_ENV_D}/config ]] ; then
441 [[ -w ${GCC_ENV_D}/config ]] && mv ${GCC_ENV_D}/config ${GCC_ENV_D}/config-${CTARGET}
442 else
443 eerror "${argv0}: No gcc profile is active; please select one!"
444 filter=${CTARGET}
445 fi
446 fi
447
448 eval $(grep -s ^CURRENT= "${GCC_ENV_D}"/config-${CTARGET})
449 CURRENT_NATIVE=${CURRENT}
450 local target=
451 for x in "${GCC_ENV_D}"/* ; do
452 if [[ -f ${x} ]] && [[ ${x/\/config} == ${x} ]] ; then
453 CTARGET=$(unset CTARGET; source "${x}"; echo ${CTARGET})
454
455 ((++i))
456
457 [[ -n ${filter} ]] && [[ ${filter} != ${CTARGET:-${REAL_CHOST}} ]] && continue
458
459 if [[ ${target} != ${CTARGET} ]] ; then
460 [[ -n ${target} ]] && echo
461 target=${CTARGET}
462 CTARGET=""
463 fi
464
465 x=${x##*/}
466 if [[ ${x} == ${CURRENT_NATIVE} ]] ; then
467 x="${x} ${GOOD}*${NORMAL}"
468 elif [[ -e ${GCC_ENV_D}/config-${target} ]] ; then
469 source "${GCC_ENV_D}/config-${target}"
470 [[ ${x} == ${CURRENT} ]] && x="${x} ${HILITE}*${NORMAL}"
471 fi
472 echo " [${i}] ${x}"
473 fi
474 done
475 }
476
477 print_environ() {
478 local GCC_PATH=
479 local ENV_CMD=
480 local SET_ELEMENT=
481
482 GCC_PATH=$(source "${GCC_ENV_D}/${CC_COMP}"; echo ${GCC_PATH:-${PATH}})
483
484 case ${SHELL} in
485 */csh|*/tcsh)
486 ENV_CMD="setenv"
487 SET_ELEMENT=" "
488 ;;
489 *)
490 ENV_CMD="export"
491 SET_ELEMENT="="
492 ;;
493 esac
494
495 (
496 PATH=${GCC_PATH}:${PATH}
497 for var in PATH GCC_SPECS ; do
498 echo "${ENV_CMD} ${var}${SET_ELEMENT}\"${!var}\""
499 done
500 )
501 }
502
503 get_bin_path() {
504 if [[ -e ${GCC_ENV_D}/${CC_COMP} ]] ; then
505 (
506 unset PATH GCC_PATH
507 source "${GCC_ENV_D}/${CC_COMP}"
508 echo "${GCC_PATH:-${PATH}}"
509 )
510 else
511 echo "no-config"
512 echo "${GCC_ENV_D}/${CC_COMP} doesnt exist" 1>&2
513 fi
514
515 return 0
516 }
517
518 get_lib_path() {
519 if [[ -e ${GCC_ENV_D}/${CC_COMP} ]] ; then
520 (
521 unset LDPATH
522 source "${GCC_ENV_D}/${CC_COMP}"
523 echo "${LDPATH}"
524 )
525 else
526 echo "no-config"
527 echo "${GCC_ENV_D}/${CC_COMP} doesnt exist" 1>&2
528 fi
529
530 return 0
531 }
532
533 get_stdcxx_incdir() {
534 # XXX: we should prob scrub this ...
535 if [[ -e ${GCC_ENV_D}/${CC_COMP} ]] ; then
536 (
537 unset LDPATH STDCXX_INCDIR
538 source "${GCC_ENV_D}/${CC_COMP}"
539 echo "${LDPATH}/include/${STDCXX_INCDIR}"
540 )
541 else
542 echo "no-config"
543 echo "${GCC_ENV_D}/${CC_COMP} doesnt exist" 1>&2
544 fi
545
546 return 0
547 }
548
549 split_gcc_ver() {
550 # Split up the gcc profile into components:
551 # TARGET-VER[-specs] -> TARGET VER [specs]
552 # arm-linux-3.3.6 -> arm-linux 3.3.6
553 # x86_64-linux-4.0.1-pre1234 -> x86_64-linux 4.0.1-pre1234
554 # sh-linux-3.4.4-hardened -> sh-linux 3.4.4 hardened
555 #
556 # So below we will start at the end and run a small state machine ...
557 # specs [3]
558 # accept everything
559 # specs -> version transition [3->2]
560 # when we find a version component
561 # version [2]
562 # accept only version components (see the regex)
563 # version -> target transition [2->1]
564 # when we hit a non version component
565 # target [1]
566 # accept everything we have left
567 #
568 echo "$@" | awk -F- '
569 function pushit(onme, pushee) {
570 return (onme == "" ? pushee : pushee"-"onme);
571 }
572 {
573 state=3
574 targ=""
575 ver=""
576 spec=""
577 for (i=NF; i > 0; --i) {
578 if (state >= 2) {
579 if ($i ~ /^(alpha|beta|pre|rc|p)?[[:digit:].]+$/) {
580 ver=pushit(ver, $i)
581 state=2
582 } else if (state == 3)
583 spec=pushit(spec, $i)
584 else
585 state=1
586 }
587 if (state == 1)
588 targ = pushit(targ, $i)
589 }
590
591 if (targ == "") {
592 if (ver == "") {
593 ver=spec
594 spec=""
595 }
596 targ=ver
597 ver=""
598 }
599 print targ " " ver (spec != "" ? " " spec : "")
600 }'
601 }
602 chop_gcc_ver_spec() {
603 local splitTED=$(split_gcc_ver $@) # target ver spec
604 splitTED=${splitTED#* } # ver spec
605 echo ${splitTED/ /-} # ver-spec
606 }
607
608 SET_X=false
609 NEED_ACTION="yes"
610 DOIT="switch_profile"
611 CHECK_CHOST="no"
612 FORCE="no"
613
614 CC_COMP=
615 [[ -z ${ROOT} ]] && ROOT="/"
616 [[ ${ROOT:0-1} != "/" ]] && ROOT="${ROOT}/"
617 ENV_D="${ROOT}etc/env.d"
618 GCC_ENV_D="${ENV_D}/gcc"
619
620 for x in "$@" ; do
621 case "${x}" in
622 # Only use specified compiler if one is not already selected.
623 -O|--use-old)
624 CTARGET=${CTARGET:-$(try_real_hard_to_find_CHOST)}
625 if get_current_profile &>/dev/null ; then
626 CC_COMP=$(get_current_profile)
627 else
628 eerror "No profile selected, unable to utilize --use-old"
629 exit 1
630 fi
631 ;;
632 -f|--force)
633 FORCE="yes"
634 ;;
635 -P|--use-portage-chost)
636 CHECK_CHOST="yes"
637 ;;
638 -c|--get-current-profile)
639 if [[ ${NEED_ACTION} == "yes" ]] ; then
640 NEED_ACTION="no"
641 DOIT="get_current_profile"
642 fi
643 ;;
644 -l|--list-profiles)
645 if [[ ${NEED_ACTION} == "yes" ]] ; then
646 NEED_ACTION="no"
647 DOIT="list_profiles"
648 fi
649 ;;
650 -S|--split-profile)
651 if [[ ( $1 != "-S" && $1 != "--split-profile" ) || $# -eq 1 ]] ; then
652 usage 1
653 fi
654 shift # push -S out
655 for x in "$@" ; do
656 split_gcc_ver ${x}
657 done
658 exit 0
659 ;;
660 -E|--print-environ)
661 if [[ ${NEED_ACTION} == "yes" ]] ; then
662 NEED_ACTION="no"
663 DOIT="print_environ"
664 fi
665 ;;
666 -B|--get-bin-path)
667 if [[ ${NEED_ACTION} == "yes" ]] ; then
668 NEED_ACTION="no"
669 DOIT="get_bin_path"
670 fi
671 ;;
672 -L|--get-lib-path)
673 if [[ ${NEED_ACTION} == "yes" ]] ; then
674 NEED_ACTION="no"
675 DOIT="get_lib_path"
676 fi
677 ;;
678 -X|--get-stdcxx-incdir)
679 if [[ ${NEED_ACTION} == "yes" ]] ; then
680 NEED_ACTION="no"
681 DOIT="get_stdcxx_incdir"
682 fi
683 ;;
684 -x|--debug)
685 SET_X=true
686 ;;
687 -C|--nocolor)
688 # nothing to do; functions.sh parsed this for us
689 ;;
690 -h|--help)
691 usage 0
692 ;;
693 -V|--version)
694 rcsfile="$RCSfile: gcc-config-1.4.1,v $"
695 rcsfile=${rcsfile#: }
696 rcsfile=${rcsfile%,v*}
697 cvsrev="$Revision: 1.11 $"
698 cvsrev=${cvsrev#: }
699 cvsdate="$Date: 2011/03/07 12:48:15 $"
700 cvsdate=${cvsdate#: }
701 echo "${rcsfile} (r${cvsrev% *} @ ${cvsdate% *})"
702 exit 0
703 ;;
704 -*)
705 eerror "${argv0}: Invalid switch! Run ${argv0} without parameters for help."
706 exit 1
707 ;;
708 *)
709 ${SET_X} && set -x
710 if [[ -z ${CC_COMP} ]] ; then
711 if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
712 # User gave us a # representing the profile
713 i=1
714 for y in "${GCC_ENV_D}"/* ; do
715 [[ -f ${y} ]] || continue
716 [[ ${y/\/config} != ${y} ]] && continue
717
718 if [[ -f ${y} ]] && [[ ${x} == ${i} ]] ; then
719 CC_COMP=${y##*/}
720 break
721 fi
722 ((++i))
723 done
724 else
725 # User gave us a full HOST-gccver
726 x=${x##*/}
727 if [[ ${DOIT} == "get_current_profile" && -z $(ls "${GCC_ENV_D}"/${x}-* 2>/dev/null) ]] || \
728 [[ ${DOIT} != "get_current_profile" && ! -f ${GCC_ENV_D}/${x} ]]
729 then
730 # Maybe they just gave us a gccver ...
731 get_real_chost
732 if [[ -f ${GCC_ENV_D}/${REAL_CHOST}-${x} ]] ; then
733 x=${REAL_CHOST}-${x}
734 else
735 eerror "${argv0}: Could not locate '$x' in '${GCC_ENV_D}/' !"
736 exit 1
737 fi
738 fi
739 CC_COMP=${x}
740 fi
741 else
742 eerror "${argv0}: Too many arguments! Run ${argv0} without parameters for help."
743 exit 1
744 fi
745 ;;
746 esac
747 done
748
749 ${SET_X} && set -x
750
751 get_real_chost
752 [[ ${DOIT} == "get_current_profile" ]] \
753 && CTARGET=${CTARGET:-${CC_COMP:-${REAL_CHOST}}} \
754 || CTARGET=${CTARGET:-${REAL_CHOST}}
755
756 if [[ ${DOIT} == "switch_profile" ]] && [[ -z ${CC_COMP} ]] ; then
757 usage 1
758 fi
759
760 if [[ -z ${CC_COMP} ]] ; then
761 CC_COMP=$(get_current_profile)
762 if [[ $? -ne 0 ]] ; then
763 echo "${CC_COMP}"
764 list_profiles
765 exit 1
766 fi
767 fi
768
769 if [[ ${DOIT} != "get_current_profile" ]] ; then
770 GCC_LIB=$(
771 LDPATH=$(source "${GCC_ENV_D}/${CC_COMP}"; echo ${LDPATH})
772 echo ${LDPATH} | awk -F/ '{ print "/"$2"/"$3"/"$4"/" }'
773 )
774
775 CC_COMP_VERSION=$(chop_gcc_ver_spec ${CC_COMP})
776 CC_COMP_TARGET=${CC_COMP%-${CC_COMP_VERSION}*}
777
778 if [[ ! -d ${ROOT}/${GCC_LIB}/${CC_COMP_TARGET}/${CC_COMP_VERSION} ]]; then
779 CC_COMP_VERSION=${CC_COMP_VERSION%-*}
780 fi
781
782 if [[ ! -d ${ROOT}/${GCC_LIB}/${CC_COMP_TARGET}/${CC_COMP_VERSION} ]] || \
783 [[ ! -f ${GCC_ENV_D}/${CC_COMP} ]]
784 then
785 eerror "${argv0}: Profile does not exist or invalid setting for ${GCC_ENV_D}/${CC_COMP}" 1>&2
786 #exit 1
787 fi
788 fi
789
790 if [[ ${CHECK_CHOST} == "yes" ]] ; then
791 # Chosen CHOST are not the same as the real CHOST according to
792 # make.conf, and --use-portage-chost option was given, so do nothing
793 get_real_chost
794 CC_COMP_VERSION=$(chop_gcc_ver_spec ${CC_COMP})
795 CC_COMP_TARGET=${CC_COMP:0:${#CC_COMP}-${#CC_COMP_VERSION}-1}
796 [[ ${CC_COMP_TARGET} != ${REAL_CHOST} ]] && exit 0
797 fi
798
799 eval ${DOIT}
800
801 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20