/[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.153 Revision 1.163
1# Copyright 1999-2009 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.153 2011/08/17 17:54:48 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
13if [[ ${___ECLASS_ONCE_FLAG_O_MATIC} != "recur -_+^+_- spank" ]] ; then
14___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
12 15
13inherit eutils toolchain-funcs multilib 16inherit 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
31setup-allowed-flags() { 34setup-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 -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.
128 126
129# @FUNCTION: filter-lfs-flags 127# @FUNCTION: filter-lfs-flags
130# @DESCRIPTION: 128# @DESCRIPTION:
131# Remove flags that enable Large File Support. 129# Remove flags that enable Large File Support.
132filter-lfs-flags() { 130filter-lfs-flags() {
133 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments" 131 [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments"
134 # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html 132 # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html
135 # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...) 133 # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...)
136 # _LARGEFILE64_SOURCE: enable support for 64bit variants (off64_t/fseeko64/etc...) 134 # _LARGEFILE64_SOURCE: enable support for 64bit variants (off64_t/fseeko64/etc...)
137 # _FILE_OFFSET_BITS: default to 64bit variants (off_t is defined as off64_t) 135 # _FILE_OFFSET_BITS: default to 64bit variants (off_t is defined as off64_t)
138 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 136 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
141# @FUNCTION: append-cppflags 139# @FUNCTION: append-cppflags
142# @USAGE: <flags> 140# @USAGE: <flags>
143# @DESCRIPTION: 141# @DESCRIPTION:
144# Add extra <flags> to the current CPPFLAGS. 142# Add extra <flags> to the current CPPFLAGS.
145append-cppflags() { 143append-cppflags() {
146 [[ -z $* ]] && return 0 144 [[ $# -eq 0 ]] && return 0
147 export CPPFLAGS="${CPPFLAGS} $*" 145 export CPPFLAGS="${CPPFLAGS} $*"
148 return 0 146 return 0
149} 147}
150 148
151# @FUNCTION: append-cflags 149# @FUNCTION: append-cflags
152# @USAGE: <flags> 150# @USAGE: <flags>
153# @DESCRIPTION: 151# @DESCRIPTION:
154# Add extra <flags> to the current CFLAGS. 152# Add extra <flags> to the current CFLAGS.
155append-cflags() { 153append-cflags() {
156 [[ -z $* ]] && return 0 154 [[ $# -eq 0 ]] && return 0
157 export CFLAGS="${CFLAGS} $*" 155 export CFLAGS=$(test-flags-CC ${CFLAGS} "$@")
158 return 0 156 return 0
159} 157}
160 158
161# @FUNCTION: append-cxxflags 159# @FUNCTION: append-cxxflags
162# @USAGE: <flags> 160# @USAGE: <flags>
163# @DESCRIPTION: 161# @DESCRIPTION:
164# Add extra <flags> to the current CXXFLAGS. 162# Add extra <flags> to the current CXXFLAGS.
165append-cxxflags() { 163append-cxxflags() {
166 [[ -z $* ]] && return 0 164 [[ $# -eq 0 ]] && return 0
167 export CXXFLAGS="${CXXFLAGS} $*" 165 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@")
168 return 0 166 return 0
169} 167}
170 168
171# @FUNCTION: append-fflags 169# @FUNCTION: append-fflags
172# @USAGE: <flags> 170# @USAGE: <flags>
173# @DESCRIPTION: 171# @DESCRIPTION:
174# Add extra <flags> to the current {F,FC}FLAGS. 172# Add extra <flags> to the current {F,FC}FLAGS.
175append-fflags() { 173append-fflags() {
176 [[ -z $* ]] && return 0 174 [[ $# -eq 0 ]] && return 0
177 export FFLAGS="${FFLAGS} $*" 175 export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@")
178 export FCFLAGS="${FCFLAGS} $*" 176 export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@")
179 return 0 177 return 0
180} 178}
181 179
182# @FUNCTION: append-lfs-flags 180# @FUNCTION: append-lfs-flags
183# @DESCRIPTION: 181# @DESCRIPTION:
184# Add flags that enable Large File Support. 182# Add flags that enable Large File Support.
185append-lfs-flags() { 183append-lfs-flags() {
186 [[ -n $@ ]] && die "append-lfs-flags takes no arguments" 184 [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments"
185 # see comments in filter-lfs-flags func for meaning of these
187 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 186 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
188} 187}
189 188
190# @FUNCTION: append-flags 189# @FUNCTION: append-flags
191# @USAGE: <flags> 190# @USAGE: <flags>
192# @DESCRIPTION: 191# @DESCRIPTION:
193# Add extra <flags> to your current {C,CXX,F,FC}FLAGS. 192# Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
194append-flags() { 193append-flags() {
195 [[ -z $* ]] && return 0 194 [[ $# -eq 0 ]] && return 0
196 append-cflags "$@" 195 append-cflags "$@"
197 append-cxxflags "$@" 196 append-cxxflags "$@"
198 append-fflags "$@" 197 append-fflags "$@"
199 return 0 198 return 0
200} 199}
332 local NEW_CFLAGS="" 331 local NEW_CFLAGS=""
333 local NEW_CXXFLAGS="" 332 local NEW_CXXFLAGS=""
334 local NEW_FFLAGS="" 333 local NEW_FFLAGS=""
335 local NEW_FCFLAGS="" 334 local NEW_FCFLAGS=""
336 335
337 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
338 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
339 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
340 fi
341
342 set -f # disable pathname expansion 336 set -f # disable pathname expansion
343 337
344 for x in ${CFLAGS}; do 338 for x in ${CFLAGS}; do
345 for y in ${ALLOWED_FLAGS}; do 339 for y in ${ALLOWED_FLAGS}; do
346 flag=${x%%=*} 340 flag=${x%%=*}
447 441
448 shift 442 shift
449 443
450 [[ -z ${comp} ]] && return 1 444 [[ -z ${comp} ]] && return 1
451 445
452 x=""
453 for x in "$@" ; do 446 for x in "$@" ; do
454 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}" 447 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
455 done 448 done
456 449
457 echo "${flags}" 450 echo "${flags}"
619# @FUNCTION: append-libs 612# @FUNCTION: append-libs
620# @USAGE: <libs> 613# @USAGE: <libs>
621# @DESCRIPTION: 614# @DESCRIPTION:
622# Add extra <libs> to the current LIBS. 615# Add extra <libs> to the current LIBS.
623append-libs() { 616append-libs() {
624 [[ -z $* ]] && return 0 617 [[ $# -eq 0 ]] && return 0
625 local flag 618 local flag
626 for flag in "$@"; do 619 for flag in "$@"; do
627 [[ ${flag} == -l* ]] && flag=${flag#-l} 620 [[ ${flag} == -l* ]] && flag=${flag#-l}
628 export LIBS="${LIBS} -l${flag}" 621 export LIBS="${LIBS} -l${flag}"
629 done 622 done
634# @FUNCTION: append-ldflags 627# @FUNCTION: append-ldflags
635# @USAGE: <flags> 628# @USAGE: <flags>
636# @DESCRIPTION: 629# @DESCRIPTION:
637# Add extra <flags> to the current LDFLAGS. 630# Add extra <flags> to the current LDFLAGS.
638append-ldflags() { 631append-ldflags() {
639 [[ -z $* ]] && return 0 632 [[ $# -eq 0 ]] && return 0
640 local flag 633 local flag
641 for flag in "$@"; do 634 for flag in "$@"; do
642 [[ ${flag} == -l* ]] && \ 635 [[ ${flag} == -l* ]] && \
643 ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS" 636 ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
644 done 637 done
655 _filter-var LDFLAGS "$@" 648 _filter-var LDFLAGS "$@"
656 return 0 649 return 0
657} 650}
658 651
659# @FUNCTION: raw-ldflags 652# @FUNCTION: raw-ldflags
660# @USAGE: <flags> 653# @USAGE: [flags]
661# @DESCRIPTION: 654# @DESCRIPTION:
662# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results 655# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
663# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed 656# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed
664# to gcc where it needs the '-Wl,'. 657# to gcc where it needs the '-Wl,'.
658#
659# If no flags are specified, then default to ${LDFLAGS}.
665raw-ldflags() { 660raw-ldflags() {
666 local x input="$@" 661 local x input="$@"
667 [[ -z ${input} ]] && input=${LDFLAGS} 662 [[ -z ${input} ]] && input=${LDFLAGS}
668 set -- 663 set --
669 for x in ${input} ; do 664 for x in ${input} ; do
680 *GNU*) # GNU ld 675 *GNU*) # GNU ld
681 echo "-Wl,--no-as-needed" ;; 676 echo "-Wl,--no-as-needed" ;;
682 esac 677 esac
683} 678}
684 679
685# Some tests for when we screw with things and want to make 680fi
686# sure we didn't break anything
687#TESTS() {
688# CFLAGS="-a -b -c=1"
689# CXXFLAGS="-x -y -z=2"
690# LDFLAGS="-l -m -n=3"
691#
692# die() { exit 1; }
693# (is-flag 1 2 3) && die
694# (is-ldflag 1 2 3) && die
695#
696# is-flagq -l && die
697# is-ldflagq -a && die
698# is-flagq -a || die
699# is-flagq -x || die
700# is-ldflagq -n=* || die
701# is-ldflagq -n && die
702#
703# strip-unsupported-flags
704# [[ ${CFLAGS} == "-c=1" ]] || die
705# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
706#
707# echo "All tests pass"
708#}
709#TESTS

Legend:
Removed from v.1.153  
changed lines
  Added in v.1.163

  ViewVC Help
Powered by ViewVC 1.1.20