/[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.152 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.152 2011/07/12 04:08:52 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"
132 # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html
133 # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...)
134 # _LARGEFILE64_SOURCE: enable support for 64bit variants (off64_t/fseeko64/etc...)
135 # _FILE_OFFSET_BITS: default to 64bit variants (off_t is defined as off64_t)
134 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
135} 137}
136 138
137# @FUNCTION: append-cppflags 139# @FUNCTION: append-cppflags
138# @USAGE: <flags> 140# @USAGE: <flags>
139# @DESCRIPTION: 141# @DESCRIPTION:
140# Add extra <flags> to the current CPPFLAGS. 142# Add extra <flags> to the current CPPFLAGS.
141append-cppflags() { 143append-cppflags() {
142 [[ -z $* ]] && return 0 144 [[ $# -eq 0 ]] && return 0
143 export CPPFLAGS="${CPPFLAGS} $*" 145 export CPPFLAGS="${CPPFLAGS} $*"
144 return 0 146 return 0
145} 147}
146 148
147# @FUNCTION: append-cflags 149# @FUNCTION: append-cflags
148# @USAGE: <flags> 150# @USAGE: <flags>
149# @DESCRIPTION: 151# @DESCRIPTION:
150# Add extra <flags> to the current CFLAGS. 152# Add extra <flags> to the current CFLAGS.
151append-cflags() { 153append-cflags() {
152 [[ -z $* ]] && return 0 154 [[ $# -eq 0 ]] && return 0
153 export CFLAGS="${CFLAGS} $*" 155 export CFLAGS=$(test-flags-CC ${CFLAGS} "$@")
154 return 0 156 return 0
155} 157}
156 158
157# @FUNCTION: append-cxxflags 159# @FUNCTION: append-cxxflags
158# @USAGE: <flags> 160# @USAGE: <flags>
159# @DESCRIPTION: 161# @DESCRIPTION:
160# Add extra <flags> to the current CXXFLAGS. 162# Add extra <flags> to the current CXXFLAGS.
161append-cxxflags() { 163append-cxxflags() {
162 [[ -z $* ]] && return 0 164 [[ $# -eq 0 ]] && return 0
163 export CXXFLAGS="${CXXFLAGS} $*" 165 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@")
164 return 0 166 return 0
165} 167}
166 168
167# @FUNCTION: append-fflags 169# @FUNCTION: append-fflags
168# @USAGE: <flags> 170# @USAGE: <flags>
169# @DESCRIPTION: 171# @DESCRIPTION:
170# Add extra <flags> to the current {F,FC}FLAGS. 172# Add extra <flags> to the current {F,FC}FLAGS.
171append-fflags() { 173append-fflags() {
172 [[ -z $* ]] && return 0 174 [[ $# -eq 0 ]] && return 0
173 export FFLAGS="${FFLAGS} $*" 175 export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@")
174 export FCFLAGS="${FCFLAGS} $*" 176 export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@")
175 return 0 177 return 0
176} 178}
177 179
178# @FUNCTION: append-lfs-flags 180# @FUNCTION: append-lfs-flags
179# @DESCRIPTION: 181# @DESCRIPTION:
180# Add flags that enable Large File Support. 182# Add flags that enable Large File Support.
181append-lfs-flags() { 183append-lfs-flags() {
182 [[ -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
183 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
184} 187}
185 188
186# @FUNCTION: append-flags 189# @FUNCTION: append-flags
187# @USAGE: <flags> 190# @USAGE: <flags>
188# @DESCRIPTION: 191# @DESCRIPTION:
189# Add extra <flags> to your current {C,CXX,F,FC}FLAGS. 192# Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
190append-flags() { 193append-flags() {
191 [[ -z $* ]] && return 0 194 [[ $# -eq 0 ]] && return 0
192 append-cflags "$@" 195 append-cflags "$@"
193 append-cxxflags "$@" 196 append-cxxflags "$@"
194 append-fflags "$@" 197 append-fflags "$@"
195 return 0 198 return 0
196} 199}
328 local NEW_CFLAGS="" 331 local NEW_CFLAGS=""
329 local NEW_CXXFLAGS="" 332 local NEW_CXXFLAGS=""
330 local NEW_FFLAGS="" 333 local NEW_FFLAGS=""
331 local NEW_FCFLAGS="" 334 local NEW_FCFLAGS=""
332 335
333 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
334 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
335 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
336 fi
337
338 set -f # disable pathname expansion 336 set -f # disable pathname expansion
339 337
340 for x in ${CFLAGS}; do 338 for x in ${CFLAGS}; do
341 for y in ${ALLOWED_FLAGS}; do 339 for y in ${ALLOWED_FLAGS}; do
342 flag=${x%%=*} 340 flag=${x%%=*}
443 441
444 shift 442 shift
445 443
446 [[ -z ${comp} ]] && return 1 444 [[ -z ${comp} ]] && return 1
447 445
448 x=""
449 for x in "$@" ; do 446 for x in "$@" ; do
450 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}" 447 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
451 done 448 done
452 449
453 echo "${flags}" 450 echo "${flags}"
615# @FUNCTION: append-libs 612# @FUNCTION: append-libs
616# @USAGE: <libs> 613# @USAGE: <libs>
617# @DESCRIPTION: 614# @DESCRIPTION:
618# Add extra <libs> to the current LIBS. 615# Add extra <libs> to the current LIBS.
619append-libs() { 616append-libs() {
620 [[ -z $* ]] && return 0 617 [[ $# -eq 0 ]] && return 0
621 local flag 618 local flag
622 for flag in "$@"; do 619 for flag in "$@"; do
623 [[ ${flag} == -l* ]] && flag=${flag#-l} 620 [[ ${flag} == -l* ]] && flag=${flag#-l}
624 export LIBS="${LIBS} -l${flag}" 621 export LIBS="${LIBS} -l${flag}"
625 done 622 done
630# @FUNCTION: append-ldflags 627# @FUNCTION: append-ldflags
631# @USAGE: <flags> 628# @USAGE: <flags>
632# @DESCRIPTION: 629# @DESCRIPTION:
633# Add extra <flags> to the current LDFLAGS. 630# Add extra <flags> to the current LDFLAGS.
634append-ldflags() { 631append-ldflags() {
635 [[ -z $* ]] && return 0 632 [[ $# -eq 0 ]] && return 0
636 local flag 633 local flag
637 for flag in "$@"; do 634 for flag in "$@"; do
638 [[ ${flag} == -l* ]] && \ 635 [[ ${flag} == -l* ]] && \
639 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"
640 done 637 done
651 _filter-var LDFLAGS "$@" 648 _filter-var LDFLAGS "$@"
652 return 0 649 return 0
653} 650}
654 651
655# @FUNCTION: raw-ldflags 652# @FUNCTION: raw-ldflags
656# @USAGE: <flags> 653# @USAGE: [flags]
657# @DESCRIPTION: 654# @DESCRIPTION:
658# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results 655# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
659# 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
660# 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}.
661raw-ldflags() { 660raw-ldflags() {
662 local x input="$@" 661 local x input="$@"
663 [[ -z ${input} ]] && input=${LDFLAGS} 662 [[ -z ${input} ]] && input=${LDFLAGS}
664 set -- 663 set --
665 for x in ${input} ; do 664 for x in ${input} ; do
676 *GNU*) # GNU ld 675 *GNU*) # GNU ld
677 echo "-Wl,--no-as-needed" ;; 676 echo "-Wl,--no-as-needed" ;;
678 esac 677 esac
679} 678}
680 679
681# Some tests for when we screw with things and want to make 680fi
682# sure we didn't break anything
683#TESTS() {
684# CFLAGS="-a -b -c=1"
685# CXXFLAGS="-x -y -z=2"
686# LDFLAGS="-l -m -n=3"
687#
688# die() { exit 1; }
689# (is-flag 1 2 3) && die
690# (is-ldflag 1 2 3) && die
691#
692# is-flagq -l && die
693# is-ldflagq -a && die
694# is-flagq -a || die
695# is-flagq -x || die
696# is-ldflagq -n=* || die
697# is-ldflagq -n && die
698#
699# strip-unsupported-flags
700# [[ ${CFLAGS} == "-c=1" ]] || die
701# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
702#
703# echo "All tests pass"
704#}
705#TESTS

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

  ViewVC Help
Powered by ViewVC 1.1.20