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