| 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.100 2005/12/09 22:25:24 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() |
| 7 | inherit eutils toolchain-funcs multilib |
7 | inherit eutils toolchain-funcs multilib |
| 8 | |
8 | |
| … | |
… | |
| 320 | |
320 | |
| 321 | shift |
321 | shift |
| 322 | |
322 | |
| 323 | [[ -z ${comp} ]] && \ |
323 | [[ -z ${comp} ]] && \ |
| 324 | return 1 |
324 | return 1 |
| 325 | |
325 | |
| 326 | for x in "$@" ; do |
326 | for x in "$@" ; do |
| 327 | test-flag-${comp} "${x}" && flags="${flags} ${x}" |
327 | test-flag-${comp} "${x}" && flags="${flags} ${x}" |
| 328 | done |
328 | done |
| 329 | |
329 | |
| 330 | echo "${flags}" |
330 | echo "${flags}" |
| … | |
… | |
| 393 | # 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 |
| 394 | has_hardened() { |
394 | has_hardened() { |
| 395 | addwrite "/dev/stderr" |
395 | addwrite "/dev/stderr" |
| 396 | ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \ |
396 | ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \ |
| 397 | >/dev/stderr |
397 | >/dev/stderr |
| 398 | |
398 | |
| 399 | test_version_info Hardened && return 0 |
399 | test_version_info Hardened && return 0 |
| 400 | # The specs file wont exist unless gcc has GCC_SPECS support |
400 | # The specs file wont exist unless gcc has GCC_SPECS support |
| 401 | [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]] |
401 | [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]] |
| 402 | } |
402 | } |
| 403 | |
403 | |
| 404 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
404 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
| 405 | # indicate whether PIC is set |
405 | # indicate whether PIC is set |
| 406 | has_pic() { |
406 | has_pic() { |
| 407 | addwrite "/dev/stderr" |
407 | addwrite "/dev/stderr" |
| 408 | ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr |
408 | ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr |
| 409 | |
409 | |
| 410 | [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \ |
410 | [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \ |
| 411 | ${CFLAGS/-fpic} != ${CFLAGS} || \ |
411 | ${CFLAGS/-fpic} != ${CFLAGS} || \ |
| 412 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] |
412 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] |
| 413 | } |
413 | } |
| 414 | |
414 | |
| 415 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
415 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
| 416 | # indicate whether PIE is set |
416 | # indicate whether PIE is set |
| 417 | has_pie() { |
417 | has_pie() { |
| 418 | addwrite "/dev/stderr" |
418 | addwrite "/dev/stderr" |
| 419 | ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr |
419 | ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr |
| 420 | |
420 | |
| 421 | [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \ |
421 | [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \ |
| 422 | ${CFLAGS/-fpie} != ${CFLAGS} || \ |
422 | ${CFLAGS/-fpie} != ${CFLAGS} || \ |
| 423 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \ |
423 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \ |
| 424 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] |
424 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]] |
| 425 | # 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__ |
| … | |
… | |
| 428 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
428 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
| 429 | # indicate whether code for SSP is being generated for all functions |
429 | # indicate whether code for SSP is being generated for all functions |
| 430 | has_ssp_all() { |
430 | has_ssp_all() { |
| 431 | addwrite "/dev/stderr" |
431 | addwrite "/dev/stderr" |
| 432 | 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 |
| 433 | |
433 | |
| 434 | # note; this matches only -fstack-protector-all |
434 | # note; this matches only -fstack-protector-all |
| 435 | [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \ |
435 | [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \ |
| 436 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \ |
436 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \ |
| 437 | gcc-specs-ssp |
437 | gcc-specs-ssp |
| 438 | } |
438 | } |
| … | |
… | |
| 440 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
440 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
| 441 | # indicate whether code for SSP is being generated |
441 | # indicate whether code for SSP is being generated |
| 442 | has_ssp() { |
442 | has_ssp() { |
| 443 | addwrite "/dev/stderr" |
443 | addwrite "/dev/stderr" |
| 444 | ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr |
444 | ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr |
| 445 | |
445 | |
| 446 | # note; this matches both -fstack-protector and -fstack-protector-all |
446 | # note; this matches both -fstack-protector and -fstack-protector-all |
| 447 | [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \ |
447 | [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \ |
| 448 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \ |
448 | -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \ |
| 449 | gcc-specs-ssp |
449 | gcc-specs-ssp |
| 450 | } |
450 | } |
| … | |
… | |
| 452 | has_m64() { |
452 | has_m64() { |
| 453 | # 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 |
| 454 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
454 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
| 455 | # please dont replace this function with test_flag in some future |
455 | # please dont replace this function with test_flag in some future |
| 456 | # clean-up! |
456 | # clean-up! |
| 457 | |
457 | |
| 458 | local temp="$(emktemp)" |
458 | local temp="$(emktemp)" |
| 459 | echo "int main() { return(0); }" > "${temp}".c |
459 | echo "int main() { return(0); }" > "${temp}".c |
| 460 | MY_CC=$(tc-getCC) |
460 | MY_CC=$(tc-getCC) |
| 461 | ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 |
461 | ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 |
| 462 | local ret=$? |
462 | local ret=$? |