/[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.187
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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.187 2013/01/12 14:32:31 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} -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 > /dev/null 2>&1
400 fi
388} 401}
389 402
390# @FUNCTION: test-flag-CC 403# @FUNCTION: test-flag-CC
391# @USAGE: <flag> 404# @USAGE: <flag>
392# @DESCRIPTION: 405# @DESCRIPTION:
393# Returns shell true if <flag> is supported by the C compiler, else returns shell false. 406# Returns shell true if <flag> is supported by the C compiler, else returns shell false.
394test-flag-CC() { test-flag-PROG "CC" "$1"; } 407test-flag-CC() { test-flag-PROG "CC" c "$1"; }
395 408
396# @FUNCTION: test-flag-CXX 409# @FUNCTION: test-flag-CXX
397# @USAGE: <flag> 410# @USAGE: <flag>
398# @DESCRIPTION: 411# @DESCRIPTION:
399# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false. 412# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
400test-flag-CXX() { test-flag-PROG "CXX" "$1"; } 413test-flag-CXX() { test-flag-PROG "CXX" c++ "$1"; }
401 414
402# @FUNCTION: test-flag-F77 415# @FUNCTION: test-flag-F77
403# @USAGE: <flag> 416# @USAGE: <flag>
404# @DESCRIPTION: 417# @DESCRIPTION:
405# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false. 418# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
406test-flag-F77() { test-flag-PROG "F77" "$1"; } 419test-flag-F77() { test-flag-PROG "F77" f77 "$1"; }
407 420
408# @FUNCTION: test-flag-FC 421# @FUNCTION: test-flag-FC
409# @USAGE: <flag> 422# @USAGE: <flag>
410# @DESCRIPTION: 423# @DESCRIPTION:
411# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false. 424# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
412test-flag-FC() { test-flag-PROG "FC" "$1"; } 425test-flag-FC() { test-flag-PROG "FC" f95 "$1"; }
413 426
414test-flags-PROG() { 427test-flags-PROG() {
415 local comp=$1 428 local comp=$1
416 local flags 429 local flags=()
417 local x 430 local x
418 431
419 shift 432 shift
420 433
421 [[ -z ${comp} ]] && return 1 434 [[ -z ${comp} ]] && return 1
422 435
423 for x in "$@" ; do 436 for x ; do
424 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}" 437 test-flag-${comp} "${x}" && flags+=( "${x}" )
425 done 438 done
426 439
427 echo "${flags}" 440 echo "${flags[*]}"
428 441
429 # Just bail if we dont have any flags 442 # Just bail if we dont have any flags
430 [[ -n ${flags} ]] 443 [[ ${#flags[@]} -gt 0 ]]
431} 444}
432 445
433# @FUNCTION: test-flags-CC 446# @FUNCTION: test-flags-CC
434# @USAGE: <flags> 447# @USAGE: <flags>
435# @DESCRIPTION: 448# @DESCRIPTION:
589raw-ldflags() { 602raw-ldflags() {
590 local x input="$@" 603 local x input="$@"
591 [[ -z ${input} ]] && input=${LDFLAGS} 604 [[ -z ${input} ]] && input=${LDFLAGS}
592 set -- 605 set --
593 for x in ${input} ; do 606 for x in ${input} ; do
607 case ${x} in
608 -Wl,*)
594 x=${x#-Wl,} 609 x=${x#-Wl,}
595 set -- "$@" ${x//,/ } 610 set -- "$@" ${x//,/ }
611 ;;
612 *) # Assume it's a compiler driver flag, so throw it away #441808
613 ;;
614 esac
596 done 615 done
597 echo "$@" 616 echo "$@"
598} 617}
599 618
600# @FUNCTION: no-as-needed 619# @FUNCTION: no-as-needed

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

  ViewVC Help
Powered by ViewVC 1.1.20