/[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.96
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.96 2005/12/08 12:16:12 azarah 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() {
317 local x
318
319 for x in "$@" ; do
320 test-flag-CC "${x}" || return 1
321 done
322
323 echo "$@"
324
325 return 0
326}
327
328# Depriciated, use test-flags()
298test_flag() { 329test_flag() {
299 if $(tc-getCC) -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then 330 ewarn "test_flag: deprecated, please use test-flags()!" >/dev/stderr
300 printf "%s\n" "$*" 331
301 return 0 332 test-flags "$@"
302 fi
303 return 1
304} 333}
305 334
306test_version_info() { 335test_version_info() {
307 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then 336 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
308 return 0 337 return 0
313 342
314strip-unsupported-flags() { 343strip-unsupported-flags() {
315 local x NEW_CFLAGS NEW_CXXFLAGS 344 local x NEW_CFLAGS NEW_CXXFLAGS
316 345
317 for x in ${CFLAGS} ; do 346 for x in ${CFLAGS} ; do
318 NEW_CFLAGS="${NEW_CFLAGS} $(test_flag ${x})" 347 NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
319 done 348 done
320 for x in ${CXXFLAGS} ; do 349 for x in ${CXXFLAGS} ; do
321 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test_flag ${x})" 350 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
322 done 351 done
323 352
324 export CFLAGS=${NEW_CFLAGS} 353 export CFLAGS=${NEW_CFLAGS}
325 export CXXFLAGS=${NEW_CXXFLAGS} 354 export CXXFLAGS=${NEW_CXXFLAGS}
326} 355}
342 return 1 371 return 1
343} 372}
344 373
345# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs 374# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs
346has_hardened() { 375has_hardened() {
376 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" \
377 >/dev/stderr
378
347 test_version_info Hardened && return 0 379 test_version_info Hardened && return 0
348 # the specs file wont exist unless gcc has GCC_SPECS support 380 # The specs file wont exist unless gcc has GCC_SPECS support
349 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 381 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
350 return 0
351 return 1
352} 382}
353 383
354# DEPRECATED - use gcc-specs-pie from toolchain-funcs 384# DEPRECATED - use gcc-specs-pie from toolchain-funcs
355# indicate whether PIC is set 385# indicate whether PIC is set
356has_pic() { 386has_pic() {
357 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 387 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >/dev/stderr
358 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 388
389 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
390 ${CFLAGS/-fpic} != ${CFLAGS} || \
359 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 391 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
360 return 1
361} 392}
362 393
363# DEPRECATED - use gcc-specs-pie from toolchain-funcs 394# DEPRECATED - use gcc-specs-pie from toolchain-funcs
364# indicate whether PIE is set 395# indicate whether PIE is set
365has_pie() { 396has_pie() {
366 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 397 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >/dev/stderr
367 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 398
399 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
400 ${CFLAGS/-fpie} != ${CFLAGS} || \
401 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__) || \
368 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 402 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__) ]]
369 # test PIC while waiting for specs to be updated to generate __PIE__ 403 # 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} 404}
373 405
374# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 406# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
375# indicate whether code for SSP is being generated for all functions 407# indicate whether code for SSP is being generated for all functions
376has_ssp_all() { 408has_ssp_all() {
409 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
410
377 # note; this matches only -fstack-protector-all 411 # note; this matches only -fstack-protector-all
378 [ "${CFLAGS/-fstack-protector-all}" != "${CFLAGS}" ] && return 0 412 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
379 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__)" ] && return 0 413 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
380 gcc-specs-ssp && return 0 414 gcc-specs-ssp
381 return 1
382} 415}
383 416
384# DEPRECATED - use gcc-specs-ssp from toolchain-funcs 417# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
385# indicate whether code for SSP is being generated 418# indicate whether code for SSP is being generated
386has_ssp() { 419has_ssp() {
420 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >/dev/stderr
421
387 # note; this matches both -fstack-protector and -fstack-protector-all 422 # note; this matches both -fstack-protector and -fstack-protector-all
388 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 423 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
389 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0 424 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
390 gcc-specs-ssp && return 0 425 gcc-specs-ssp
391 return 1
392} 426}
393 427
394has_m64() { 428has_m64() {
395 # this doesnt test if the flag is accepted, it tests if the flag 429 # 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! 430 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
397 # please dont replace this function with test_flag in some future 431 # please dont replace this function with test_flag in some future
398 # clean-up! 432 # clean-up!
433
399 local temp="$(emktemp)" 434 local temp="$(emktemp)"
400 echo "int main() { return(0); }" > ${temp}.c 435 echo "int main() { return(0); }" > "${temp}".c
401 MY_CC=$(tc-getCC) 436 MY_CC=$(tc-getCC)
402 ${MY_CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 437 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
403 local ret=$? 438 local ret=$?
404 rm -f ${temp}.c 439 rm -f "${temp}".c
405 [ "$ret" != "1" ] && return 0 440 [[ ${ret} != 1 ]] && return 0
406 return 1 441 return 1
407} 442}
408 443
409has_m32() { 444has_m32() {
410 # this doesnt test if the flag is accepted, it tests if the flag 445 # this doesnt test if the flag is accepted, it tests if the flag
418 echo "int main() { return(0); }" > "${temp}".c 453 echo "int main() { return(0); }" > "${temp}".c
419 MY_CC=$(tc-getCC) 454 MY_CC=$(tc-getCC)
420 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1 455 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
421 local ret=$? 456 local ret=$?
422 rm -f "${temp}".c 457 rm -f "${temp}".c
423 [ "$ret" != "1" ] && return 0 458 [[ ${ret} != 1 ]] && return 0
424 return 1 459 return 1
425} 460}
426 461
427replace-sparc64-flags() { 462replace-sparc64-flags() {
428 local SPARC64_CPUS="ultrasparc v9" 463 local SPARC64_CPUS="ultrasparc v9"

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

  ViewVC Help
Powered by ViewVC 1.1.20