| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2011 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.159 2011/12/07 06:42:40 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.163 2011/12/28 06:28:55 dirtyepic 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 |
| 9 | # @DESCRIPTION: |
9 | # @DESCRIPTION: |
| 10 | # This eclass contains a suite of functions to help developers sanely |
10 | # This eclass contains a suite of functions to help developers sanely |
| 11 | # and safely manage toolchain flags in their builds. |
11 | # and safely manage toolchain flags in their builds. |
|
|
12 | |
|
|
13 | if [[ ${___ECLASS_ONCE_FLAG_O_MATIC} != "recur -_+^+_- spank" ]] ; then |
|
|
14 | ___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank" |
| 12 | |
15 | |
| 13 | inherit eutils toolchain-funcs multilib |
16 | inherit eutils toolchain-funcs multilib |
| 14 | |
17 | |
| 15 | ################ DEPRECATED functions ################ |
18 | ################ DEPRECATED functions ################ |
| 16 | # The following are still present to avoid breaking existing |
19 | # The following are still present to avoid breaking existing |
| … | |
… | |
| 27 | |
30 | |
| 28 | |
31 | |
| 29 | # {C,CXX,F,FC}FLAGS that we allow in strip-flags |
32 | # {C,CXX,F,FC}FLAGS that we allow in strip-flags |
| 30 | # Note: shell globs and character lists are allowed |
33 | # Note: shell globs and character lists are allowed |
| 31 | setup-allowed-flags() { |
34 | setup-allowed-flags() { |
| 32 | if [[ -z ${ALLOWED_FLAGS} ]] ; then |
|
|
| 33 | export ALLOWED_FLAGS="-pipe" |
35 | ALLOWED_FLAGS="-pipe" |
| 34 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune" |
36 | ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune" |
| 35 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all" |
37 | ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all" |
| 36 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-strict-overflow" |
38 | ALLOWED_FLAGS+=" -fbounds-checking -fno-strict-overflow" |
| 37 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time" |
39 | ALLOWED_FLAGS+=" -fno-PIE -fno-pie -fno-unit-at-a-time" |
| 38 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+" |
40 | ALLOWED_FLAGS+=" -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+" |
| 39 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident -fpermissive" |
41 | ALLOWED_FLAGS+=" -fno-ident -fpermissive" |
| 40 | export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w" |
42 | ALLOWED_FLAGS+=" -W* -w" |
| 41 | fi |
43 | |
| 42 | # allow a bunch of flags that negate features / control ABI |
44 | # allow a bunch of flags that negate features / control ABI |
| 43 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all \ |
45 | ALLOWED_FLAGS+=" -fno-stack-protector -fno-stack-protector-all \ |
| 44 | -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer" |
46 | -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow \ |
|
|
47 | -fno-omit-frame-pointer" |
| 45 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ |
48 | ALLOWED_FLAGS+=" -mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse \ |
| 46 | -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 \ |
49 | -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 \ |
| 47 | -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow \ |
50 | -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt \ |
| 48 | -mno-popcnt -mno-abm \ |
|
|
| 49 | -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \ |
51 | -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \ |
| 50 | -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ |
52 | -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ |
| 51 | -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \ |
53 | -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \ |
| 52 | -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ |
54 | -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat \ |
| 53 | -mflat -mno-flat -mno-faster-structs -mfaster-structs \ |
55 | -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi \ |
| 54 | -m32 -m64 -mx32 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ |
56 | -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel \ |
| 55 | -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \ |
57 | -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -D* -U*" |
| 56 | -msecure-plt -m*-toc -D* -U*" |
|
|
| 57 | |
58 | |
| 58 | # 4.5 |
59 | # 4.5 |
| 59 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fma4 -mno-movbe -mno-xop -mno-lwp" |
60 | ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp" |
| 60 | # 4.6 |
61 | # 4.6 |
| 61 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fsgsbase -mno-rdrnd -mno-f16c \ |
62 | ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm" |
| 62 | -mno-bmi -mno-tbm" |
|
|
| 63 | |
63 | |
| 64 | # {C,CXX,F,FC}FLAGS that we are think is ok, but needs testing |
64 | export ALLOWED_FLAGS |
| 65 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
|
|
| 66 | export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks" |
|
|
| 67 | return 0 |
65 | return 0 |
| 68 | } |
66 | } |
| 69 | |
67 | |
| 70 | # inverted filters for hardened compiler. This is trying to unpick |
68 | # inverted filters for hardened compiler. This is trying to unpick |
| 71 | # the hardened compiler defaults. |
69 | # the hardened compiler defaults. |
| … | |
… | |
| 333 | local NEW_CFLAGS="" |
331 | local NEW_CFLAGS="" |
| 334 | local NEW_CXXFLAGS="" |
332 | local NEW_CXXFLAGS="" |
| 335 | local NEW_FFLAGS="" |
333 | local NEW_FFLAGS="" |
| 336 | local NEW_FCFLAGS="" |
334 | local NEW_FCFLAGS="" |
| 337 | |
335 | |
| 338 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
|
|
| 339 | if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then |
|
|
| 340 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
|
|
| 341 | fi |
|
|
| 342 | |
|
|
| 343 | set -f # disable pathname expansion |
336 | set -f # disable pathname expansion |
| 344 | |
337 | |
| 345 | for x in ${CFLAGS}; do |
338 | for x in ${CFLAGS}; do |
| 346 | for y in ${ALLOWED_FLAGS}; do |
339 | for y in ${ALLOWED_FLAGS}; do |
| 347 | flag=${x%%=*} |
340 | flag=${x%%=*} |
| … | |
… | |
| 682 | *GNU*) # GNU ld |
675 | *GNU*) # GNU ld |
| 683 | echo "-Wl,--no-as-needed" ;; |
676 | echo "-Wl,--no-as-needed" ;; |
| 684 | esac |
677 | esac |
| 685 | } |
678 | } |
| 686 | |
679 | |
| 687 | # Some tests for when we screw with things and want to make |
680 | fi |
| 688 | # sure we didn't break anything |
|
|
| 689 | #TESTS() { |
|
|
| 690 | # CFLAGS="-a -b -c=1" |
|
|
| 691 | # CXXFLAGS="-x -y -z=2" |
|
|
| 692 | # LDFLAGS="-l -m -n=3" |
|
|
| 693 | # |
|
|
| 694 | # die() { exit 1; } |
|
|
| 695 | # (is-flag 1 2 3) && die |
|
|
| 696 | # (is-ldflag 1 2 3) && die |
|
|
| 697 | # |
|
|
| 698 | # is-flagq -l && die |
|
|
| 699 | # is-ldflagq -a && die |
|
|
| 700 | # is-flagq -a || die |
|
|
| 701 | # is-flagq -x || die |
|
|
| 702 | # is-ldflagq -n=* || die |
|
|
| 703 | # is-ldflagq -n && die |
|
|
| 704 | # |
|
|
| 705 | # strip-unsupported-flags |
|
|
| 706 | # [[ ${CFLAGS} == "-c=1" ]] || die |
|
|
| 707 | # [[ ${CXXFLAGS} == "-y -z=2" ]] || die |
|
|
| 708 | # |
|
|
| 709 | # echo "All tests pass" |
|
|
| 710 | #} |
|
|
| 711 | #TESTS |
|
|