/[gentoo-x86]/eclass/flag-o-matic.eclass
Gentoo

Diff of /eclass/flag-o-matic.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.96 Revision 1.104
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.96 2005/12/08 12:16:12 azarah Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.104 2006/01/14 10:52:12 kevquinn Exp $
4 4
5 5
6# need access to emktemp() 6# need access to emktemp()
7inherit eutils toolchain-funcs multilib 7inherit eutils toolchain-funcs multilib
8 8
311test-flag-CC() { test-flag-PROG "CC" "$1"; } 311test-flag-CC() { test-flag-PROG "CC" "$1"; }
312 312
313# Returns true if C++ compiler support given flag 313# Returns true if C++ compiler support given flag
314test-flag-CXX() { test-flag-PROG "CXX" "$1"; } 314test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
315 315
316test-flags() { 316test-flags-PROG() {
317 local comp=$1
318 local flags
317 local x 319 local x
318 320
321 shift
322
323 [[ -z ${comp} ]] && \
324 return 1
325
319 for x in "$@" ; do 326 for x in "$@" ; do
320 test-flag-CC "${x}" || return 1 327 test-flag-${comp} "${x}" && flags="${flags} ${x}"
321 done 328 done
322 329
323 echo "$@" 330 echo "${flags}"
324 331
325 return 0 332 # Just bail if we dont have any flags
333 [[ -n ${flags} ]]
326} 334}
327 335
336# Returns (echo's) the given flags supported by the C compiler
337test-flags-CC() { test-flags-PROG "CC" "$@"; }
338
339# Returns (echo's) the given flags supported by the C++ compiler
340test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
341
342# Short-hand that should hopefully work for both C and C++ compiler, but
343# its really only present due to the append-flags() abomination.
344test-flags() { test-flags-CC "$@"; }
345
328# Depriciated, use test-flags() 346# Deprecated, use test-flags()
329test_flag() { 347test_flag() {
330 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr 348 ewarn "test_flag: deprecated, please use test-flags()!" >&2
331 349
332 test-flags "$@" 350 test-flags-CC "$@"
333} 351}
334 352
335test_version_info() { 353test_version_info() {
336 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then 354 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
337 return 0 355 return 0
371 return 1 389 return 1
372} 390}
373 391
374# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs 392# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs
375has_hardened() { 393has_hardened() {
376 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \ 394 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" >&2
377 >/dev/stderr 395
378
379 test_version_info Hardened && return 0 396 test_version_info Hardened && return 0
380 # The specs file wont exist unless gcc has GCC_SPECS support 397 # The specs file wont exist unless gcc has GCC_SPECS support
381 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]] 398 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
382} 399}
383 400
384# DEPRECATED - use gcc-specs-pie from toolchain-funcs 401# DEPRECATED - use gcc-specs-pie from toolchain-funcs
385# indicate whether PIC is set 402# indicate whether PIC is set
386has_pic() { 403has_pic() {
387 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr 404 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >&2
388 405
389 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \ 406 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
390 ${CFLAGS/-fpic} != ${CFLAGS} || \ 407 ${CFLAGS/-fpic} != ${CFLAGS} || \
391 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 408 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
392} 409}
393 410
394# DEPRECATED - use gcc-specs-pie from toolchain-funcs 411# DEPRECATED - use gcc-specs-pie from toolchain-funcs
395# indicate whether PIE is set 412# indicate whether PIE is set
396has_pie() { 413has_pie() {
397 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr 414 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >&2
398 415
399 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \ 416 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
400 ${CFLAGS/-fpie} != ${CFLAGS} || \ 417 ${CFLAGS/-fpie} != ${CFLAGS} || \
401 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \ 418 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \
402 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 419 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
403 # test PIC while waiting for specs to be updated to generate __PIE__ 420 # test PIC while waiting for specs to be updated to generate __PIE__
404} 421}
405 422
406# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 423# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
407# indicate whether code for SSP is being generated for all functions 424# indicate whether code for SSP is being generated for all functions
408has_ssp_all() { 425has_ssp_all() {
409 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >/dev/stderr 426 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >&2
410 427
411 # note; this matches only -fstack-protector-all 428 # note; this matches only -fstack-protector-all
412 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \ 429 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
413 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \ 430 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
414 gcc-specs-ssp 431 gcc-specs-ssp
415} 432}
416 433
417# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 434# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
418# indicate whether code for SSP is being generated 435# indicate whether code for SSP is being generated
419has_ssp() { 436has_ssp() {
420 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr 437 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >&2
421 438
422 # note; this matches both -fstack-protector and -fstack-protector-all 439 # note; this matches both -fstack-protector and -fstack-protector-all
423 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \ 440 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \ 441 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
425 gcc-specs-ssp 442 gcc-specs-ssp
426} 443}
428has_m64() { 445has_m64() {
429 # this doesnt test if the flag is accepted, it tests if the flag 446 # this doesnt test if the flag is accepted, it tests if the flag
430 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 447 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
431 # please dont replace this function with test_flag in some future 448 # please dont replace this function with test_flag in some future
432 # clean-up! 449 # clean-up!
433 450
434 local temp="$(emktemp)" 451 local temp="$(emktemp)"
435 echo "int main() { return(0); }" > "${temp}".c 452 echo "int main() { return(0); }" > "${temp}".c
436 MY_CC=$(tc-getCC) 453 MY_CC=$(tc-getCC)
437 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 454 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
438 local ret=$? 455 local ret=$?
458 [[ ${ret} != 1 ]] && return 0 475 [[ ${ret} != 1 ]] && return 0
459 return 1 476 return 1
460} 477}
461 478
462replace-sparc64-flags() { 479replace-sparc64-flags() {
463 local SPARC64_CPUS="ultrasparc v9" 480 local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
464 481
465 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 482 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
466 for x in ${SPARC64_CPUS}; do 483 for x in ${SPARC64_CPUS}; do
467 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 484 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
468 done 485 done
502 [[ -z ${LDFLAGS// } ]] \ 519 [[ -z ${LDFLAGS// } ]] \
503 && LDFLAGS="" \ 520 && LDFLAGS="" \
504 || LDFLAGS=${LDFLAGS:1:${#LDFLAGS}-2} 521 || LDFLAGS=${LDFLAGS:1:${#LDFLAGS}-2}
505 export LDFLAGS 522 export LDFLAGS
506 return 0 523 return 0
524}
525
526# Turn C style ldflags (-Wl,-foo) into straight ldflags
527raw-ldflags() {
528 local x input="$@"
529 [[ -z ${input} ]] && input=${LDFLAGS}
530 set --
531 for x in ${input} ; do
532 x=${x#-Wl,}
533 set -- "$@" ${x//,/ }
534 done
535 echo "$@"
507} 536}
508 537
509fstack-flags() { 538fstack-flags() {
510 if gcc-specs-ssp; then 539 if gcc-specs-ssp; then
511 [ -z "`is-flag -fno-stack-protector`" ] && 540 [ -z "`is-flag -fno-stack-protector`" ] &&

Legend:
Removed from v.1.96  
changed lines
  Added in v.1.104

  ViewVC Help
Powered by ViewVC 1.1.20