/[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.173 Revision 1.186
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 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.173 2012/05/31 00:29:06 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.186 2012/12/20 21:01:50 jlec Exp $
4 4
5# @ECLASS: flag-o-matic.eclass 5# @ECLASS: flag-o-matic.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# toolchain@gentoo.org 7# toolchain@gentoo.org
8# @BLURB: common functions to manipulate and query toolchain flags 8# @BLURB: common functions to manipulate and query toolchain flags
18# Return all the flag variables that our high level funcs operate on. 18# Return all the flag variables that our high level funcs operate on.
19all-flag-vars() { 19all-flag-vars() {
20 echo {C,CPP,CXX,CCAS,F,FC,LD}FLAGS 20 echo {C,CPP,CXX,CCAS,F,FC,LD}FLAGS
21} 21}
22 22
23# {C,CXX,F,FC}FLAGS that we allow in strip-flags 23# {C,CPP,CXX,CCAS,F,FC,LD}FLAGS that we allow in strip-flags
24# Note: shell globs and character lists are allowed 24# Note: shell globs and character lists are allowed
25setup-allowed-flags() { 25setup-allowed-flags() {
26 ALLOWED_FLAGS="-pipe" 26 ALLOWED_FLAGS="-pipe"
27 ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune" 27 ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune"
28 ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all" 28 ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all"
43 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 43 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
44 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \ 44 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \
45 -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat \ 45 -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat \
46 -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi \ 46 -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi \
47 -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel \ 47 -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel \
48 -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -D* -U*" 48 -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -mfloat-abi \
49 -D* -U*"
49 50
50 # 4.5 51 # 4.5
51 ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp" 52 ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp"
52 # 4.6 53 # 4.6
53 ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm" 54 ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm"
55 # 4.7
56 ALLOWED_FLAGS+=" -mno-avx2 -mno-bmi2 -mno-fma -mno-lzcnt"
57
58 # CPPFLAGS and LDFLAGS
59 ALLOWED_FLAGS+=" -I* -L* -R* -Wl,*"
54 60
55 export ALLOWED_FLAGS 61 export ALLOWED_FLAGS
56 return 0 62 return 0
57} 63}
58 64
189append-ldflags() { 195append-ldflags() {
190 [[ $# -eq 0 ]] && return 0 196 [[ $# -eq 0 ]] && return 0
191 local flag 197 local flag
192 for flag in "$@"; do 198 for flag in "$@"; do
193 [[ ${flag} == -l* ]] && \ 199 [[ ${flag} == -l* ]] && \
194 ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS" 200 eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
195 done 201 done
196 202
197 export LDFLAGS="${LDFLAGS} $*" 203 export LDFLAGS="${LDFLAGS} $*"
198 return 0 204 return 0
199} 205}
257 done 263 done
258 return 0 264 return 0
259} 265}
260 266
261_is_flagq() { 267_is_flagq() {
262 local x 268 local x var
269 eval var=\""\${$1[*]}"\"
263 for x in ${!1} ; do 270 for x in ${var} ; do
264 [[ ${x} == $2 ]] && return 0 271 [[ ${x} == $2 ]] && return 0
265 done 272 done
266 return 1 273 return 1
267} 274}
268 275
339 return 0 346 return 0
340} 347}
341 348
342# @FUNCTION: strip-flags 349# @FUNCTION: strip-flags
343# @DESCRIPTION: 350# @DESCRIPTION:
344# Strip C[XX]FLAGS of everything except known good/safe flags. 351# Strip *FLAGS of everything except known good/safe flags. This runs over all
352# flags returned by all_flag_vars().
345strip-flags() { 353strip-flags() {
346 local x y var 354 local x y var
347 355
348 setup-allowed-flags 356 setup-allowed-flags
349 357
375 return 0 383 return 0
376} 384}
377 385
378test-flag-PROG() { 386test-flag-PROG() {
379 local comp=$1 387 local comp=$1
380 local flag=$2 388 local lang=$2
389 local flag=$3
381 390
382 [[ -z ${comp} || -z ${flag} ]] && return 1 391 [[ -z ${comp} || -z ${flag} ]] && return 1
383 392
384 # use -c so we can test the assembler as well 393 # use -c so we can test the assembler as well
385 local PROG=$(tc-get${comp}) 394 local PROG=$(tc-get${comp})
395 if $( ${PROG} "${flag}" -c -o /dev/null -x${lang} - < /dev/null > /dev/null 2>&1 ); then
386 ${PROG} "${flag}" -c -o /dev/null -xc /dev/null \ 396 ${PROG} "${flag}" -c -o /dev/null -x${lang} - < /dev/null \
387 > /dev/null 2>&1 397 > /dev/null 2>&1
398 else
399 ${PROG} "${flag}" -c -o /dev/null /dev/null \
400 > /dev/null 2>&1
401 fi
388} 402}
389 403
390# @FUNCTION: test-flag-CC 404# @FUNCTION: test-flag-CC
391# @USAGE: <flag> 405# @USAGE: <flag>
392# @DESCRIPTION: 406# @DESCRIPTION:
393# Returns shell true if <flag> is supported by the C compiler, else returns shell false. 407# Returns shell true if <flag> is supported by the C compiler, else returns shell false.
394test-flag-CC() { test-flag-PROG "CC" "$1"; } 408test-flag-CC() { test-flag-PROG "CC" c "$1"; }
395 409
396# @FUNCTION: test-flag-CXX 410# @FUNCTION: test-flag-CXX
397# @USAGE: <flag> 411# @USAGE: <flag>
398# @DESCRIPTION: 412# @DESCRIPTION:
399# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false. 413# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
400test-flag-CXX() { test-flag-PROG "CXX" "$1"; } 414test-flag-CXX() { test-flag-PROG "CXX" c++ "$1"; }
401 415
402# @FUNCTION: test-flag-F77 416# @FUNCTION: test-flag-F77
403# @USAGE: <flag> 417# @USAGE: <flag>
404# @DESCRIPTION: 418# @DESCRIPTION:
405# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false. 419# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
406test-flag-F77() { test-flag-PROG "F77" "$1"; } 420test-flag-F77() { test-flag-PROG "F77" f77 "$1"; }
407 421
408# @FUNCTION: test-flag-FC 422# @FUNCTION: test-flag-FC
409# @USAGE: <flag> 423# @USAGE: <flag>
410# @DESCRIPTION: 424# @DESCRIPTION:
411# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false. 425# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
412test-flag-FC() { test-flag-PROG "FC" "$1"; } 426test-flag-FC() { test-flag-PROG "FC" f95 "$1"; }
413 427
414test-flags-PROG() { 428test-flags-PROG() {
415 local comp=$1 429 local comp=$1
416 local flags 430 local flags=()
417 local x 431 local x
418 432
419 shift 433 shift
420 434
421 [[ -z ${comp} ]] && return 1 435 [[ -z ${comp} ]] && return 1
422 436
423 for x in "$@" ; do 437 for x ; do
424 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}" 438 test-flag-${comp} "${x}" && flags+=( "${x}" )
425 done 439 done
426 440
427 echo "${flags}" 441 echo "${flags[*]}"
428 442
429 # Just bail if we dont have any flags 443 # Just bail if we dont have any flags
430 [[ -n ${flags} ]] 444 [[ ${#flags[@]} -gt 0 ]]
431} 445}
432 446
433# @FUNCTION: test-flags-CC 447# @FUNCTION: test-flags-CC
434# @USAGE: <flags> 448# @USAGE: <flags>
435# @DESCRIPTION: 449# @DESCRIPTION:
589raw-ldflags() { 603raw-ldflags() {
590 local x input="$@" 604 local x input="$@"
591 [[ -z ${input} ]] && input=${LDFLAGS} 605 [[ -z ${input} ]] && input=${LDFLAGS}
592 set -- 606 set --
593 for x in ${input} ; do 607 for x in ${input} ; do
608 case ${x} in
609 -Wl,*)
594 x=${x#-Wl,} 610 x=${x#-Wl,}
595 set -- "$@" ${x//,/ } 611 set -- "$@" ${x//,/ }
612 ;;
613 *) # Assume it's a compiler driver flag, so throw it away #441808
614 ;;
615 esac
596 done 616 done
597 echo "$@" 617 echo "$@"
598} 618}
599 619
600# @FUNCTION: no-as-needed 620# @FUNCTION: no-as-needed

Legend:
Removed from v.1.173  
changed lines
  Added in v.1.186

  ViewVC Help
Powered by ViewVC 1.1.20