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

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

  ViewVC Help
Powered by ViewVC 1.1.20