/[gentoo-alt]/trunk/toolchain-prefix-wrapper/binutils-config.in
Gentoo

Contents of /trunk/toolchain-prefix-wrapper/binutils-config.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1601 - (show annotations) (download)
Mon Feb 4 17:56:28 2008 UTC (6 years, 7 months ago) by haubi
File MIME type: text/plain
File size: 15768 byte(s)
set BINPATH into PATH during binutils-config to allow finding new ld,
the old one may be unmerged already (native only).

1 #! @GENTOO_PORTAGE_EPREFIX@/bin/bash
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-1.9,v 1.10 2007/05/06 09:04:01 vapier Exp $
5
6 # Format of /etc/env.d/binutils/:
7 # config-TARGET: CURRENT=version for TARGET
8 # TARGET-VER: has a TARGET and VER variable
9
10 VERSION="@VERSION@"
11 BPREFIX="@GENTOO_PORTAGE_EPREFIX@"
12 CFLAGS="@CFLAGS@"
13 BUILD_CC="@CC@"
14 [[ -z ${EPREFIX} ]] && EPREFIX=${BPREFIX}
15
16 [[ -z ${ROOT} ]] && ROOT="/"
17 [[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
18 EROOT="${ROOT%/}${EPREFIX}/"
19 export ROOT EPREFIX
20
21 cd "${EROOT}"
22
23 trap ":" INT QUIT TSTP
24
25 argv0=${0##*/}
26 source "${BPREFIX}"/etc/init.d/functions.sh || {
27 echo "${argv0}: Could not source ${BPREFIX}/etc/init.d/functions.sh!" 1>&2
28 exit 1
29 }
30 esyslog() { :; }
31 umask 022
32
33 usage() {
34 cat << USAGE_END
35
36 Usage: ${HILITE}binutils-config${NORMAL} ${GOOD}[options]${NORMAL} ${BRACKET}[binutils profile]${NORMAL}
37
38 ${HILITE}General Options:${NORMAL}
39 ${GOOD}-B, --get-bin-path${NORMAL} Print current linker bin path
40 ${GOOD}-c, --get-current-profile${NORMAL} Print current profile
41 ${GOOD}-l, --list-profiles${NORMAL} Print a list of available profiles
42 ${GOOD}-u, --uninstall${NORMAL} Remove all signs of specified target
43 ${GOOD}-d, --debug${NORMAL} Execute with debug output
44
45 ${HILITE}Arch Specific Cruft:${NORMAL}
46 ${GOOD}--amd64${NORMAL} Install extra amd64 links (x86_64)
47 ${GOOD}--arm${NORMAL} Install extra arm links (arm/armeb)
48 ${GOOD}--mips${NORMAL} Install extra mips links (mips/mipsel)
49 ${GOOD}--x86${NORMAL} Install extra x86 links (i[3-6]86)
50
51 Profile names are of the form: ${BRACKET}<CTARGET>-<binutils version>${NORMAL}
52 For example: ${BRACKET}i686-pc-linux-gnu-2.15.92.0.2${NORMAL}
53
54 For more info, please see ${HILITE}binutils-config${NORMAL}(8).
55 USAGE_END
56 }
57
58 switch_profile() {
59 unset TARGET VER LIBPATH FAKE_TARGETS
60 source "${ENV_D}/${PROFILE}"
61 if [[ -z ${TARGET} ]] ; then
62 eerror "${PROFILE} is invalid (no \$TARGET defined) :("
63 return 1
64 fi
65 if [[ -z ${VER} ]] ; then
66 eerror "${PROFILE} is invalid (no \$VER defined) :("
67 return 1
68 fi
69
70 #
71 # Older installs don't have 'FAKE_TARGETS' defined, so lets
72 # update these env.d entries so that we don't force the poor
73 # user to re-emerge their binutils just for 1 envvar :/
74 #
75 if [[ ${FAKE_TARGETS-poor user} == "poor user" ]] ; then
76 local targ=${TARGET/-*}
77 local FAKE_TARGETS=${TARGET}
78 case ${targ} in
79 mips|powerpc|sparc)
80 FAKE_TARGETS="${FAKE_TARGETS} ${TARGET/-/64-}";;
81 mips64|powerpc64|sparc64)
82 FAKE_TARGETS="${FAKE_TARGETS} ${TARGET/64-/-}";;
83 esac
84 echo "FAKE_TARGETS=\"${FAKE_TARGETS}\"" >> "${ENV_D}/${PROFILE}"
85 fi
86 local fake_targ_append="${TARGET#*-}"
87 FAKE_TARGETS="${FAKE_TARGETS} ${FAKE_TARGETS_USER// /-${fake_targ_append} }"
88
89 ebegin "Switching to ${PROFILE}"
90
91 # Find the bin wrapper
92 local wrapper
93 for wrapper in lib lib64 lib32 ; do
94 wrapper="${EROOT}usr/${wrapper}/misc/binutils-config-${VERSION}"
95 [[ -e ${wrapper}/libbinutils-config.a ]] && break
96 done
97
98 #
99 # Generate binary symlinks
100 # On systems that do 32bit/64bit, we need to fake an
101 # extra set of binary names (${FAKE_TARGETS})
102 #
103 BINPATH=""
104 BINPATH_LINKS=""
105 if [[ ${TARGET} != ${HOST} ]] ; then
106 #
107 # Newer paths: /usr/${HOST}/${TARGET}/...
108 # Older paths: /usr/${TARGET}/...
109 #
110 if [[ -d ${EROOT}usr/${HOST}/${TARGET}/binutils-bin/${VER} ]] ; then
111 BINPATH=usr/${HOST}/${TARGET}/binutils-bin/${VER}
112 BINPATH_LINKS=usr/libexec/gcc/${TARGET}
113 fi
114 fi
115 if [[ -z ${BINPATH} ]] ; then
116 BINPATH=usr/${TARGET}/binutils-bin/${VER}
117 BINPATH_LINKS=usr/${TARGET}/bin
118 fi
119 cd "${EROOT}${BINPATH}" || exit 1
120 mkdir -p "${EROOT}${BINPATH_LINKS}" "${EROOT}usr/bin"
121 for x in * ; do
122 case ${x} in
123 ld|ld64)
124 # remove symlink first if exists, to avoid overwriting
125 # the target in the cp that follows
126 local oldumask=$(umask)
127 umask 077
128 local ctargetfile="${TMPDIR:-${BPREFIX}/tmp}"/ctarget-$$.c
129 rm -f "${ctargetfile}"
130 (
131 plugins=
132 echo "#include <ldplugin.h>"
133 echo "char const *CTARGET=\"${TARGET}\";"
134 if [[ ${TARGET} != ${HOST} ]]; then
135 # cross linker
136 plugins="${plugins} gnu"
137 # allow debugging any plugin
138 [[ -z ${LDPLUGINS} ]] || plugins=${LDPLUGINS}
139 else
140 local ldversion=$("${EROOT}${BINPATH}/${x}" --version 2>/dev/null)
141 if [[ $? -eq 0 && ${ldversion} == *GNU* ]]; then
142 plugins="${plugins} gnu"
143 else
144 case ${TARGET} in
145 *-darwin*) plugins="${plugins} darwin" ;;
146 *-aix*) plugins="${plugins} aix" ;;
147 *-hpux*) plugins="${plugins} hpux" ;;
148 *-linux* | *-solaris*) plugins="${plugins} gnu" ;;
149 *) eerror "unknown platform ${CTARGET}"
150 exit 1
151 ;;
152 esac
153 fi
154 fi
155 for plugin in ${plugins}; do
156 echo "#include <${plugin}plugin.h>"
157 done
158 echo "LdPluginFct const* LDPLUGINS() {"
159 echo " static const LdPluginFct plugins[] = {"
160 for plugin in ${plugins}; do
161 echo " ${plugin}plugin,"
162 done
163 echo " 0 };"
164 echo " return plugins; };"
165 echo -n "int DEBUG(void) { return "
166 [[ ${DEBUG} == yes ]] && echo "1; }" || echo "0; }"
167 ) > "${ctargetfile}" || return 1
168 umask ${oldumask} || return 1
169 local cc=$(type -p "${CC}")
170 [[ -z ${cc} ]] && set_BUILD
171 [[ -z ${cc} ]] && [[ ${HOST} == ${BUILD} ]] && cc=$(type -p "${BUILD_CC}")
172 [[ -z ${cc} ]] && cc=$(type -p "${HOST}-gcc")
173 [[ -z ${cc} ]] && cc=$(type -p "${HOST}-cc")
174 if [[ -z ${cc} && ${HOST} == ${BUILD} ]]; then
175 [[ -z ${cc} ]] && cc=$(type -p gcc)
176 [[ -z ${cc} ]] && cc=$(type -p cc)
177 fi
178 if [[ -z ${cc} ]]; then
179 echo -n "Cannot find compiler for ${HOST} (try setting CC)"
180 return 1
181 fi
182 rm -f "${EROOT}${BINPATH_LINKS}/${x}.new" > /dev/null || return 1
183 if [[ -z ${ROOT%/} && ${TARGET} == ${HOST} ]]; then
184 # allow current ld-wrapper find the new ld,
185 # since the old one may be unmerged already.
186 export PATH="${EPREFIX}/${BINPATH}:${PATH}"
187 fi
188 "${cc}" -o "${EROOT}${BINPATH_LINKS}/${x}.new" "${ctargetfile}" \
189 "-I${wrapper}" "${wrapper}/libbinutils-config.a" ${CFLAGS} || return 1
190 [[ ${DEBUG} == yes ]] || rm -f "${ctargetfile}" || return 1
191 mv -f "${EROOT}${BINPATH_LINKS}/${x}"{.new,} || return 1
192 touch -r "${EROOT}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
193 ;;
194 *)
195 ln -sf "${EPREFIX}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
196 ;;
197 esac
198 ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${TARGET}-${x} || return 1
199 for fake in ${FAKE_TARGETS} ; do
200 [[ -f ${ENV_D}/config-${fake} ]] && continue
201 ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${fake}-${x} || return 1
202 done
203 if [[ ${TARGET} == ${HOST} ]] ; then
204 ln -sf ${TARGET}-${x} "${EROOT}"usr/bin/${x} || return 1
205 fi
206 done
207
208 #
209 # Generate library / ldscripts symlinks
210 #
211 LIBPATH=$(echo "${LIBPATH}" | sed -e "s|^${EPREFIX}/|/|g" )
212 LIBPATH=${LIBPATH:-usr/lib/binutils/${TARGET}/${VER}}
213 cd "${EROOT}${LIBPATH}" || exit 1
214 if [[ ${TARGET} == ${HOST} ]] ; then
215 dstlib="${EROOT}"usr/${HOST}/lib
216 else
217 dstlib="${EROOT}"usr/${HOST}/${TARGET}/lib
218 # Clean out old path
219 rm -rf "${EROOT}"usr/${TARGET}/lib/ldscripts
220 rmdir "${EROOT}"usr/${TARGET}/lib >& /dev/null
221 fi
222 # When upgrading, we need to clean up ldscripts and libs
223 rm -rf "${dstlib}/ldscripts" "${EROOT}${BINPATH_LINKS}"/ldscripts
224 mkdir -p "${dstlib}"
225 ln -sf "${EPREFIX}/${LIBPATH}/ldscripts" "${dstlib}"/ldscripts
226 find -L "${dstlib}" -type l -exec rm {} \;
227 for x in lib* ; do
228 ln -sf "${EPREFIX}/${LIBPATH}/${x}" "${dstlib}/${x}"
229 done
230
231 #
232 # Generate include symlinks
233 #
234 INCPATH=${LIBPATH}/include
235 if [[ -d ${EROOT}${INCPATH} ]] ; then
236 cd "${EROOT}${INCPATH}" || exit 1
237 if [[ ${HOST} == ${TARGET} ]] ; then
238 mkdir -p "${EROOT}usr/include"
239 for x in * ; do
240 ln -sf "${EPREFIX}/${INCPATH}/${x}" "${EROOT}usr/include/${x}"
241 done
242 else
243 # Clean out old path
244 find . -type f -exec rm -f "${EROOT}usr/${TARGET}/usr/include/{}" \;
245 rmdir "${EROOT}usr/${TARGET}/usr/include" >& /dev/null
246 rmdir "${EROOT}usr/${TARGET}/usr" >& /dev/null
247 rmdir "${EROOT}usr/${TARGET}" >& /dev/null
248 fi
249 fi
250
251 #
252 # Make sure proper paths get updated
253 #
254 if [[ ${TARGET} == ${HOST} ]] ; then
255 echo "PATH=${EPREFIX}${BINPATH}" > "${EROOT}"etc/env.d/05binutils
256 echo "ROOTPATH=${EPREFIX}${BINPATH}" >> "${EROOT}"etc/env.d/05binutils
257 DATAPATH="${EPREFIX}"/usr/share/binutils-data/${TARGET}/${VER}
258 [[ -d ${DATAPATH}/man ]] && \
259 echo "MANPATH=${DATAPATH}/man" >> "${EROOT}"etc/env.d/05binutils
260 [[ -d ${DATAPATH}/info ]] && \
261 echo "INFOPATH=${DATAPATH}/info" >> "${EROOT}"etc/env.d/05binutils
262 # hmm, `ld` has this in SEARCH_DIR(), but ld.so does not ...
263 echo "LDPATH=${EPREFIX}/usr/${TARGET}/lib" >> "${EROOT}"etc/env.d/05binutils
264 fi
265
266 eend 0
267
268 echo "CURRENT=${VER}" > "${ENV_D}/config-${TARGET}"
269 echo "FAKE_TARGETS=\"${FAKE_TARGETS}\"" >> "${ENV_D}/config-${TARGET}"
270
271 #
272 # Regen env.d if need/can be
273 #
274 if [[ ${EROOT%/} == ${BPREFIX} ]] && [[ ${TARGET} == ${HOST} ]] ; then
275 env-update
276 echo
277 ewarn "Please remember to run:"
278 echo
279 ewarn " (bash) # source ${EPREFIX}/etc/profile"
280 ewarn "or"
281 ewarn " (tcsh) # source ${EPREFIX}/etc/csh.login"
282 echo
283 fi
284
285 return 0
286 }
287
288 uninstall_target() {
289 if [[ -z ${EPREFIX} && ${TARGET} == ${HOST} ]] ; then
290 eerror "${argv0}: Refusing to uninstall native binutils"
291 exit 1
292 fi
293
294 shopt -s nullglob
295 PROFILE=""
296
297 for PROFILE in "${ENV_D}"/${TARGET}-* ; do
298 ewarn "Removing all signs of ${PROFILE##*/}"
299 rm -f "${ENV_D}"/${PROFILE}
300 done
301 if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
302 eerror "${argv0}: No profiles exist for '${TARGET}'"
303 exit 1
304 fi
305
306 unset FAKE_TARGETS
307 source "${ENV_D}"/config-${TARGET}
308
309 for target in ${TARGET} ${FAKE_TARGETS}; do
310 for x in addr2line ar as c++filt elf2flt flthdr gprof ld ld.real \
311 nm objcopy objdump ranlib readelf size strings strip ; do
312 rm -f "${EROOT}"usr/bin/${target}-${x}
313 rm -f "${EROOT}"usr/{${HOST}/,}${target}/bin/${x}
314 rm -f "${EROOT}"usr/libexec/gcc/${target}/${x}
315 done
316 done
317 for x in ansidecl.h bfd.h bfdlink.h dis-asm.h symcat.h ; do
318 rm -f "${EROOT}"usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
319 done
320 for x in bfd iberty opcodes ; do
321 rm -f "${EROOT}"usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
322 done
323 # Delete broken symlinks
324 local destdir="${EROOT}usr/${HOST}/${TARGET}"
325 rm -f "${destdir}"/lib/ldscripts
326 find -L "${destdir}"/lib -type l -exec rm {} \;
327 rmdir "${destdir}"/lib "${destdir}" 2>/dev/null
328 rmdir "${destdir}"/{bin,include,lib,usr} "${destdir}" 2>/dev/null
329 rmdir "${EROOT}"var/db/pkg/cross-${TARGET} 2>/dev/null
330
331 rm -f "${ENV_D}"/config-${TARGET}
332 rm -f "${ENV_D}"/${TARGET}-*
333 }
334
335 get_bin_path() {
336 if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
337 eerror "${argv0}: No binutils profile is active!"
338 return 1
339 fi
340
341 source "${ENV_D}/config-${PROFILE}"
342
343 if [[ -z ${CURRENT} ]] ; then
344 eerror "${argv0}: No binutils profile is active!"
345 return 1
346 fi
347
348 unset TARGET VER
349 source "${ENV_D}/${PROFILE}-${CURRENT}"
350 if [[ -z ${TARGET} ]] ; then
351 eerror "${PROFILE}-${CURRENT} is invalid (no \$TARGET defined) :("
352 return 1
353 fi
354 if [[ -z ${VER} ]] ; then
355 eerror "${PROFILE}-${CURRENT} is invalid (no \$VER defined) :("
356 return 1
357 fi
358
359 if [[ ${TARGET} == ${HOST} ]]; then
360 echo "${BPREFIX}/usr/${TARGET}/binutils-bin/${VER}"
361 else
362 echo "${BPREFIX}/usr/${HOST}/${TARGET}/binutils-bin/${VER}"
363 fi
364
365 return 0
366 }
367
368 get_current_profile() {
369 if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
370 eerror "${argv0}: No binutils profile is active!"
371 return 1
372 fi
373
374 source "${ENV_D}/config-${PROFILE}"
375
376 if [[ -z ${CURRENT} ]] ; then
377 eerror "${argv0}: No binutils profile is active!"
378 return 1
379 fi
380
381 echo "${PROFILE}-${CURRENT}"
382
383 return 0
384 }
385
386 list_profiles() {
387 local i=1 x
388
389 set_HOST
390
391 if [[ ${EROOT} != ${BPREFIX}/ ]] ; then
392 echo "Using binutils-config info in ${EROOT}"
393 fi
394 target=
395 for x in "${ENV_D}"/* ; do
396 if [[ -f ${x} ]] && [[ ${x##*/} != config-* ]] ; then
397 source "${x}"
398 if [[ ${target} != ${TARGET} ]] ; then
399 [[ -n ${target} ]] && echo
400 target=${TARGET}
401 fi
402
403 x=${x##*/}
404 if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
405 source "${ENV_D}/config-${TARGET}"
406 if [[ ${VER} == ${CURRENT} ]] ; then
407 [[ ${TARGET} == ${HOST} ]] \
408 && x="${x} ${GOOD}*${NORMAL}" \
409 || x="${x} ${HILITE}*${NORMAL}"
410 fi
411 fi
412 echo " [${i}] ${x}"
413 ((++i))
414 fi
415 done
416 }
417
418 set_HOST() {
419 [[ -n ${HOST} ]] && return 0
420
421 if [[ -z ${CHOST} ]] ; then
422 HOST=$(portageq envvar CHOST)
423 else
424 HOST=${CHOST}
425 fi
426 }
427
428 set_BUILD() {
429 [[ -n ${BUILD} ]] && return 0
430
431 if [[ -z ${CBUILD} ]] ; then
432 BUILD=$(env -i "${BPREFIX}"/usr/bin/portageq envvar CBUILD)
433 else
434 BUILD=${CBUILD}
435 fi
436 }
437
438 ENV_D="${EROOT}etc/env.d/binutils"
439
440 DEBUG="no"
441 NEED_ACTION="yes"
442 DOIT="switch_profile"
443 PROFILE=""
444 FAKE_TARGETS_USER=""
445 HOST=""
446
447 while [[ $# -gt 0 ]] ; do
448 x=$1
449 shift
450 case ${x} in
451 -B|--get-bin-path)
452 DOIT="get_bin_path"
453 NEED_ACTION="no"
454 ;;
455 -c|--get-current-profile)
456 if [[ ${NEED_ACTION} == "yes" ]] ; then
457 NEED_ACTION="no"
458 DOIT="get_current_profile"
459 fi
460 ;;
461 -d|--debug)
462 DEBUG="yes"
463 ;;
464 -l|--list-profiles)
465 if [[ ${NEED_ACTION} == "yes" ]] ; then
466 NEED_ACTION="no"
467 DOIT="list_profiles"
468 fi
469 ;;
470 -u|--uninstall)
471 if [[ ${NEED_ACTION} == "yes" ]] ; then
472 NEED_ACTION="no"
473 DOIT="uninstall_target"
474 TARGET=$1
475 shift
476 fi
477 ;;
478 -h|--help)
479 usage
480 exit 0
481 ;;
482 -V|--version)
483 cvsver="$Header: /var/cvsroot/gentoo-x86/sys-devel/binutils-config/files/binutils-config-1.9,v 1.10 2007/05/06 09:04:01 vapier Exp $"
484 cvsver=${cvsver##*binutils-config-}
485 bver=${cvsver%%,v *}
486 cvsver=${cvsver#* }
487 echo "binutils-config-${bver} (r${cvsver%% *})"
488 exit 0
489 ;;
490 --amd64|--arm|--mips|--x86)
491 if [[ ${NEED_ACTION} == "yes" ]] ; then
492 # Make sure we have a space after each target
493 NEED_ACTION="no"
494 [[ -z ${PROFILE} ]] && PROFILE="current"
495 case ${x} in
496 --amd64) FAKE_TARGETS_USER="x86_64 ";;
497 --arm) FAKE_TARGETS_USER="arm armeb ";;
498 --x86) FAKE_TARGETS_USER="i386 i486 i586 i686 ";;
499 --mips) FAKE_TARGETS_USER="mips mips64 mipsel mipsel64 ";;
500 esac
501 fi
502 ;;
503 -*)
504 eerror "${0##*/}: Invalid switch! Try '--help'."
505 exit 1
506 ;;
507 *)
508 if [[ -n ${PROFILE} ]] && [[ ${PROFILE} != "current" ]] ; then
509 eerror "${argv0}: Too many arguments! Run ${argv0} without parameters for help."
510 exit 1
511 fi
512
513 if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then
514 # User gave us a # representing the profile
515 i=1
516 for y in "${ENV_D}"/* ; do
517 [[ ${y/config-} != ${y} ]] && continue
518
519 if [[ -f ${y} ]] && [[ ${x} -eq ${i} ]] ; then
520 PROFILE=${y##*/}
521 NEED_ACTION="no"
522 break
523 fi
524 ((++i))
525 done
526 fi
527
528 if [[ -z ${PROFILE} ]] ; then
529 # User gave us a full HOST-ver
530 x=${x##*/}
531 if [[ ! -f ${ENV_D}/${x} ]] && [[ ! -f ${ENV_D}/config-${x} ]] ; then
532 # Maybe they just gave us a ver ...
533 set_HOST
534 if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
535 x=${HOST}-${x}
536 else
537 eerror "${argv0}: Could not locate '$x' in '${ENV_D}/'!"
538 exit 1
539 fi
540 fi
541 PROFILE=${x}
542 NEED_ACTION="no"
543 fi
544 ;;
545 esac
546 done
547
548 [[ ${NEED_ACTION} == "yes" ]] && usage && exit 1
549 [[ ${DEBUG} == "yes" ]] && { PS4='($LINENO) +'; set -x; }
550
551 [[ ${DOIT} != "list_profiles" ]] && set_HOST
552 [[ -z ${PROFILE} ]] && PROFILE=${HOST}
553 [[ ${PROFILE} == "current" ]] && PROFILE=$(PROFILE=${HOST} get_current_profile)
554 eval ${DOIT}
555
556 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20