/[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 1606 - (show annotations) (download)
Tue Feb 26 09:10:50 2008 UTC (6 years, 8 months ago) by haubi
File MIME type: text/plain
File size: 15548 byte(s)
added interix as known platform
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 ctargetstem="${TMPDIR:-${BPREFIX}/tmp}"/binutils-config-ctarget-$$
129 local plugins=
130 if [[ ${TARGET} != ${HOST} ]]; then
131 # cross linker
132 plugins="${plugins}${plugins:+,}gnu"
133 # allow debugging any plugin
134 [[ -z ${LDPLUGINS} ]] || plugins=${LDPLUGINS}
135 else
136 case ${TARGET} in
137 *-darwin*) plugins="${plugins}${plugins:+,}darwin" ;;
138 *-aix*) plugins="${plugins}${plugins:+,}aix" ;;
139 *-hpux*) plugins="${plugins}${plugins:+,}hpux" ;;
140 *-linux* | *-solaris* | *-interix*) plugins="${plugins}${plugins:+,}gnu" ;;
141 *) eerror "unknown platform ${CTARGET}"
142 exit 1
143 ;;
144 esac
145 fi
146 rm -f "${ctargetstem}".*
147 (
148 echo "#include <binutils-config.h>"
149 echo "char const *CTARGET(void) { return \"${TARGET}\"; }"
150 echo "char const* LDPLUGINS() { return \"${plugins}\"; }"
151 [[ ${DEBUG} == yes ]] \
152 && echo "int DEBUG(void) { return 1; }" \
153 || echo "int DEBUG(void) { return 0; }"
154 ) > "${ctargetstem}".c || return 1
155 umask ${oldumask} || return 1
156 set_BUILD
157 local cc=$(type -p "${CC}")
158 [[ -z ${cc} ]] && cc=$(type -p "${HOST}-gcc")
159 [[ -z ${cc} ]] && cc=$(type -p "${HOST}-cc")
160 if [[ ${HOST} == ${BUILD} ]]; then
161 [[ -z ${cc} ]] && cc=$(type -p "${BUILD_CC}")
162 [[ -z ${cc} ]] && cc=$(type -p gcc)
163 [[ -z ${cc} ]] && cc=$(type -p cc)
164 fi
165 if [[ -z ${cc} ]]; then
166 echo -n "Cannot find compiler for ${HOST} (try setting CC)"
167 return 1
168 fi
169
170 if [[ -z ${ROOT%/} && ${TARGET} == ${HOST} && ${EPREFIX} == ${BPREFIX} ]]; then
171 # builtin ld-wrapper config may be out-of-date,
172 # so configure it by environment.
173 export BINUTILS_CONFIG_LD="${EPREFIX}/${BINPATH}/${x}"
174 export BINUTILS_CONFIG_LDTARGET="${HOST}"
175 export BINUTILS_CONFIG_LDPLUGINS="${plugins}"
176 fi
177 rm -f "${EROOT}${BINPATH_LINKS}/${x}.new" > /dev/null || return 1
178 "${cc}" ${CFLAGS} -o "${EROOT}${BINPATH_LINKS}/${x}.new" \
179 "${ctargetstem}".c "-I${wrapper}" \
180 "${wrapper}/libbinutils-config.a" || return 1
181 [[ ${DEBUG} == yes ]] || rm -f "${ctargetstem}".* || return 1
182 mv -f "${EROOT}${BINPATH_LINKS}/${x}"{.new,} || return 1
183 touch -r "${EROOT}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
184 ;;
185 *)
186 ln -sf "${EPREFIX}/${BINPATH}/${x}" "${EROOT}${BINPATH_LINKS}/${x}" || return 1
187 ;;
188 esac
189 ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${TARGET}-${x} || return 1
190 for fake in ${FAKE_TARGETS} ; do
191 [[ -f ${ENV_D}/config-${fake} ]] && continue
192 ln -sf "${EPREFIX}/${BINPATH_LINKS}/${x}" "${EROOT}"usr/bin/${fake}-${x} || return 1
193 done
194 if [[ ${TARGET} == ${HOST} ]] ; then
195 ln -sf ${TARGET}-${x} "${EROOT}"usr/bin/${x} || return 1
196 fi
197 done
198
199 #
200 # Generate library / ldscripts symlinks
201 #
202 LIBPATH=$(echo "${LIBPATH}" | sed -e "s|^${EPREFIX}/|/|g" )
203 LIBPATH=${LIBPATH:-usr/lib/binutils/${TARGET}/${VER}}
204 cd "${EROOT}${LIBPATH}" || exit 1
205 if [[ ${TARGET} == ${HOST} ]] ; then
206 dstlib="${EROOT}"usr/${HOST}/lib
207 else
208 dstlib="${EROOT}"usr/${HOST}/${TARGET}/lib
209 # Clean out old path
210 rm -rf "${EROOT}"usr/${TARGET}/lib/ldscripts
211 rmdir "${EROOT}"usr/${TARGET}/lib >& /dev/null
212 fi
213 # When upgrading, we need to clean up ldscripts and libs
214 rm -rf "${dstlib}/ldscripts" "${EROOT}${BINPATH_LINKS}"/ldscripts
215 mkdir -p "${dstlib}"
216 ln -sf "${EPREFIX}/${LIBPATH}/ldscripts" "${dstlib}"/ldscripts
217 find -L "${dstlib}" -type l -exec rm {} \;
218 for x in lib* ; do
219 ln -sf "${EPREFIX}/${LIBPATH}/${x}" "${dstlib}/${x}"
220 done
221
222 #
223 # Generate include symlinks
224 #
225 INCPATH=${LIBPATH}/include
226 if [[ -d ${EROOT}${INCPATH} ]] ; then
227 cd "${EROOT}${INCPATH}" || exit 1
228 if [[ ${HOST} == ${TARGET} ]] ; then
229 mkdir -p "${EROOT}usr/include"
230 for x in * ; do
231 ln -sf "${EPREFIX}/${INCPATH}/${x}" "${EROOT}usr/include/${x}"
232 done
233 else
234 # Clean out old path
235 find . -type f -exec rm -f "${EROOT}usr/${TARGET}/usr/include/{}" \;
236 rmdir "${EROOT}usr/${TARGET}/usr/include" >& /dev/null
237 rmdir "${EROOT}usr/${TARGET}/usr" >& /dev/null
238 rmdir "${EROOT}usr/${TARGET}" >& /dev/null
239 fi
240 fi
241
242 #
243 # Make sure proper paths get updated
244 #
245 if [[ ${TARGET} == ${HOST} ]] ; then
246 echo "PATH=${EPREFIX}/${BINPATH}" > "${EROOT}"etc/env.d/05binutils
247 echo "ROOTPATH=${EPREFIX}/${BINPATH}" >> "${EROOT}"etc/env.d/05binutils
248 DATAPATH="${EPREFIX}"/usr/share/binutils-data/${TARGET}/${VER}
249 [[ -d ${DATAPATH}/man ]] && \
250 echo "MANPATH=${DATAPATH}/man" >> "${EROOT}"etc/env.d/05binutils
251 [[ -d ${DATAPATH}/info ]] && \
252 echo "INFOPATH=${DATAPATH}/info" >> "${EROOT}"etc/env.d/05binutils
253 # hmm, `ld` has this in SEARCH_DIR(), but ld.so does not ...
254 echo "LDPATH=${EPREFIX}/usr/${TARGET}/lib" >> "${EROOT}"etc/env.d/05binutils
255 fi
256
257 eend 0
258
259 echo "CURRENT=${VER}" > "${ENV_D}/config-${TARGET}"
260 echo "FAKE_TARGETS=\"${FAKE_TARGETS}\"" >> "${ENV_D}/config-${TARGET}"
261
262 #
263 # Regen env.d if need/can be
264 #
265 if [[ ${EROOT%/} == ${BPREFIX} ]] && [[ ${TARGET} == ${HOST} ]] ; then
266 env-update
267 echo
268 ewarn "Please remember to run:"
269 echo
270 ewarn " (bash) # source ${EPREFIX}/etc/profile"
271 ewarn "or"
272 ewarn " (tcsh) # source ${EPREFIX}/etc/csh.login"
273 echo
274 fi
275
276 return 0
277 }
278
279 uninstall_target() {
280 if [[ -z ${EPREFIX} && ${TARGET} == ${HOST} ]] ; then
281 eerror "${argv0}: Refusing to uninstall native binutils"
282 exit 1
283 fi
284
285 shopt -s nullglob
286 PROFILE=""
287
288 for PROFILE in "${ENV_D}"/${TARGET}-* ; do
289 ewarn "Removing all signs of ${PROFILE##*/}"
290 rm -f "${ENV_D}"/${PROFILE}
291 done
292 if [[ -z ${PROFILE} ]] && [[ ! -e ${ENV_D}/config-${TARGET} ]] ; then
293 eerror "${argv0}: No profiles exist for '${TARGET}'"
294 exit 1
295 fi
296
297 unset FAKE_TARGETS
298 source "${ENV_D}"/config-${TARGET}
299
300 for target in ${TARGET} ${FAKE_TARGETS}; do
301 for x in addr2line ar as c++filt elf2flt flthdr gprof ld ld.real \
302 nm objcopy objdump ranlib readelf size strings strip ; do
303 rm -f "${EROOT}"usr/bin/${target}-${x}
304 rm -f "${EROOT}"usr/{${HOST}/,}${target}/bin/${x}
305 rm -f "${EROOT}"usr/libexec/gcc/${target}/${x}
306 done
307 done
308 for x in ansidecl.h bfd.h bfdlink.h dis-asm.h symcat.h ; do
309 rm -f "${EROOT}"usr/{${HOST}/,}${TARGET}/{usr/,}include/${x}
310 done
311 for x in bfd iberty opcodes ; do
312 rm -f "${EROOT}"usr/${HOST}/${TARGET}/lib/lib${x}{{-*,}.so,.a,.la}
313 done
314 # Delete broken symlinks
315 local destdir="${EROOT}usr/${HOST}/${TARGET}"
316 rm -f "${destdir}"/lib/ldscripts
317 find -L "${destdir}"/lib -type l -exec rm {} \;
318 rmdir "${destdir}"/lib "${destdir}" 2>/dev/null
319 rmdir "${destdir}"/{bin,include,lib,usr} "${destdir}" 2>/dev/null
320 rmdir "${EROOT}"var/db/pkg/cross-${TARGET} 2>/dev/null
321
322 rm -f "${ENV_D}"/config-${TARGET}
323 rm -f "${ENV_D}"/${TARGET}-*
324 }
325
326 get_bin_path() {
327 if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
328 eerror "${argv0}: No binutils profile is active!"
329 return 1
330 fi
331
332 source "${ENV_D}/config-${PROFILE}"
333
334 if [[ -z ${CURRENT} ]] ; then
335 eerror "${argv0}: No binutils profile is active!"
336 return 1
337 fi
338
339 unset TARGET VER
340 source "${ENV_D}/${PROFILE}-${CURRENT}"
341 if [[ -z ${TARGET} ]] ; then
342 eerror "${PROFILE}-${CURRENT} is invalid (no \$TARGET defined) :("
343 return 1
344 fi
345 if [[ -z ${VER} ]] ; then
346 eerror "${PROFILE}-${CURRENT} is invalid (no \$VER defined) :("
347 return 1
348 fi
349
350 if [[ ${TARGET} == ${HOST} ]]; then
351 echo "${BPREFIX}/usr/${TARGET}/binutils-bin/${VER}"
352 else
353 echo "${BPREFIX}/usr/${HOST}/${TARGET}/binutils-bin/${VER}"
354 fi
355
356 return 0
357 }
358
359 get_current_profile() {
360 if [[ ! -f ${ENV_D}/config-${PROFILE} ]] ; then
361 eerror "${argv0}: No binutils profile is active!"
362 return 1
363 fi
364
365 source "${ENV_D}/config-${PROFILE}"
366
367 if [[ -z ${CURRENT} ]] ; then
368 eerror "${argv0}: No binutils profile is active!"
369 return 1
370 fi
371
372 echo "${PROFILE}-${CURRENT}"
373
374 return 0
375 }
376
377 list_profiles() {
378 local i=1 x
379
380 set_HOST
381
382 if [[ ${EROOT} != ${BPREFIX}/ ]] ; then
383 echo "Using binutils-config info in ${EROOT}"
384 fi
385 target=
386 for x in "${ENV_D}"/* ; do
387 if [[ -f ${x} ]] && [[ ${x##*/} != config-* ]] ; then
388 source "${x}"
389 if [[ ${target} != ${TARGET} ]] ; then
390 [[ -n ${target} ]] && echo
391 target=${TARGET}
392 fi
393
394 x=${x##*/}
395 if [[ -e ${ENV_D}/config-${TARGET} ]] ; then
396 source "${ENV_D}/config-${TARGET}"
397 if [[ ${VER} == ${CURRENT} ]] ; then
398 [[ ${TARGET} == ${HOST} ]] \
399 && x="${x} ${GOOD}*${NORMAL}" \
400 || x="${x} ${HILITE}*${NORMAL}"
401 fi
402 fi
403 echo " [${i}] ${x}"
404 ((++i))
405 fi
406 done
407 }
408
409 set_HOST() {
410 [[ -n ${HOST} ]] && return 0
411
412 if [[ -z ${CHOST} ]] ; then
413 HOST=$(portageq envvar CHOST)
414 else
415 HOST=${CHOST}
416 fi
417 }
418
419 set_BUILD() {
420 [[ -n ${BUILD} ]] && return 0
421
422 if [[ -z ${CBUILD} ]] ; then
423 BUILD=$(env -i "${BPREFIX}"/usr/bin/portageq envvar CBUILD)
424 else
425 BUILD=${CBUILD}
426 fi
427 }
428
429 ENV_D="${EROOT}etc/env.d/binutils"
430
431 DEBUG="no"
432 NEED_ACTION="yes"
433 DOIT="switch_profile"
434 PROFILE=""
435 FAKE_TARGETS_USER=""
436 HOST=""
437
438 while [[ $# -gt 0 ]] ; do
439 x=$1
440 shift
441 case ${x} in
442 -B|--get-bin-path)
443 DOIT="get_bin_path"
444 NEED_ACTION="no"
445 ;;
446 -c|--get-current-profile)
447 if [[ ${NEED_ACTION} == "yes" ]] ; then
448 NEED_ACTION="no"
449 DOIT="get_current_profile"
450 fi
451 ;;
452 -d|--debug)
453 DEBUG="yes"
454 ;;
455 -l|--list-profiles)
456 if [[ ${NEED_ACTION} == "yes" ]] ; then
457 NEED_ACTION="no"
458 DOIT="list_profiles"
459 fi
460 ;;
461 -u|--uninstall)
462 if [[ ${NEED_ACTION} == "yes" ]] ; then
463 NEED_ACTION="no"
464 DOIT="uninstall_target"
465 TARGET=$1
466 shift
467 fi
468 ;;
469 -h|--help)
470 usage
471 exit 0
472 ;;
473 -V|--version)
474 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 $"
475 cvsver=${cvsver##*binutils-config-}
476 bver=${cvsver%%,v *}
477 cvsver=${cvsver#* }
478 echo "binutils-config-${bver} (r${cvsver%% *})"
479 exit 0
480 ;;
481 --amd64|--arm|--mips|--x86)
482 if [[ ${NEED_ACTION} == "yes" ]] ; then
483 # Make sure we have a space after each target
484 NEED_ACTION="no"
485 [[ -z ${PROFILE} ]] && PROFILE="current"
486 case ${x} in
487 --amd64) FAKE_TARGETS_USER="x86_64 ";;
488 --arm) FAKE_TARGETS_USER="arm armeb ";;
489 --x86) FAKE_TARGETS_USER="i386 i486 i586 i686 ";;
490 --mips) FAKE_TARGETS_USER="mips mips64 mipsel mipsel64 ";;
491 esac
492 fi
493 ;;
494 -*)
495 eerror "${0##*/}: Invalid switch! Try '--help'."
496 exit 1
497 ;;
498 *)
499 if [[ -n ${PROFILE} ]] && [[ ${PROFILE} != "current" ]] ; then
500 eerror "${argv0}: Too many arguments! Run ${argv0} without parameters for help."
501 exit 1
502 fi
503
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 NEED_ACTION="no"
513 break
514 fi
515 ((++i))
516 done
517 fi
518
519 if [[ -z ${PROFILE} ]] ; then
520 # User gave us a full HOST-ver
521 x=${x##*/}
522 if [[ ! -f ${ENV_D}/${x} ]] && [[ ! -f ${ENV_D}/config-${x} ]] ; then
523 # Maybe they just gave us a ver ...
524 set_HOST
525 if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then
526 x=${HOST}-${x}
527 else
528 eerror "${argv0}: Could not locate '$x' in '${ENV_D}/'!"
529 exit 1
530 fi
531 fi
532 PROFILE=${x}
533 NEED_ACTION="no"
534 fi
535 ;;
536 esac
537 done
538
539 [[ ${NEED_ACTION} == "yes" ]] && usage && exit 1
540 [[ ${DEBUG} == "yes" ]] && { PS4='($LINENO) +'; set -x; }
541
542 [[ ${DOIT} != "list_profiles" ]] && set_HOST
543 [[ -z ${PROFILE} ]] && PROFILE=${HOST}
544 [[ ${PROFILE} == "current" ]] && PROFILE=$(PROFILE=${HOST} get_current_profile)
545 eval ${DOIT}
546
547 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20