/[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.98 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.98 2005/12/09 18:40:11 fmccor 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() {
330 addwrite "/dev/stderr" 348 addwrite "/dev/stderr"
331 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr 349 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr
332 350
333 test-flags "$@" 351 test-flags-CC "$@"
334} 352}
335 353
336test_version_info() { 354test_version_info() {
337 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then 355 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
338 return 0 356 return 0
375# 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
376has_hardened() { 394has_hardened() {
377 addwrite "/dev/stderr" 395 addwrite "/dev/stderr"
378 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \ 396 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \
379 >/dev/stderr 397 >/dev/stderr
380 398
381 test_version_info Hardened && return 0 399 test_version_info Hardened && return 0
382 # The specs file wont exist unless gcc has GCC_SPECS support 400 # The specs file wont exist unless gcc has GCC_SPECS support
383 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]] 401 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
384} 402}
385 403
386# DEPRECATED - use gcc-specs-pie from toolchain-funcs 404# DEPRECATED - use gcc-specs-pie from toolchain-funcs
387# indicate whether PIC is set 405# indicate whether PIC is set
388has_pic() { 406has_pic() {
389 addwrite "/dev/stderr" 407 addwrite "/dev/stderr"
390 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr 408 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr
391 409
392 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \ 410 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
393 ${CFLAGS/-fpic} != ${CFLAGS} || \ 411 ${CFLAGS/-fpic} != ${CFLAGS} || \
394 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 412 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
395} 413}
396 414
397# DEPRECATED - use gcc-specs-pie from toolchain-funcs 415# DEPRECATED - use gcc-specs-pie from toolchain-funcs
398# indicate whether PIE is set 416# indicate whether PIE is set
399has_pie() { 417has_pie() {
400 addwrite "/dev/stderr" 418 addwrite "/dev/stderr"
401 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr 419 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr
402 420
403 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \ 421 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
404 ${CFLAGS/-fpie} != ${CFLAGS} || \ 422 ${CFLAGS/-fpie} != ${CFLAGS} || \
405 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \ 423 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \
406 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] 424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
407 # 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__
410# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 428# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
411# indicate whether code for SSP is being generated for all functions 429# indicate whether code for SSP is being generated for all functions
412has_ssp_all() { 430has_ssp_all() {
413 addwrite "/dev/stderr" 431 addwrite "/dev/stderr"
414 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
415 433
416 # note; this matches only -fstack-protector-all 434 # note; this matches only -fstack-protector-all
417 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \ 435 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
418 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \ 436 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
419 gcc-specs-ssp 437 gcc-specs-ssp
420} 438}
422# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 440# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
423# indicate whether code for SSP is being generated 441# indicate whether code for SSP is being generated
424has_ssp() { 442has_ssp() {
425 addwrite "/dev/stderr" 443 addwrite "/dev/stderr"
426 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr 444 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
427 445
428 # note; this matches both -fstack-protector and -fstack-protector-all 446 # note; this matches both -fstack-protector and -fstack-protector-all
429 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \ 447 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
430 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \ 448 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
431 gcc-specs-ssp 449 gcc-specs-ssp
432} 450}
434has_m64() { 452has_m64() {
435 # 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
436 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 454 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
437 # please dont replace this function with test_flag in some future 455 # please dont replace this function with test_flag in some future
438 # clean-up! 456 # clean-up!
439 457
440 local temp="$(emktemp)" 458 local temp="$(emktemp)"
441 echo "int main() { return(0); }" > "${temp}".c 459 echo "int main() { return(0); }" > "${temp}".c
442 MY_CC=$(tc-getCC) 460 MY_CC=$(tc-getCC)
443 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 461 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
444 local ret=$? 462 local ret=$?

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

  ViewVC Help
Powered by ViewVC 1.1.20