/[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.95 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.95 2005/10/13 05:33:34 vapier 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
293 export CFLAGS="${NEW_CFLAGS}" 293 export CFLAGS="${NEW_CFLAGS}"
294 export CXXFLAGS="${NEW_CXXFLAGS}" 294 export CXXFLAGS="${NEW_CXXFLAGS}"
295 return 0 295 return 0
296} 296}
297 297
298test-flag-PROG() {
299 local comp=$1
300 local flags="$2"
301
302 [[ -z ${comp} || -z ${flags} ]] && \
303 return 1
304
305 local PROG=$(tc-get${comp})
306 ${PROG} ${flags} -S -o /dev/null -xc /dev/null \
307 > /dev/null 2>&1
308}
309
310# Returns true if C compiler support given flag
311test-flag-CC() { test-flag-PROG "CC" "$1"; }
312
313# Returns true if C++ compiler support given flag
314test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
315
316test-flags-PROG() {
317 local comp=$1
318 local flags
319 local x
320
321 shift
322
323 [[ -z ${comp} ]] && \
324 return 1
325
326 for x in "$@" ; do
327 test-flag-${comp} "${x}" && flags="${flags} ${x}"
328 done
329
330 echo "${flags}"
331
332 # Just bail if we dont have any flags
333 [[ -n ${flags} ]]
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 "$@"; }
345
346# Depriciated, use test-flags()
298test_flag() { 347test_flag() {
299 if $(tc-getCC) -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then 348 addwrite "/dev/stderr"
300 printf "%s\n" "$*" 349 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr
301 return 0 350
302 fi 351 test-flags-CC "$@"
303 return 1
304} 352}
305 353
306test_version_info() { 354test_version_info() {
307 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then 355 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
308 return 0 356 return 0
313 361
314strip-unsupported-flags() { 362strip-unsupported-flags() {
315 local x NEW_CFLAGS NEW_CXXFLAGS 363 local x NEW_CFLAGS NEW_CXXFLAGS
316 364
317 for x in ${CFLAGS} ; do 365 for x in ${CFLAGS} ; do
318 NEW_CFLAGS="${NEW_CFLAGS} $(test_flag ${x})" 366 NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
319 done 367 done
320 for x in ${CXXFLAGS} ; do 368 for x in ${CXXFLAGS} ; do
321 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test_flag ${x})" 369 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
322 done 370 done
323 371
324 export CFLAGS=${NEW_CFLAGS} 372 export CFLAGS=${NEW_CFLAGS}
325 export CXXFLAGS=${NEW_CXXFLAGS} 373 export CXXFLAGS=${NEW_CXXFLAGS}
326} 374}
342 return 1 390 return 1
343} 391}
344 392
345# 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
346has_hardened() { 394has_hardened() {
395 addwrite "/dev/stderr"
396 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \
397 >/dev/stderr
398
347 test_version_info Hardened && return 0 399 test_version_info Hardened && return 0
348 # the specs file wont exist unless gcc has GCC_SPECS support 400 # The specs file wont exist unless gcc has GCC_SPECS support
349 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 401 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
350 return 0
351 return 1
352} 402}
353 403
354# DEPRECATED - use gcc-specs-pie from toolchain-funcs 404# DEPRECATED - use gcc-specs-pie from toolchain-funcs
355# indicate whether PIC is set 405# indicate whether PIC is set
356has_pic() { 406has_pic() {
357 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 407 addwrite "/dev/stderr"
358 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 408 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr
409
410 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
411 ${CFLAGS/-fpic} != ${CFLAGS} || \
359 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 412 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
360 return 1
361} 413}
362 414
363# DEPRECATED - use gcc-specs-pie from toolchain-funcs 415# DEPRECATED - use gcc-specs-pie from toolchain-funcs
364# indicate whether PIE is set 416# indicate whether PIE is set
365has_pie() { 417has_pie() {
366 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 418 addwrite "/dev/stderr"
367 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 419 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr
420
421 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
422 ${CFLAGS/-fpie} != ${CFLAGS} || \
423 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \
368 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
369 # 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__
370 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0
371 return 1
372} 426}
373 427
374# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 428# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
375# indicate whether code for SSP is being generated for all functions 429# indicate whether code for SSP is being generated for all functions
376has_ssp_all() { 430has_ssp_all() {
431 addwrite "/dev/stderr"
432 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
433
377 # note; this matches only -fstack-protector-all 434 # note; this matches only -fstack-protector-all
378 [ "${CFLAGS/-fstack-protector-all}" != "${CFLAGS}" ] && return 0 435 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
379 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__)" ] && return 0 436 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
380 gcc-specs-ssp && return 0 437 gcc-specs-ssp
381 return 1
382} 438}
383 439
384# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 440# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
385# indicate whether code for SSP is being generated 441# indicate whether code for SSP is being generated
386has_ssp() { 442has_ssp() {
443 addwrite "/dev/stderr"
444 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
445
387 # note; this matches both -fstack-protector and -fstack-protector-all 446 # note; this matches both -fstack-protector and -fstack-protector-all
388 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 447 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
389 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0 448 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
390 gcc-specs-ssp && return 0 449 gcc-specs-ssp
391 return 1
392} 450}
393 451
394has_m64() { 452has_m64() {
395 # 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
396 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 454 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
397 # please dont replace this function with test_flag in some future 455 # please dont replace this function with test_flag in some future
398 # clean-up! 456 # clean-up!
457
399 local temp="$(emktemp)" 458 local temp="$(emktemp)"
400 echo "int main() { return(0); }" > ${temp}.c 459 echo "int main() { return(0); }" > "${temp}".c
401 MY_CC=$(tc-getCC) 460 MY_CC=$(tc-getCC)
402 ${MY_CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 461 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
403 local ret=$? 462 local ret=$?
404 rm -f ${temp}.c 463 rm -f "${temp}".c
405 [ "$ret" != "1" ] && return 0 464 [[ ${ret} != 1 ]] && return 0
406 return 1 465 return 1
407} 466}
408 467
409has_m32() { 468has_m32() {
410 # this doesnt test if the flag is accepted, it tests if the flag 469 # this doesnt test if the flag is accepted, it tests if the flag
418 echo "int main() { return(0); }" > "${temp}".c 477 echo "int main() { return(0); }" > "${temp}".c
419 MY_CC=$(tc-getCC) 478 MY_CC=$(tc-getCC)
420 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 479 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
421 local ret=$? 480 local ret=$?
422 rm -f "${temp}".c 481 rm -f "${temp}".c
423 [ "$ret" != "1" ] && return 0 482 [[ ${ret} != 1 ]] && return 0
424 return 1 483 return 1
425} 484}
426 485
427replace-sparc64-flags() { 486replace-sparc64-flags() {
428 local SPARC64_CPUS="ultrasparc v9" 487 local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
429 488
430 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 489 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
431 for x in ${SPARC64_CPUS}; do 490 for x in ${SPARC64_CPUS}; do
432 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 491 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
433 done 492 done

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

  ViewVC Help
Powered by ViewVC 1.1.20