/[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.121 Revision 1.124
1# Copyright 1999-2008 Gentoo Foundation 1# Copyright 1999-2008 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.121 2008/02/16 22:43:04 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.124 2008/07/03 05:30:54 dberkholz 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
24# has_pic 24# has_pic
25# has_ssp_all 25# has_ssp_all
26# has_ssp 26# has_ssp
27 27
28 28
29# C[XX]FLAGS that we allow in strip-flags 29# {C,CXX,F,FC}FLAGS that we allow in strip-flags
30# Note: shell globs and character lists are allowed 30# Note: shell globs and character lists are allowed
31setup-allowed-flags() { 31setup-allowed-flags() {
32 if [[ -z ${ALLOWED_FLAGS} ]] ; then 32 if [[ -z ${ALLOWED_FLAGS} ]] ; then
33 export ALLOWED_FLAGS="-pipe" 33 export ALLOWED_FLAGS="-pipe"
34 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune" 34 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
51 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 51 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
52 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 52 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
53 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \ 53 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \
54 -msecure-plt -D*" 54 -msecure-plt -D*"
55 55
56 # C[XX]FLAGS that we are think is ok, but needs testing 56 # {C,CXX,F,FC}FLAGS that we are think is ok, but needs testing
57 # NOTE: currently -Os have issues with gcc3 and K6* arch's 57 # NOTE: currently -Os have issues with gcc3 and K6* arch's
58 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks" 58 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
59 return 0 59 return 0
60} 60}
61 61
102} 102}
103 103
104# @FUNCTION: filter-flags 104# @FUNCTION: filter-flags
105# @USAGE: <flags> 105# @USAGE: <flags>
106# @DESCRIPTION: 106# @DESCRIPTION:
107# Remove particular <flags> from {C,CPP,CXX}FLAGS. Accepts shell globs. 107# Remove particular <flags> from {C,CPP,CXX,F,FC}FLAGS. Accepts shell globs.
108filter-flags() { 108filter-flags() {
109 _filter-hardened "$@" 109 _filter-hardened "$@"
110 _filter-var CFLAGS "$@" 110 _filter-var CFLAGS "$@"
111 _filter-var CPPFLAGS "$@" 111 _filter-var CPPFLAGS "$@"
112 _filter-var CXXFLAGS "$@" 112 _filter-var CXXFLAGS "$@"
113 _filter-var FFLAGS "$@"
114 _filter-var FCFLAGS "$@"
113 return 0 115 return 0
114} 116}
115 117
116# @FUNCTION: filter-lfs-flags 118# @FUNCTION: filter-lfs-flags
117# @DESCRIPTION: 119# @DESCRIPTION:
129 [[ -z $* ]] && return 0 131 [[ -z $* ]] && return 0
130 export CPPFLAGS="${CPPFLAGS} $*" 132 export CPPFLAGS="${CPPFLAGS} $*"
131 return 0 133 return 0
132} 134}
133 135
136# @FUNCTION: append-fflags
137# @USAGE: <flags>
138# @DESCRIPTION:
139# Add extra <flags> to the current {F,FC}FLAGS.
140append-fflags() {
141 [[ -z $* ]] && return 0
142 export FFLAGS="${FFLAGS} $*"
143 export FCFLAGS="${FCFLAGS} $*"
144 return 0
145}
146
134# @FUNCTION: append-lfs-flags 147# @FUNCTION: append-lfs-flags
135# @DESCRIPTION: 148# @DESCRIPTION:
136# Add flags that enable Large File Support. 149# Add flags that enable Large File Support.
137append-lfs-flags() { 150append-lfs-flags() {
138 [[ -n $@ ]] && die "append-lfs-flags takes no arguments" 151 [[ -n $@ ]] && die "append-lfs-flags takes no arguments"
140} 153}
141 154
142# @FUNCTION: append-flags 155# @FUNCTION: append-flags
143# @USAGE: <flags> 156# @USAGE: <flags>
144# @DESCRIPTION: 157# @DESCRIPTION:
145# Add extra <flags> to your current C[XX]FLAGS. 158# Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
146append-flags() { 159append-flags() {
147 [[ -z $* ]] && return 0 160 [[ -z $* ]] && return 0
148 export CFLAGS="${CFLAGS} $*" 161 export CFLAGS="${CFLAGS} $*"
149 export CXXFLAGS="${CXXFLAGS} $*" 162 export CXXFLAGS="${CXXFLAGS} $*"
163 export FFLAGS="${FFLAGS} $*"
164 export FCFLAGS="${FCFLAGS} $*"
150 return 0 165 return 0
151} 166}
152 167
153# @FUNCTION: replace-flags 168# @FUNCTION: replace-flags
154# @USAGE: <old> <new> 169# @USAGE: <old> <new>
160 && die "replace-flags takes 2 arguments, not $#" 175 && die "replace-flags takes 2 arguments, not $#"
161 176
162 local f fset 177 local f fset
163 declare -a new_CFLAGS new_CXXFLAGS 178 declare -a new_CFLAGS new_CXXFLAGS
164 179
165 for fset in CFLAGS CXXFLAGS; do 180 for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS; do
166 # Looping over the flags instead of using a global 181 # Looping over the flags instead of using a global
167 # substitution ensures that we're working with flag atoms. 182 # substitution ensures that we're working with flag atoms.
168 # Otherwise globs like -O* have the potential to wipe out the 183 # Otherwise globs like -O* have the potential to wipe out the
169 # list of flags. 184 # list of flags.
170 for f in ${!fset}; do 185 for f in ${!fset}; do
205} 220}
206 221
207# @FUNCTION: is-flagq 222# @FUNCTION: is-flagq
208# @USAGE: <flag> 223# @USAGE: <flag>
209# @DESCRIPTION: 224# @DESCRIPTION:
210# Returns shell true if <flag> is in C[XX]FLAGS, else returns shell false. Accepts shell globs. 225# Returns shell true if <flag> is in {C,CXX,F,FC}FLAGS, else returns shell false. Accepts shell globs.
211is-flagq() { 226is-flagq() {
212 [[ -n $2 ]] && die "Usage: is-flag <flag>" 227 [[ -n $2 ]] && die "Usage: is-flag <flag>"
213 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 228 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
214} 229}
215 230
216# @FUNCTION: is-flag 231# @FUNCTION: is-flag
217# @USAGE: <flag> 232# @USAGE: <flag>
218# @DESCRIPTION: 233# @DESCRIPTION:
219# Echo's "true" if flag is set in C[XX]FLAGS. Accepts shell globs. 234# Echo's "true" if flag is set in {C,CXX,F,FC}FLAGS. Accepts shell globs.
220is-flag() { 235is-flag() {
221 is-flagq "$@" && echo true 236 is-flagq "$@" && echo true
222} 237}
223 238
224# @FUNCTION: is-ldflagq 239# @FUNCTION: is-ldflagq
274 289
275# @FUNCTION: strip-flags 290# @FUNCTION: strip-flags
276# @DESCRIPTION: 291# @DESCRIPTION:
277# Strip C[XX]FLAGS of everything except known good/safe flags. 292# Strip C[XX]FLAGS of everything except known good/safe flags.
278strip-flags() { 293strip-flags() {
279 local x y flag NEW_CFLAGS NEW_CXXFLAGS 294 local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS
280 295
281 setup-allowed-flags 296 setup-allowed-flags
282 297
283 local NEW_CFLAGS="" 298 local NEW_CFLAGS=""
284 local NEW_CXXFLAGS="" 299 local NEW_CXXFLAGS=""
300 local NEW_FFLAGS=""
301 local NEW_FCFLAGS=""
285 302
286 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 303 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
287 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then 304 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then
288 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 305 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
289 fi 306 fi
308 break 325 break
309 fi 326 fi
310 done 327 done
311 done 328 done
312 329
330 for x in ${FFLAGS}; do
331 for y in ${ALLOWED_FLAGS}; do
332 flag=${x%%=*}
333 if [ "${flag%%${y}}" = "" ] ; then
334 NEW_FFLAGS="${NEW_FFLAGS} ${x}"
335 break
336 fi
337 done
338 done
339
340 for x in ${FCFLAGS}; do
341 for y in ${ALLOWED_FLAGS}; do
342 flag=${x%%=*}
343 if [ "${flag%%${y}}" = "" ] ; then
344 NEW_FCFLAGS="${NEW_FCFLAGS} ${x}"
345 break
346 fi
347 done
348 done
349
313 # In case we filtered out all optimization flags fallback to -O2 350 # In case we filtered out all optimization flags fallback to -O2
314 if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then 351 if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
315 NEW_CFLAGS="${NEW_CFLAGS} -O2" 352 NEW_CFLAGS="${NEW_CFLAGS} -O2"
316 fi 353 fi
317 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then 354 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
318 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 355 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
319 fi 356 fi
357 if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
358 NEW_FFLAGS="${NEW_FFLAGS} -O2"
359 fi
360 if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
361 NEW_FCFLAGS="${NEW_FCFLAGS} -O2"
362 fi
320 363
321 set +f # re-enable pathname expansion 364 set +f # re-enable pathname expansion
322 365
323 export CFLAGS="${NEW_CFLAGS}" 366 export CFLAGS="${NEW_CFLAGS}"
324 export CXXFLAGS="${NEW_CXXFLAGS}" 367 export CXXFLAGS="${NEW_CXXFLAGS}"
368 export FFLAGS="${NEW_FFLAGS}"
369 export FCFLAGS="${NEW_FCFLAGS}"
325 return 0 370 return 0
326} 371}
327 372
328test-flag-PROG() { 373test-flag-PROG() {
329 local comp=$1 374 local comp=$1
346# @FUNCTION: test-flag-CXX 391# @FUNCTION: test-flag-CXX
347# @USAGE: <flag> 392# @USAGE: <flag>
348# @DESCRIPTION: 393# @DESCRIPTION:
349# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false. 394# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
350test-flag-CXX() { test-flag-PROG "CXX" "$1"; } 395test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
396
397# @FUNCTION: test-flag-F77
398# @USAGE: <flag>
399# @DESCRIPTION:
400# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
401test-flag-F77() { test-flag-PROG "F77" "$1"; }
402
403# @FUNCTION: test-flag-FC
404# @USAGE: <flag>
405# @DESCRIPTION:
406# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
407test-flag-FC() { test-flag-PROG "FC" "$1"; }
351 408
352test-flags-PROG() { 409test-flags-PROG() {
353 local comp=$1 410 local comp=$1
354 local flags 411 local flags
355 local x 412 local x
378# @FUNCTION: test-flags-CXX 435# @FUNCTION: test-flags-CXX
379# @USAGE: <flags> 436# @USAGE: <flags>
380# @DESCRIPTION: 437# @DESCRIPTION:
381# Returns shell true if <flags> are supported by the C++ compiler, else returns shell false. 438# Returns shell true if <flags> are supported by the C++ compiler, else returns shell false.
382test-flags-CXX() { test-flags-PROG "CXX" "$@"; } 439test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
440
441# @FUNCTION: test-flags-F77
442# @USAGE: <flags>
443# @DESCRIPTION:
444# Returns shell true if <flags> are supported by the Fortran 77 compiler, else returns shell false.
445test-flags-F77() { test-flags-PROG "F77" "$@"; }
446
447# @FUNCTION: test-flags-FC
448# @USAGE: <flags>
449# @DESCRIPTION:
450# Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false.
451test-flags-FC() { test-flags-PROG "FC" "$@"; }
383 452
384# @FUNCTION: test-flags 453# @FUNCTION: test-flags
385# @USAGE: <flags> 454# @USAGE: <flags>
386# @DESCRIPTION: 455# @DESCRIPTION:
387# Short-hand that should hopefully work for both C and C++ compiler, but 456# Short-hand that should hopefully work for both C and C++ compiler, but
410 fi 479 fi
411} 480}
412 481
413# @FUNCTION: strip-unsupported-flags 482# @FUNCTION: strip-unsupported-flags
414# @DESCRIPTION: 483# @DESCRIPTION:
415# Strip C[XX]FLAGS of any flags not supported by the active toolchain. 484# Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain.
416strip-unsupported-flags() { 485strip-unsupported-flags() {
417 export CFLAGS=$(test-flags-CC ${CFLAGS}) 486 export CFLAGS=$(test-flags-CC ${CFLAGS})
418 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}) 487 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
488 export FFLAGS=$(test-flags-F77 ${FFLAGS})
489 export FCFLAGS=$(test-flags-FC ${FCFLAGS})
419} 490}
420 491
421# @FUNCTION: get-flag 492# @FUNCTION: get-flag
422# @USAGE: <flag> 493# @USAGE: <flag>
423# @DESCRIPTION: 494# @DESCRIPTION:
428 # this code looks a little flaky but seems to work for 499 # this code looks a little flaky but seems to work for
429 # everything we want ... 500 # everything we want ...
430 # for example, if CFLAGS="-march=i686": 501 # for example, if CFLAGS="-march=i686":
431 # `get-flag -march` == "-march=i686" 502 # `get-flag -march` == "-march=i686"
432 # `get-flag march` == "i686" 503 # `get-flag march` == "i686"
433 for f in ${CFLAGS} ${CXXFLAGS} ; do 504 for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS} ; do
434 if [ "${f/${findflag}}" != "${f}" ] ; then 505 if [ "${f/${findflag}}" != "${f}" ] ; then
435 printf "%s\n" "${f/-${findflag}=}" 506 printf "%s\n" "${f/-${findflag}=}"
436 return 0 507 return 0
437 fi 508 fi
438 done 509 done
577# @USAGE: <flags> 648# @USAGE: <flags>
578# @DESCRIPTION: 649# @DESCRIPTION:
579# Add extra <flags> to the current LDFLAGS. 650# Add extra <flags> to the current LDFLAGS.
580append-ldflags() { 651append-ldflags() {
581 [[ -z $* ]] && return 0 652 [[ -z $* ]] && return 0
653 local flag
654 for flag in "$@"; do
655 [[ ${flag} == -l* ]] && \
656 ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
657 done
658
582 export LDFLAGS="${LDFLAGS} $*" 659 export LDFLAGS="${LDFLAGS} $*"
583 return 0 660 return 0
584} 661}
585 662
586# @FUNCTION: filter-ldflags 663# @FUNCTION: filter-ldflags
612# @FUNCTION: bindnow-flags 689# @FUNCTION: bindnow-flags
613# @RETURN: Returns the flags to enable "now" binding in the current selected linker. 690# @RETURN: Returns the flags to enable "now" binding in the current selected linker.
614# @DESCRIPTION: 691# @DESCRIPTION:
615# DEPRECATED - Gets the flags needed for "NOW" binding 692# DEPRECATED - Gets the flags needed for "NOW" binding
616bindnow-flags() { 693bindnow-flags() {
617 ewarn "QA: stop using the bindnow-flags function ... simply drop it from your ebuild" 694 ewarn "QA: stop using the bindnow-flags function ... simply drop it from your ebuild" >&2
618 695
619 case $($(tc-getLD) -v 2>&1 </dev/null) in 696 case $($(tc-getLD) -v 2>&1 </dev/null) in
620 *GNU* | *'with BFD'*) # GNU ld 697 *GNU* | *'with BFD'*) # GNU ld
621 echo "-Wl,-z,now" ;; 698 echo "-Wl,-z,now" ;;
622 *Apple*) # Darwin ld 699 *Apple*) # Darwin ld

Legend:
Removed from v.1.121  
changed lines
  Added in v.1.124

  ViewVC Help
Powered by ViewVC 1.1.20