/[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.101
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.101 2006/01/01 01:14:59 swegener 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}
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 "$@"; }
327 345
328# Depriciated, use test-flags() 346# Depriciated, use test-flags()
329test_flag() { 347test_flag() {
348 addwrite "/dev/stderr"
330 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr 349 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr
331 350
332 test-flags "$@" 351 test-flags-CC "$@"
333} 352}
334 353
335test_version_info() { 354test_version_info() {
336 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then 355 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
337 return 0 356 return 0
371 return 1 390 return 1
372} 391}
373 392
374# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs 393# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs
375has_hardened() { 394has_hardened() {
395 addwrite "/dev/stderr"
376 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \ 396 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \
377 >/dev/stderr 397 >/dev/stderr
378 398
379 test_version_info Hardened && return 0 399 test_version_info Hardened && return 0
380 # The specs file wont exist unless gcc has GCC_SPECS support 400 # The specs file wont exist unless gcc has GCC_SPECS support
381 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]] 401 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
382} 402}
383 403
384# DEPRECATED - use gcc-specs-pie from toolchain-funcs 404# DEPRECATED - use gcc-specs-pie from toolchain-funcs
385# indicate whether PIC is set 405# indicate whether PIC is set
386has_pic() { 406has_pic() {
407 addwrite "/dev/stderr"
387 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr 408 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr
388 409
389 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \ 410 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
390 ${CFLAGS/-fpic} != ${CFLAGS} || \ 411 ${CFLAGS/-fpic} != ${CFLAGS} || \
391 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 412 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
392} 413}
393 414
394# DEPRECATED - use gcc-specs-pie from toolchain-funcs 415# DEPRECATED - use gcc-specs-pie from toolchain-funcs
395# indicate whether PIE is set 416# indicate whether PIE is set
396has_pie() { 417has_pie() {
418 addwrite "/dev/stderr"
397 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr 419 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr
398 420
399 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \ 421 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
400 ${CFLAGS/-fpie} != ${CFLAGS} || \ 422 ${CFLAGS/-fpie} != ${CFLAGS} || \
401 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \ 423 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \
402 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
403 # test PIC while waiting for specs to be updated to generate __PIE__ 425 # test PIC while waiting for specs to be updated to generate __PIE__
404} 426}
405 427
406# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 428# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
407# indicate whether code for SSP is being generated for all functions 429# indicate whether code for SSP is being generated for all functions
408has_ssp_all() { 430has_ssp_all() {
431 addwrite "/dev/stderr"
409 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >/dev/stderr 432 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
410 433
411 # note; this matches only -fstack-protector-all 434 # note; this matches only -fstack-protector-all
412 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \ 435 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
413 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \ 436 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
414 gcc-specs-ssp 437 gcc-specs-ssp
415} 438}
416 439
417# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 440# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
418# indicate whether code for SSP is being generated 441# indicate whether code for SSP is being generated
419has_ssp() { 442has_ssp() {
443 addwrite "/dev/stderr"
420 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr 444 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
421 445
422 # note; this matches both -fstack-protector and -fstack-protector-all 446 # note; this matches both -fstack-protector and -fstack-protector-all
423 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \ 447 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \ 448 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
425 gcc-specs-ssp 449 gcc-specs-ssp
426} 450}
428has_m64() { 452has_m64() {
429 # this doesnt test if the flag is accepted, it tests if the flag 453 # 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! 454 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
431 # please dont replace this function with test_flag in some future 455 # please dont replace this function with test_flag in some future
432 # clean-up! 456 # clean-up!
433 457
434 local temp="$(emktemp)" 458 local temp="$(emktemp)"
435 echo "int main() { return(0); }" > "${temp}".c 459 echo "int main() { return(0); }" > "${temp}".c
436 MY_CC=$(tc-getCC) 460 MY_CC=$(tc-getCC)
437 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 461 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
438 local ret=$? 462 local ret=$?
458 [[ ${ret} != 1 ]] && return 0 482 [[ ${ret} != 1 ]] && return 0
459 return 1 483 return 1
460} 484}
461 485
462replace-sparc64-flags() { 486replace-sparc64-flags() {
463 local SPARC64_CPUS="ultrasparc v9" 487 local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
464 488
465 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 489 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
466 for x in ${SPARC64_CPUS}; do 490 for x in ${SPARC64_CPUS}; do
467 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 491 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
468 done 492 done

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

  ViewVC Help
Powered by ViewVC 1.1.20