/[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.122 Revision 1.159
1# Copyright 1999-2008 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.122 2008/02/18 18:20:47 swegener Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.159 2011/12/07 06:42:40 vapier 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"
35 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all" 35 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all"
36 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking" 36 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-strict-overflow"
37 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time" 37 export ALLOWED_FLAGS="${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+" 38 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+"
39 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident" 39 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident -fpermissive"
40 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w" 40 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w"
41 fi 41 fi
42 # allow a bunch of flags that negate features / control ABI 42 # allow a bunch of flags that negate features / control ABI
43 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all \ 43 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all \
44 -fno-strict-aliasing -fno-bounds-checking" 44 -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer"
45 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ 45 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \
46 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \ 46 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 \
47 -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow \
48 -mno-popcnt -mno-abm \
47 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \ 49 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \
48 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 50 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
49 -mieee -mieee-with-inexact -mschedule \ 51 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \
50 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ 52 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \
51 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 53 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
52 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 54 -m32 -m64 -mx32 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
53 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \ 55 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \
54 -msecure-plt -D*" 56 -msecure-plt -m*-toc -D* -U*"
55 57
58 # 4.5
59 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fma4 -mno-movbe -mno-xop -mno-lwp"
60 # 4.6
61 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fsgsbase -mno-rdrnd -mno-f16c \
62 -mno-bmi -mno-tbm"
63
56 # C[XX]FLAGS that we are think is ok, but needs testing 64 # {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 65 # NOTE: currently -Os have issues with gcc3 and K6* arch's
58 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks" 66 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
59 return 0 67 return 0
60} 68}
61 69
71 -fPIC|-fpic|-fPIE|-fpie|-Wl,pie|-pie) 79 -fPIC|-fpic|-fPIE|-fpie|-Wl,pie|-pie)
72 gcc-specs-pie || continue 80 gcc-specs-pie || continue
73 is-flagq -nopie || append-flags -nopie;; 81 is-flagq -nopie || append-flags -nopie;;
74 -fstack-protector) 82 -fstack-protector)
75 gcc-specs-ssp || continue 83 gcc-specs-ssp || continue
76 is-flagq -fno-stack-protector || append-flags -fno-stack-protector;; 84 is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector);;
77 -fstack-protector-all) 85 -fstack-protector-all)
78 gcc-specs-ssp-to-all || continue 86 gcc-specs-ssp-to-all || continue
79 is-flagq -fno-stack-protector-all || append-flags -fno-stack-protector-all;; 87 is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all);;
88 -fno-strict-overflow)
89 gcc-specs-nostrict || continue
90 is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow);;
80 esac 91 esac
81 done 92 done
82} 93}
83 94
84# Remove occurrences of strings from variable given in $1 95# Remove occurrences of strings from variable given in $1
102} 113}
103 114
104# @FUNCTION: filter-flags 115# @FUNCTION: filter-flags
105# @USAGE: <flags> 116# @USAGE: <flags>
106# @DESCRIPTION: 117# @DESCRIPTION:
107# Remove particular <flags> from {C,CPP,CXX}FLAGS. Accepts shell globs. 118# Remove particular <flags> from {C,CPP,CXX,F,FC}FLAGS. Accepts shell globs.
108filter-flags() { 119filter-flags() {
109 _filter-hardened "$@" 120 _filter-hardened "$@"
110 _filter-var CFLAGS "$@" 121 _filter-var CFLAGS "$@"
111 _filter-var CPPFLAGS "$@" 122 _filter-var CPPFLAGS "$@"
112 _filter-var CXXFLAGS "$@" 123 _filter-var CXXFLAGS "$@"
124 _filter-var FFLAGS "$@"
125 _filter-var FCFLAGS "$@"
113 return 0 126 return 0
114} 127}
115 128
116# @FUNCTION: filter-lfs-flags 129# @FUNCTION: filter-lfs-flags
117# @DESCRIPTION: 130# @DESCRIPTION:
118# Remove flags that enable Large File Support. 131# Remove flags that enable Large File Support.
119filter-lfs-flags() { 132filter-lfs-flags() {
120 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments" 133 [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments"
134 # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html
135 # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...)
136 # _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)
121 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 138 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
122} 139}
123 140
124# @FUNCTION: append-cppflags 141# @FUNCTION: append-cppflags
125# @USAGE: <flags> 142# @USAGE: <flags>
126# @DESCRIPTION: 143# @DESCRIPTION:
127# Add extra <flags> to the current CPPFLAGS. 144# Add extra <flags> to the current CPPFLAGS.
128append-cppflags() { 145append-cppflags() {
129 [[ -z $* ]] && return 0 146 [[ $# -eq 0 ]] && return 0
130 export CPPFLAGS="${CPPFLAGS} $*" 147 export CPPFLAGS="${CPPFLAGS} $*"
148 return 0
149}
150
151# @FUNCTION: append-cflags
152# @USAGE: <flags>
153# @DESCRIPTION:
154# Add extra <flags> to the current CFLAGS.
155append-cflags() {
156 [[ $# -eq 0 ]] && return 0
157 export CFLAGS=$(test-flags-CC ${CFLAGS} "$@")
158 return 0
159}
160
161# @FUNCTION: append-cxxflags
162# @USAGE: <flags>
163# @DESCRIPTION:
164# Add extra <flags> to the current CXXFLAGS.
165append-cxxflags() {
166 [[ $# -eq 0 ]] && return 0
167 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@")
168 return 0
169}
170
171# @FUNCTION: append-fflags
172# @USAGE: <flags>
173# @DESCRIPTION:
174# Add extra <flags> to the current {F,FC}FLAGS.
175append-fflags() {
176 [[ $# -eq 0 ]] && return 0
177 export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@")
178 export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@")
131 return 0 179 return 0
132} 180}
133 181
134# @FUNCTION: append-lfs-flags 182# @FUNCTION: append-lfs-flags
135# @DESCRIPTION: 183# @DESCRIPTION:
136# Add flags that enable Large File Support. 184# Add flags that enable Large File Support.
137append-lfs-flags() { 185append-lfs-flags() {
138 [[ -n $@ ]] && die "append-lfs-flags takes no arguments" 186 [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments"
187 # see comments in filter-lfs-flags func for meaning of these
139 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 188 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
140} 189}
141 190
142# @FUNCTION: append-flags 191# @FUNCTION: append-flags
143# @USAGE: <flags> 192# @USAGE: <flags>
144# @DESCRIPTION: 193# @DESCRIPTION:
145# Add extra <flags> to your current C[XX]FLAGS. 194# Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
146append-flags() { 195append-flags() {
147 [[ -z $* ]] && return 0 196 [[ $# -eq 0 ]] && return 0
148 export CFLAGS="${CFLAGS} $*" 197 append-cflags "$@"
149 export CXXFLAGS="${CXXFLAGS} $*" 198 append-cxxflags "$@"
199 append-fflags "$@"
150 return 0 200 return 0
151} 201}
152 202
153# @FUNCTION: replace-flags 203# @FUNCTION: replace-flags
154# @USAGE: <old> <new> 204# @USAGE: <old> <new>
158 [[ $# != 2 ]] \ 208 [[ $# != 2 ]] \
159 && echo && eerror "Usage: replace-flags <old flag> <new flag>" \ 209 && echo && eerror "Usage: replace-flags <old flag> <new flag>" \
160 && die "replace-flags takes 2 arguments, not $#" 210 && die "replace-flags takes 2 arguments, not $#"
161 211
162 local f fset 212 local f fset
163 declare -a new_CFLAGS new_CXXFLAGS 213 declare -a new_CFLAGS new_CXXFLAGS new_FFLAGS new_FCFLAGS
164 214
165 for fset in CFLAGS CXXFLAGS; do 215 for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS; do
166 # Looping over the flags instead of using a global 216 # Looping over the flags instead of using a global
167 # substitution ensures that we're working with flag atoms. 217 # substitution ensures that we're working with flag atoms.
168 # Otherwise globs like -O* have the potential to wipe out the 218 # Otherwise globs like -O* have the potential to wipe out the
169 # list of flags. 219 # list of flags.
170 for f in ${!fset}; do 220 for f in ${!fset}; do
205} 255}
206 256
207# @FUNCTION: is-flagq 257# @FUNCTION: is-flagq
208# @USAGE: <flag> 258# @USAGE: <flag>
209# @DESCRIPTION: 259# @DESCRIPTION:
210# Returns shell true if <flag> is in C[XX]FLAGS, else returns shell false. Accepts shell globs. 260# Returns shell true if <flag> is in {C,CXX,F,FC}FLAGS, else returns shell false. Accepts shell globs.
211is-flagq() { 261is-flagq() {
212 [[ -n $2 ]] && die "Usage: is-flag <flag>" 262 [[ -n $2 ]] && die "Usage: is-flag <flag>"
213 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 263 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
214} 264}
215 265
216# @FUNCTION: is-flag 266# @FUNCTION: is-flag
217# @USAGE: <flag> 267# @USAGE: <flag>
218# @DESCRIPTION: 268# @DESCRIPTION:
219# Echo's "true" if flag is set in C[XX]FLAGS. Accepts shell globs. 269# Echo's "true" if flag is set in {C,CXX,F,FC}FLAGS. Accepts shell globs.
220is-flag() { 270is-flag() {
221 is-flagq "$@" && echo true 271 is-flagq "$@" && echo true
222} 272}
223 273
224# @FUNCTION: is-ldflagq 274# @FUNCTION: is-ldflagq
274 324
275# @FUNCTION: strip-flags 325# @FUNCTION: strip-flags
276# @DESCRIPTION: 326# @DESCRIPTION:
277# Strip C[XX]FLAGS of everything except known good/safe flags. 327# Strip C[XX]FLAGS of everything except known good/safe flags.
278strip-flags() { 328strip-flags() {
279 local x y flag NEW_CFLAGS NEW_CXXFLAGS 329 local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS
280 330
281 setup-allowed-flags 331 setup-allowed-flags
282 332
283 local NEW_CFLAGS="" 333 local NEW_CFLAGS=""
284 local NEW_CXXFLAGS="" 334 local NEW_CXXFLAGS=""
335 local NEW_FFLAGS=""
336 local NEW_FCFLAGS=""
285 337
286 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 338 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
287 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then 339 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
288 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 340 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
289 fi 341 fi
290 342
291 set -f # disable pathname expansion 343 set -f # disable pathname expansion
292 344
308 break 360 break
309 fi 361 fi
310 done 362 done
311 done 363 done
312 364
365 for x in ${FFLAGS}; do
366 for y in ${ALLOWED_FLAGS}; do
367 flag=${x%%=*}
368 if [ "${flag%%${y}}" = "" ] ; then
369 NEW_FFLAGS="${NEW_FFLAGS} ${x}"
370 break
371 fi
372 done
373 done
374
375 for x in ${FCFLAGS}; do
376 for y in ${ALLOWED_FLAGS}; do
377 flag=${x%%=*}
378 if [ "${flag%%${y}}" = "" ] ; then
379 NEW_FCFLAGS="${NEW_FCFLAGS} ${x}"
380 break
381 fi
382 done
383 done
384
313 # In case we filtered out all optimization flags fallback to -O2 385 # In case we filtered out all optimization flags fallback to -O2
314 if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then 386 if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
315 NEW_CFLAGS="${NEW_CFLAGS} -O2" 387 NEW_CFLAGS="${NEW_CFLAGS} -O2"
316 fi 388 fi
317 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then 389 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
318 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 390 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
319 fi 391 fi
392 if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
393 NEW_FFLAGS="${NEW_FFLAGS} -O2"
394 fi
395 if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
396 NEW_FCFLAGS="${NEW_FCFLAGS} -O2"
397 fi
320 398
321 set +f # re-enable pathname expansion 399 set +f # re-enable pathname expansion
322 400
323 export CFLAGS="${NEW_CFLAGS}" 401 export CFLAGS="${NEW_CFLAGS}"
324 export CXXFLAGS="${NEW_CXXFLAGS}" 402 export CXXFLAGS="${NEW_CXXFLAGS}"
403 export FFLAGS="${NEW_FFLAGS}"
404 export FCFLAGS="${NEW_FCFLAGS}"
325 return 0 405 return 0
326} 406}
327 407
328test-flag-PROG() { 408test-flag-PROG() {
329 local comp=$1 409 local comp=$1
330 local flags="$2" 410 local flags="$2"
331 411
332 [[ -z ${comp} || -z ${flags} ]] && \ 412 [[ -z ${comp} || -z ${flags} ]] && return 1
333 return 1
334 413
414 # use -c so we can test the assembler as well
335 local PROG=$(tc-get${comp}) 415 local PROG=$(tc-get${comp})
336 ${PROG} ${flags} -S -o /dev/null -xc /dev/null \ 416 ${PROG} ${flags} -c -o /dev/null -xc /dev/null \
337 > /dev/null 2>&1 417 > /dev/null 2>&1
338} 418}
339 419
340# @FUNCTION: test-flag-CC 420# @FUNCTION: test-flag-CC
341# @USAGE: <flag> 421# @USAGE: <flag>
346# @FUNCTION: test-flag-CXX 426# @FUNCTION: test-flag-CXX
347# @USAGE: <flag> 427# @USAGE: <flag>
348# @DESCRIPTION: 428# @DESCRIPTION:
349# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false. 429# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
350test-flag-CXX() { test-flag-PROG "CXX" "$1"; } 430test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
431
432# @FUNCTION: test-flag-F77
433# @USAGE: <flag>
434# @DESCRIPTION:
435# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
436test-flag-F77() { test-flag-PROG "F77" "$1"; }
437
438# @FUNCTION: test-flag-FC
439# @USAGE: <flag>
440# @DESCRIPTION:
441# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
442test-flag-FC() { test-flag-PROG "FC" "$1"; }
351 443
352test-flags-PROG() { 444test-flags-PROG() {
353 local comp=$1 445 local comp=$1
354 local flags 446 local flags
355 local x 447 local x
356 448
357 shift 449 shift
358 450
359 [[ -z ${comp} ]] && return 1 451 [[ -z ${comp} ]] && return 1
360 452
361 x=""
362 for x in "$@" ; do 453 for x in "$@" ; do
363 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}" 454 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
364 done 455 done
365 456
366 echo "${flags}" 457 echo "${flags}"
378# @FUNCTION: test-flags-CXX 469# @FUNCTION: test-flags-CXX
379# @USAGE: <flags> 470# @USAGE: <flags>
380# @DESCRIPTION: 471# @DESCRIPTION:
381# Returns shell true if <flags> are supported by the C++ compiler, else returns shell false. 472# Returns shell true if <flags> are supported by the C++ compiler, else returns shell false.
382test-flags-CXX() { test-flags-PROG "CXX" "$@"; } 473test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
474
475# @FUNCTION: test-flags-F77
476# @USAGE: <flags>
477# @DESCRIPTION:
478# Returns shell true if <flags> are supported by the Fortran 77 compiler, else returns shell false.
479test-flags-F77() { test-flags-PROG "F77" "$@"; }
480
481# @FUNCTION: test-flags-FC
482# @USAGE: <flags>
483# @DESCRIPTION:
484# Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false.
485test-flags-FC() { test-flags-PROG "FC" "$@"; }
383 486
384# @FUNCTION: test-flags 487# @FUNCTION: test-flags
385# @USAGE: <flags> 488# @USAGE: <flags>
386# @DESCRIPTION: 489# @DESCRIPTION:
387# Short-hand that should hopefully work for both C and C++ compiler, but 490# Short-hand that should hopefully work for both C and C++ compiler, but
388# its really only present due to the append-flags() abomination. 491# its really only present due to the append-flags() abomination.
389test-flags() { test-flags-CC "$@"; } 492test-flags() { test-flags-CC "$@"; }
390
391# @FUNCTION: test_flag
392# @DESCRIPTION:
393# DEPRICIATED, use test-flags()
394test_flag() {
395 ewarn "test_flag: deprecated, please use test-flags()!" >&2
396
397 test-flags-CC "$@"
398}
399 493
400# @FUNCTION: test_version_info 494# @FUNCTION: test_version_info
401# @USAGE: <version> 495# @USAGE: <version>
402# @DESCRIPTION: 496# @DESCRIPTION:
403# Returns shell true if the current C compiler version matches <version>, else returns shell false. 497# Returns shell true if the current C compiler version matches <version>, else returns shell false.
410 fi 504 fi
411} 505}
412 506
413# @FUNCTION: strip-unsupported-flags 507# @FUNCTION: strip-unsupported-flags
414# @DESCRIPTION: 508# @DESCRIPTION:
415# Strip C[XX]FLAGS of any flags not supported by the active toolchain. 509# Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain.
416strip-unsupported-flags() { 510strip-unsupported-flags() {
417 export CFLAGS=$(test-flags-CC ${CFLAGS}) 511 export CFLAGS=$(test-flags-CC ${CFLAGS})
418 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}) 512 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
513 export FFLAGS=$(test-flags-F77 ${FFLAGS})
514 export FCFLAGS=$(test-flags-FC ${FCFLAGS})
419} 515}
420 516
421# @FUNCTION: get-flag 517# @FUNCTION: get-flag
422# @USAGE: <flag> 518# @USAGE: <flag>
423# @DESCRIPTION: 519# @DESCRIPTION:
428 # this code looks a little flaky but seems to work for 524 # this code looks a little flaky but seems to work for
429 # everything we want ... 525 # everything we want ...
430 # for example, if CFLAGS="-march=i686": 526 # for example, if CFLAGS="-march=i686":
431 # `get-flag -march` == "-march=i686" 527 # `get-flag -march` == "-march=i686"
432 # `get-flag march` == "i686" 528 # `get-flag march` == "i686"
433 for f in ${CFLAGS} ${CXXFLAGS} ; do 529 for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS} ; do
434 if [ "${f/${findflag}}" != "${f}" ] ; then 530 if [ "${f/${findflag}}" != "${f}" ] ; then
435 printf "%s\n" "${f/-${findflag}=}" 531 printf "%s\n" "${f/-${findflag}=}"
436 return 0 532 return 0
437 fi 533 fi
438 done 534 done
439 return 1 535 return 1
440} 536}
441 537
442# @FUNCTION: has_hardened 538# DEAD FUNCS. Remove by Dec 2011.
443# @DESCRIPTION: 539test_flag() { die "$0: deprecated, please use test-flags()!" ; }
444# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs
445has_hardened() {
446 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" >&2 540has_hardened() { die "$0: deprecated, please use gcc-specs-{relro,now}()!" ; }
447
448 test_version_info Hardened && return 0
449 # The specs file wont exist unless gcc has GCC_SPECS support
450 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
451}
452
453# @FUNCTION: has_pic
454# @DESCRIPTION:
455# DEPRECATED - use gcc-specs-pie from toolchain-funcs
456# indicate whether PIC is set
457has_pic() {
458 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >&2 541has_pic() { die "$0: deprecated, please use gcc-specs-pie()!" ; }
459
460 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
461 ${CFLAGS/-fpic} != ${CFLAGS} ]] || \
462 gcc-specs-pie
463}
464
465# @FUNCTION: has_pie
466# @DESCRIPTION:
467# DEPRECATED - use gcc-specs-pie from toolchain-funcs
468# indicate whether PIE is set
469has_pie() {
470 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >&2 542has_pie() { die "$0: deprecated, please use gcc-specs-pie()!" ; }
471
472 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
473 ${CFLAGS/-fpie} != ${CFLAGS} ]] || \
474 gcc-specs-pie
475}
476
477# @FUNCTION: has_ssp_all
478# @DESCRIPTION:
479# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
480# indicate whether code for SSP is being generated for all functions
481has_ssp_all() {
482 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >&2 543has_ssp_all() { die "$0: deprecated, please use gcc-specs-ssp()!" ; }
483
484 # note; this matches only -fstack-protector-all
485 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
486 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
487 gcc-specs-ssp-all
488}
489
490# @FUNCTION: has_ssp
491# @DESCRIPTION:
492# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
493# indicate whether code for SSP is being generated
494has_ssp() {
495 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >&2 544has_ssp() { die "$0: deprecated, please use gcc-specs-ssp()!" ; }
496
497 # note; this matches both -fstack-protector and -fstack-protector-all
498 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
499 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
500 gcc-specs-ssp
501}
502 545
503# @FUNCTION: has_m64 546# @FUNCTION: has_m64
504# @DESCRIPTION: 547# @DESCRIPTION:
505# This doesn't test if the flag is accepted, it tests if the flag actually 548# This doesn't test if the flag is accepted, it tests if the flag actually
506# WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works 549# WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works
571 fi 614 fi
572 615
573 export CFLAGS CXXFLAGS 616 export CFLAGS CXXFLAGS
574} 617}
575 618
619# @FUNCTION: append-libs
620# @USAGE: <libs>
621# @DESCRIPTION:
622# Add extra <libs> to the current LIBS.
623append-libs() {
624 [[ $# -eq 0 ]] && return 0
625 local flag
626 for flag in "$@"; do
627 [[ ${flag} == -l* ]] && flag=${flag#-l}
628 export LIBS="${LIBS} -l${flag}"
629 done
630
631 return 0
632}
633
576# @FUNCTION: append-ldflags 634# @FUNCTION: append-ldflags
577# @USAGE: <flags> 635# @USAGE: <flags>
578# @DESCRIPTION: 636# @DESCRIPTION:
579# Add extra <flags> to the current LDFLAGS. 637# Add extra <flags> to the current LDFLAGS.
580append-ldflags() { 638append-ldflags() {
581 [[ -z $* ]] && return 0 639 [[ $# -eq 0 ]] && return 0
640 local flag
641 for flag in "$@"; do
642 [[ ${flag} == -l* ]] && \
643 ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
644 done
645
582 export LDFLAGS="${LDFLAGS} $*" 646 export LDFLAGS="${LDFLAGS} $*"
583 return 0 647 return 0
584} 648}
585 649
586# @FUNCTION: filter-ldflags 650# @FUNCTION: filter-ldflags
591 _filter-var LDFLAGS "$@" 655 _filter-var LDFLAGS "$@"
592 return 0 656 return 0
593} 657}
594 658
595# @FUNCTION: raw-ldflags 659# @FUNCTION: raw-ldflags
596# @USAGE: <flags> 660# @USAGE: [flags]
597# @DESCRIPTION: 661# @DESCRIPTION:
598# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results 662# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
599# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed 663# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed
600# to gcc where it needs the '-Wl,'. 664# to gcc where it needs the '-Wl,'.
665#
666# If no flags are specified, then default to ${LDFLAGS}.
601raw-ldflags() { 667raw-ldflags() {
602 local x input="$@" 668 local x input="$@"
603 [[ -z ${input} ]] && input=${LDFLAGS} 669 [[ -z ${input} ]] && input=${LDFLAGS}
604 set -- 670 set --
605 for x in ${input} ; do 671 for x in ${input} ; do
607 set -- "$@" ${x//,/ } 673 set -- "$@" ${x//,/ }
608 done 674 done
609 echo "$@" 675 echo "$@"
610} 676}
611 677
612# @FUNCTION: bindnow-flags 678# @FUNCTION: no-as-needed
613# @RETURN: Returns the flags to enable "now" binding in the current selected linker. 679# @RETURN: Flag to disable asneeded behavior for use with append-ldflags.
614# @DESCRIPTION: 680no-as-needed() {
615# DEPRECATED - Gets the flags needed for "NOW" binding
616bindnow-flags() {
617 ewarn "QA: stop using the bindnow-flags function ... simply drop it from your ebuild" >&2
618
619 case $($(tc-getLD) -v 2>&1 </dev/null) in 681 case $($(tc-getLD) -v 2>&1 </dev/null) in
620 *GNU* | *'with BFD'*) # GNU ld 682 *GNU*) # GNU ld
621 echo "-Wl,-z,now" ;; 683 echo "-Wl,--no-as-needed" ;;
622 *Apple*) # Darwin ld
623 echo "-bind_at_load" ;;
624 *)
625 # Some linkers just recognize -V instead of -v
626 case $($(tc-getLD) -V 2>&1 </dev/null) in
627 *Solaris*) # Solaris accept almost the same GNU options
628 echo "-Wl,-z,now" ;;
629 esac
630 ;;
631 esac 684 esac
632} 685}
633
634 686
635# Some tests for when we screw with things and want to make 687# Some tests for when we screw with things and want to make
636# sure we didn't break anything 688# sure we didn't break anything
637#TESTS() { 689#TESTS() {
638# CFLAGS="-a -b -c=1" 690# CFLAGS="-a -b -c=1"

Legend:
Removed from v.1.122  
changed lines
  Added in v.1.159

  ViewVC Help
Powered by ViewVC 1.1.20