Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/proj/prefix:master commit in: eclass/
Date: Tue, 04 May 2021 17:21:01
Message-Id: 1620148551.5b4bc212f92575f039a0a39aec988beae66f6701.grobian@gentoo
1 commit: 5b4bc212f92575f039a0a39aec988beae66f6701
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 4 17:15:51 2021 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Tue May 4 17:15:51 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=5b4bc212
7
8 eclass/flag-o-matic: drop from prefix
9
10 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
11
12 eclass/flag-o-matic.eclass | 776 ---------------------------------------------
13 1 file changed, 776 deletions(-)
14
15 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
16 deleted file mode 100644
17 index 20ee39d98b..0000000000
18 --- a/eclass/flag-o-matic.eclass
19 +++ /dev/null
20 @@ -1,776 +0,0 @@
21 -# Copyright 1999-2020 Gentoo Authors
22 -# Distributed under the terms of the GNU General Public License v2
23 -
24 -# @ECLASS: flag-o-matic.eclass
25 -# @MAINTAINER:
26 -# toolchain@g.o
27 -# @BLURB: common functions to manipulate and query toolchain flags
28 -# @DESCRIPTION:
29 -# This eclass contains a suite of functions to help developers sanely
30 -# and safely manage toolchain flags in their builds.
31 -
32 -if [[ -z ${_FLAG_O_MATIC_ECLASS} ]]; then
33 -_FLAG_O_MATIC_ECLASS=1
34 -
35 -inherit eutils toolchain-funcs multilib
36 -
37 -# Return all the flag variables that our high level funcs operate on.
38 -all-flag-vars() {
39 - echo {ADA,C,CPP,CXX,CCAS,F,FC,LD}FLAGS
40 -}
41 -
42 -# {C,CPP,CXX,CCAS,F,FC,LD}FLAGS that we allow in strip-flags
43 -# Note: shell globs and character lists are allowed
44 -setup-allowed-flags() {
45 - ALLOWED_FLAGS=(
46 - -pipe -O '-O[12sg]' -mcpu -march -mtune
47 - '-fstack-protector*' '-fsanitize*' '-fstack-check*' -fno-stack-check
48 - -fbounds-check -fbounds-checking -fno-strict-overflow
49 - -fno-PIE -fno-pie -nopie -no-pie -fno-unit-at-a-time
50 -
51 - # debugging symbols should generally be very safe to add
52 - -g '-g[0-9]'
53 - -ggdb '-ggdb[0-9]'
54 - -gdwarf '-gdwarf-*'
55 - -gstabs -gstabs+
56 - -gz
57 -
58 - -fno-ident -fpermissive -frecord-gcc-switches
59 - '-fdiagnostics*' '-fplugin*'
60 - '-W*' -w
61 -
62 - # CPPFLAGS and LDFLAGS
63 - '-[DUILR]*' '-Wl,*'
64 -
65 - # Linker choice flag
66 - '-fuse-ld'
67 - )
68 -
69 - # allow a bunch of flags that negate features / control ABI
70 - ALLOWED_FLAGS+=(
71 - '-fno-stack-protector*' '-fabi-version=*'
72 - -fno-strict-aliasing -fno-bounds-check -fno-bounds-checking -fstrict-overflow
73 - -fno-omit-frame-pointer '-fno-builtin*'
74 - )
75 - ALLOWED_FLAGS+=(
76 - -mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse
77 - -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2
78 - -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt
79 - -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt
80 - -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu
81 - -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe
82 - -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat
83 - -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi
84 - -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel
85 - -mstack-bias -mno-stack-bias -msecure-plt '-m*-toc' -mfloat-abi
86 - -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400
87 - -mfix-rm7000 -mno-fix-rm7000 -mfix-r10000 -mno-fix-r10000
88 - -mr10k-cache-barrier -mthumb -marm
89 -
90 - # gcc 4.5
91 - -mno-fma4 -mno-movbe -mno-xop -mno-lwp
92 - # gcc 4.6
93 - -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm
94 - # gcc 4.7
95 - -mno-avx2 -mno-bmi2 -mno-fma -mno-lzcnt
96 - # gcc 4.8
97 - -mno-fxsr -mno-hle -mno-rtm -mno-xsave -mno-xsaveopt
98 - # gcc 4.9
99 - -mno-avx512cd -mno-avx512er -mno-avx512f -mno-avx512pf -mno-sha
100 - )
101 -
102 - # Allow some safe individual flags. Should come along with the bug reference.
103 - ALLOWED_FLAGS+=(
104 - # Allow explicit stack realignment to run non-conformant
105 - # binaries: bug #677852
106 - -mstackrealign
107 - )
108 -}
109 -
110 -# inverted filters for hardened compiler. This is trying to unpick
111 -# the hardened compiler defaults.
112 -_filter-hardened() {
113 - local f
114 - for f in "$@" ; do
115 - case "${f}" in
116 - # Ideally we should only concern ourselves with PIE flags,
117 - # not -fPIC or -fpic, but too many places filter -fPIC without
118 - # thinking about -fPIE.
119 - -fPIC|-fpic|-fPIE|-fpie|-Wl,pie|-pie)
120 - gcc-specs-pie || continue
121 - if ! is-flagq -nopie && ! is-flagq -no-pie ; then
122 - # Support older Gentoo form first (-nopie) before falling
123 - # back to the official gcc-6+ form (-no-pie).
124 - if test-flags -nopie >/dev/null ; then
125 - append-flags -nopie
126 - else
127 - append-flags -no-pie
128 - fi
129 - fi
130 - ;;
131 - -fstack-protector)
132 - gcc-specs-ssp || continue
133 - is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector);;
134 - -fstack-protector-all)
135 - gcc-specs-ssp-to-all || continue
136 - is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all);;
137 - -fno-strict-overflow)
138 - gcc-specs-nostrict || continue
139 - is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow);;
140 - esac
141 - done
142 -}
143 -
144 -# Remove occurrences of strings from variable given in $1
145 -# Strings removed are matched as globs, so for example
146 -# '-O*' would remove -O1, -O2 etc.
147 -_filter-var() {
148 - local f x var=$1 new=()
149 - shift
150 -
151 - for f in ${!var} ; do
152 - for x in "$@" ; do
153 - # Note this should work with globs like -O*
154 - [[ ${f} == ${x} ]] && continue 2
155 - done
156 - new+=( "${f}" )
157 - done
158 - export ${var}="${new[*]}"
159 -}
160 -
161 -# @FUNCTION: filter-flags
162 -# @USAGE: <flags>
163 -# @DESCRIPTION:
164 -# Remove particular <flags> from {C,CPP,CXX,CCAS,F,FC,LD}FLAGS. Accepts shell globs.
165 -filter-flags() {
166 - _filter-hardened "$@"
167 - local v
168 - for v in $(all-flag-vars) ; do
169 - _filter-var ${v} "$@"
170 - done
171 - return 0
172 -}
173 -
174 -# @FUNCTION: filter-lfs-flags
175 -# @DESCRIPTION:
176 -# Remove flags that enable Large File Support.
177 -filter-lfs-flags() {
178 - [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments"
179 - # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html
180 - # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...)
181 - # _LARGEFILE64_SOURCE: enable support for 64bit variants (off64_t/fseeko64/etc...)
182 - # _FILE_OFFSET_BITS: default to 64bit variants (off_t is defined as off64_t)
183 - filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
184 -}
185 -
186 -# @FUNCTION: filter-ldflags
187 -# @USAGE: <flags>
188 -# @DESCRIPTION:
189 -# Remove particular <flags> from LDFLAGS. Accepts shell globs.
190 -filter-ldflags() {
191 - _filter-var LDFLAGS "$@"
192 - return 0
193 -}
194 -
195 -# @FUNCTION: append-cppflags
196 -# @USAGE: <flags>
197 -# @DESCRIPTION:
198 -# Add extra <flags> to the current CPPFLAGS.
199 -append-cppflags() {
200 - [[ $# -eq 0 ]] && return 0
201 - export CPPFLAGS+=" $*"
202 - return 0
203 -}
204 -
205 -# @FUNCTION: append-cflags
206 -# @USAGE: <flags>
207 -# @DESCRIPTION:
208 -# Add extra <flags> to the current CFLAGS. If a flag might not be supported
209 -# with different compilers (or versions), then use test-flags-CC like so:
210 -# @CODE
211 -# append-cflags $(test-flags-CC -funky-flag)
212 -# @CODE
213 -append-cflags() {
214 - [[ $# -eq 0 ]] && return 0
215 - # Do not do automatic flag testing ourselves. #417047
216 - export CFLAGS+=" $*"
217 - return 0
218 -}
219 -
220 -# @FUNCTION: append-cxxflags
221 -# @USAGE: <flags>
222 -# @DESCRIPTION:
223 -# Add extra <flags> to the current CXXFLAGS. If a flag might not be supported
224 -# with different compilers (or versions), then use test-flags-CXX like so:
225 -# @CODE
226 -# append-cxxflags $(test-flags-CXX -funky-flag)
227 -# @CODE
228 -append-cxxflags() {
229 - [[ $# -eq 0 ]] && return 0
230 - # Do not do automatic flag testing ourselves. #417047
231 - export CXXFLAGS+=" $*"
232 - return 0
233 -}
234 -
235 -# @FUNCTION: append-fflags
236 -# @USAGE: <flags>
237 -# @DESCRIPTION:
238 -# Add extra <flags> to the current {F,FC}FLAGS. If a flag might not be supported
239 -# with different compilers (or versions), then use test-flags-F77 like so:
240 -# @CODE
241 -# append-fflags $(test-flags-F77 -funky-flag)
242 -# @CODE
243 -append-fflags() {
244 - [[ $# -eq 0 ]] && return 0
245 - # Do not do automatic flag testing ourselves. #417047
246 - export FFLAGS+=" $*"
247 - export FCFLAGS+=" $*"
248 - return 0
249 -}
250 -
251 -# @FUNCTION: append-lfs-flags
252 -# @DESCRIPTION:
253 -# Add flags that enable Large File Support.
254 -append-lfs-flags() {
255 - [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments"
256 - # see comments in filter-lfs-flags func for meaning of these
257 - append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
258 -}
259 -
260 -# @FUNCTION: append-ldflags
261 -# @USAGE: <flags>
262 -# @DESCRIPTION:
263 -# Add extra <flags> to the current LDFLAGS.
264 -append-ldflags() {
265 - [[ $# -eq 0 ]] && return 0
266 - local flag
267 - for flag in "$@"; do
268 - [[ ${flag} == -l* ]] && \
269 - eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
270 - done
271 -
272 - export LDFLAGS="${LDFLAGS} $*"
273 - return 0
274 -}
275 -
276 -# @FUNCTION: append-flags
277 -# @USAGE: <flags>
278 -# @DESCRIPTION:
279 -# Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
280 -append-flags() {
281 - [[ $# -eq 0 ]] && return 0
282 - case " $* " in
283 - *' '-[DIU]*) eqawarn 'please use append-cppflags for preprocessor flags' ;;
284 - *' '-L*|\
285 - *' '-Wl,*) eqawarn 'please use append-ldflags for linker flags' ;;
286 - esac
287 - append-cflags "$@"
288 - append-cxxflags "$@"
289 - append-fflags "$@"
290 - return 0
291 -}
292 -
293 -# @FUNCTION: replace-flags
294 -# @USAGE: <old> <new>
295 -# @DESCRIPTION:
296 -# Replace the <old> flag with <new>. Accepts shell globs for <old>.
297 -replace-flags() {
298 - [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>"
299 -
300 - local f var new
301 - for var in $(all-flag-vars) ; do
302 - # Looping over the flags instead of using a global
303 - # substitution ensures that we're working with flag atoms.
304 - # Otherwise globs like -O* have the potential to wipe out the
305 - # list of flags.
306 - new=()
307 - for f in ${!var} ; do
308 - # Note this should work with globs like -O*
309 - [[ ${f} == ${1} ]] && f=${2}
310 - new+=( "${f}" )
311 - done
312 - export ${var}="${new[*]}"
313 - done
314 -
315 - return 0
316 -}
317 -
318 -# @FUNCTION: replace-cpu-flags
319 -# @USAGE: <old> <new>
320 -# @DESCRIPTION:
321 -# Replace cpu flags (like -march/-mcpu/-mtune) that select the <old> cpu
322 -# with flags that select the <new> cpu. Accepts shell globs for <old>.
323 -replace-cpu-flags() {
324 - local newcpu="$#" ; newcpu="${!newcpu}"
325 - while [ $# -gt 1 ] ; do
326 - # quote to make sure that no globbing is done (particularly on
327 - # ${oldcpu}) prior to calling replace-flags
328 - replace-flags "-march=${1}" "-march=${newcpu}"
329 - replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
330 - replace-flags "-mtune=${1}" "-mtune=${newcpu}"
331 - shift
332 - done
333 - return 0
334 -}
335 -
336 -_is_flagq() {
337 - local x var="$1[*]"
338 - for x in ${!var} ; do
339 - [[ ${x} == $2 ]] && return 0
340 - done
341 - return 1
342 -}
343 -
344 -# @FUNCTION: is-flagq
345 -# @USAGE: <flag>
346 -# @DESCRIPTION:
347 -# Returns shell true if <flag> is in {C,CXX,F,FC}FLAGS, else returns shell false. Accepts shell globs.
348 -is-flagq() {
349 - [[ -n $2 ]] && die "Usage: is-flag <flag>"
350 -
351 - local var
352 - for var in $(all-flag-vars) ; do
353 - _is_flagq ${var} "$1" && return 0
354 - done
355 - return 1
356 -}
357 -
358 -# @FUNCTION: is-flag
359 -# @USAGE: <flag>
360 -# @DESCRIPTION:
361 -# Echo's "true" if flag is set in {C,CXX,F,FC}FLAGS. Accepts shell globs.
362 -is-flag() {
363 - is-flagq "$@" && echo true
364 -}
365 -
366 -# @FUNCTION: is-ldflagq
367 -# @USAGE: <flag>
368 -# @DESCRIPTION:
369 -# Returns shell true if <flag> is in LDFLAGS, else returns shell false. Accepts shell globs.
370 -is-ldflagq() {
371 - [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
372 - _is_flagq LDFLAGS $1
373 -}
374 -
375 -# @FUNCTION: is-ldflag
376 -# @USAGE: <flag>
377 -# @DESCRIPTION:
378 -# Echo's "true" if flag is set in LDFLAGS. Accepts shell globs.
379 -is-ldflag() {
380 - is-ldflagq "$@" && echo true
381 -}
382 -
383 -# @FUNCTION: filter-mfpmath
384 -# @USAGE: <math types>
385 -# @DESCRIPTION:
386 -# Remove specified math types from the fpmath flag. For example, if the user
387 -# has -mfpmath=sse,386, running `filter-mfpmath sse` will leave the user with
388 -# -mfpmath=386.
389 -filter-mfpmath() {
390 - local orig_mfpmath new_math prune_math
391 -
392 - # save the original -mfpmath flag
393 - orig_mfpmath=$(get-flag -mfpmath)
394 - # get the value of the current -mfpmath flag
395 - new_math=$(get-flag mfpmath)
396 - # convert "both" to something we can filter
397 - new_math=${new_math/both/387,sse}
398 - new_math=" ${new_math//[,+]/ } "
399 - # figure out which math values are to be removed
400 - prune_math=""
401 - for prune_math in "$@" ; do
402 - new_math=${new_math/ ${prune_math} / }
403 - done
404 - new_math=$(echo ${new_math})
405 - new_math=${new_math// /,}
406 -
407 - if [[ -z ${new_math} ]] ; then
408 - # if we're removing all user specified math values are
409 - # slated for removal, then we just filter the flag
410 - filter-flags ${orig_mfpmath}
411 - else
412 - # if we only want to filter some of the user specified
413 - # math values, then we replace the current flag
414 - replace-flags ${orig_mfpmath} -mfpmath=${new_math}
415 - fi
416 - return 0
417 -}
418 -
419 -# @FUNCTION: strip-flags
420 -# @DESCRIPTION:
421 -# Strip *FLAGS of everything except known good/safe flags. This runs over all
422 -# flags returned by all_flag_vars().
423 -strip-flags() {
424 - [[ $# -ne 0 ]] && die "strip-flags takes no arguments"
425 - local x y var
426 -
427 - local ALLOWED_FLAGS
428 - setup-allowed-flags
429 -
430 - set -f # disable pathname expansion
431 -
432 - for var in $(all-flag-vars) ; do
433 - local new=()
434 -
435 - for x in ${!var} ; do
436 - local flag=${x%%=*}
437 - for y in "${ALLOWED_FLAGS[@]}" ; do
438 - if [[ -z ${flag%%${y}} ]] ; then
439 - new+=( "${x}" )
440 - break
441 - fi
442 - done
443 - done
444 -
445 - # In case we filtered out all optimization flags fallback to -O2
446 - if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*" ; then
447 - new+=( -O2 )
448 - fi
449 -
450 - if [[ ${!var} != "${new[*]}" ]] ; then
451 - einfo "strip-flags: ${var}: changed '${!var}' to '${new[*]}'"
452 - fi
453 - export ${var}="${new[*]}"
454 - done
455 -
456 - set +f # re-enable pathname expansion
457 -
458 - return 0
459 -}
460 -
461 -test-flag-PROG() {
462 - local comp=$1
463 - local lang=$2
464 - shift 2
465 -
466 - if [[ -z ${comp} ]]; then
467 - return 1
468 - fi
469 - if [[ -z $1 ]]; then
470 - return 1
471 - fi
472 -
473 - # verify selected compiler exists before using it
474 - comp=($(tc-get${comp}))
475 - # 'comp' can already contain compiler options.
476 - # 'type' needs a binary name
477 - if ! type -p ${comp[0]} >/dev/null; then
478 - return 1
479 - fi
480 -
481 - # Set up test file.
482 - local in_src in_ext cmdline_extra=()
483 - case "${lang}" in
484 - # compiler/assembler only
485 - c)
486 - in_ext='c'
487 - in_src='int main(void) { return 0; }'
488 - cmdline_extra+=(-xc -c)
489 - ;;
490 - c++)
491 - in_ext='cc'
492 - in_src='int main(void) { return 0; }'
493 - cmdline_extra+=(-xc++ -c)
494 - ;;
495 - f77)
496 - in_ext='f'
497 - # fixed source form
498 - in_src=' end'
499 - cmdline_extra+=(-xf77 -c)
500 - ;;
501 - f95)
502 - in_ext='f90'
503 - in_src='end'
504 - cmdline_extra+=(-xf95 -c)
505 - ;;
506 -
507 - # C compiler/assembler/linker
508 - c+ld)
509 - in_ext='c'
510 - in_src='int main(void) { return 0; }'
511 - cmdline_extra+=(-xc)
512 - ;;
513 - esac
514 - local test_in=${T}/test-flag.${in_ext}
515 - local test_out=${T}/test-flag.exe
516 -
517 - printf "%s\n" "${in_src}" > "${test_in}" || die "Failed to create '${test_in}'"
518 -
519 - # Currently we rely on warning-free output of a compiler
520 - # before the flag to see if a flag prduces any warnings.
521 - # This has a few drawbacks:
522 - # - if compiler already generates warnings we filter out
523 - # every single flag: bug #712488
524 - # - if user actually wants to see warnings we just strip
525 - # them regardless of warnings type.
526 - #
527 - # We can add more selective detection of no-op flags via
528 - # '-Werror=ignored-optimization-argument' and similar error options
529 - # similar to what we are doing with '-Qunused-arguments'.
530 - local cmdline=(
531 - "${comp[@]}"
532 - # Clang will warn about unknown gcc flags but exit 0.
533 - # Need -Werror to force it to exit non-zero.
534 - -Werror
535 - "$@"
536 - # -x<lang> options need to go before first source file
537 - "${cmdline_extra[@]}"
538 -
539 - "${test_in}" -o "${test_out}"
540 - )
541 -
542 - if ! "${cmdline[@]}" &>/dev/null; then
543 - # -Werror makes clang bail out on unused arguments as well;
544 - # try to add -Qunused-arguments to work-around that
545 - # other compilers don't support it but then, it's failure like
546 - # any other
547 - cmdline+=( -Qunused-arguments )
548 - "${cmdline[@]}" &>/dev/null
549 - fi
550 -}
551 -
552 -# @FUNCTION: test-flag-CC
553 -# @USAGE: <flag>
554 -# @DESCRIPTION:
555 -# Returns shell true if <flag> is supported by the C compiler, else returns shell false.
556 -test-flag-CC() { test-flag-PROG "CC" c "$@"; }
557 -
558 -# @FUNCTION: test-flag-CXX
559 -# @USAGE: <flag>
560 -# @DESCRIPTION:
561 -# Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
562 -test-flag-CXX() { test-flag-PROG "CXX" c++ "$@"; }
563 -
564 -# @FUNCTION: test-flag-F77
565 -# @USAGE: <flag>
566 -# @DESCRIPTION:
567 -# Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
568 -test-flag-F77() { test-flag-PROG "F77" f77 "$@"; }
569 -
570 -# @FUNCTION: test-flag-FC
571 -# @USAGE: <flag>
572 -# @DESCRIPTION:
573 -# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
574 -test-flag-FC() { test-flag-PROG "FC" f95 "$@"; }
575 -
576 -# @FUNCTION: test-flag-CCLD
577 -# @USAGE: <flag>
578 -# @DESCRIPTION:
579 -# Returns shell true if <flag> is supported by the C compiler and linker, else returns shell false.
580 -test-flag-CCLD() { test-flag-PROG "CC" c+ld "$@"; }
581 -
582 -test-flags-PROG() {
583 - local comp=$1
584 - local flags=()
585 - local x
586 -
587 - shift
588 -
589 - [[ -z ${comp} ]] && return 1
590 -
591 - while (( $# )); do
592 - case "$1" in
593 - # '-B /foo': bug # 687198
594 - --param|-B)
595 - if test-flag-${comp} "$1" "$2"; then
596 - flags+=( "$1" "$2" )
597 - fi
598 - shift 2
599 - ;;
600 - *)
601 - if test-flag-${comp} "$1"; then
602 - flags+=( "$1" )
603 - fi
604 - shift 1
605 - ;;
606 - esac
607 - done
608 -
609 - echo "${flags[*]}"
610 -
611 - # Just bail if we dont have any flags
612 - [[ ${#flags[@]} -gt 0 ]]
613 -}
614 -
615 -# @FUNCTION: test-flags-CC
616 -# @USAGE: <flags>
617 -# @DESCRIPTION:
618 -# Returns shell true if <flags> are supported by the C compiler, else returns shell false.
619 -test-flags-CC() { test-flags-PROG "CC" "$@"; }
620 -
621 -# @FUNCTION: test-flags-CXX
622 -# @USAGE: <flags>
623 -# @DESCRIPTION:
624 -# Returns shell true if <flags> are supported by the C++ compiler, else returns shell false.
625 -test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
626 -
627 -# @FUNCTION: test-flags-F77
628 -# @USAGE: <flags>
629 -# @DESCRIPTION:
630 -# Returns shell true if <flags> are supported by the Fortran 77 compiler, else returns shell false.
631 -test-flags-F77() { test-flags-PROG "F77" "$@"; }
632 -
633 -# @FUNCTION: test-flags-FC
634 -# @USAGE: <flags>
635 -# @DESCRIPTION:
636 -# Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false.
637 -test-flags-FC() { test-flags-PROG "FC" "$@"; }
638 -
639 -# @FUNCTION: test-flags-CCLD
640 -# @USAGE: <flags>
641 -# @DESCRIPTION:
642 -# Returns shell true if <flags> are supported by the C compiler and default linker, else returns shell false.
643 -test-flags-CCLD() { test-flags-PROG "CCLD" "$@"; }
644 -
645 -# @FUNCTION: test-flags
646 -# @USAGE: <flags>
647 -# @DESCRIPTION:
648 -# Short-hand that should hopefully work for both C and C++ compiler, but
649 -# its really only present due to the append-flags() abomination.
650 -test-flags() { test-flags-CC "$@"; }
651 -
652 -# @FUNCTION: test_version_info
653 -# @USAGE: <version>
654 -# @DESCRIPTION:
655 -# Returns shell true if the current C compiler version matches <version>, else returns shell false.
656 -# Accepts shell globs.
657 -test_version_info() {
658 - if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
659 - return 0
660 - else
661 - return 1
662 - fi
663 -}
664 -
665 -# @FUNCTION: strip-unsupported-flags
666 -# @DESCRIPTION:
667 -# Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain.
668 -strip-unsupported-flags() {
669 - [[ $# -ne 0 ]] && die "strip-unsupported-flags takes no arguments"
670 - export CFLAGS=$(test-flags-CC ${CFLAGS})
671 - export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
672 - export FFLAGS=$(test-flags-F77 ${FFLAGS})
673 - export FCFLAGS=$(test-flags-FC ${FCFLAGS})
674 - export LDFLAGS=$(test-flags-CCLD ${LDFLAGS})
675 -}
676 -
677 -# @FUNCTION: get-flag
678 -# @USAGE: <flag>
679 -# @DESCRIPTION:
680 -# Find and echo the value for a particular flag. Accepts shell globs.
681 -get-flag() {
682 - [[ $# -ne 1 ]] && die "usage: <flag>"
683 - local f var findflag="$1"
684 -
685 - # this code looks a little flaky but seems to work for
686 - # everything we want ...
687 - # for example, if CFLAGS="-march=i686":
688 - # `get-flag -march` == "-march=i686"
689 - # `get-flag march` == "i686"
690 - for var in $(all-flag-vars) ; do
691 - for f in ${!var} ; do
692 - if [ "${f/${findflag}}" != "${f}" ] ; then
693 - printf "%s\n" "${f/-${findflag}=}"
694 - return 0
695 - fi
696 - done
697 - done
698 - return 1
699 -}
700 -
701 -# @FUNCTION: replace-sparc64-flags
702 -# @DESCRIPTION:
703 -# Sets mcpu to v8 and uses the original value as mtune if none specified.
704 -replace-sparc64-flags() {
705 - [[ $# -ne 0 ]] && die "replace-sparc64-flags takes no arguments"
706 - local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
707 -
708 - if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
709 - for x in ${SPARC64_CPUS}; do
710 - CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
711 - done
712 - else
713 - for x in ${SPARC64_CPUS}; do
714 - CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
715 - done
716 - fi
717 -
718 - if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
719 - for x in ${SPARC64_CPUS}; do
720 - CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
721 - done
722 - else
723 - for x in ${SPARC64_CPUS}; do
724 - CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
725 - done
726 - fi
727 -
728 - export CFLAGS CXXFLAGS
729 -}
730 -
731 -# @FUNCTION: append-libs
732 -# @USAGE: <libs>
733 -# @DESCRIPTION:
734 -# Add extra <libs> to the current LIBS. All arguments should be prefixed with
735 -# either -l or -L. For compatibility, if arguments are not prefixed as
736 -# options, they are given a -l prefix automatically.
737 -append-libs() {
738 - [[ $# -eq 0 ]] && return 0
739 - local flag
740 - for flag in "$@"; do
741 - if [[ -z "${flag// }" ]]; then
742 - eqawarn "Appending an empty argument to LIBS is invalid! Skipping."
743 - continue
744 - fi
745 - case $flag in
746 - -[lL]*)
747 - export LIBS="${LIBS} ${flag}"
748 - ;;
749 - -*)
750 - eqawarn "Appending non-library to LIBS (${flag}); Other linker flags should be passed via LDFLAGS"
751 - export LIBS="${LIBS} ${flag}"
752 - ;;
753 - *)
754 - export LIBS="${LIBS} -l${flag}"
755 - esac
756 - done
757 -
758 - return 0
759 -}
760 -
761 -# @FUNCTION: raw-ldflags
762 -# @USAGE: [flags]
763 -# @DESCRIPTION:
764 -# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
765 -# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed
766 -# to gcc where it needs the '-Wl,'.
767 -#
768 -# If no flags are specified, then default to ${LDFLAGS}.
769 -raw-ldflags() {
770 - local x input="$@"
771 - [[ -z ${input} ]] && input=${LDFLAGS}
772 - set --
773 - for x in ${input} ; do
774 - case ${x} in
775 - -Wl,*)
776 - x=${x#-Wl,}
777 - set -- "$@" ${x//,/ }
778 - ;;
779 - *) # Assume it's a compiler driver flag, so throw it away #441808
780 - ;;
781 - esac
782 - done
783 - echo "$@"
784 -}
785 -
786 -# @FUNCTION: no-as-needed
787 -# @RETURN: Flag to disable asneeded behavior for use with append-ldflags.
788 -no-as-needed() {
789 - [[ $# -ne 0 ]] && die "no-as-needed takes no arguments"
790 - case $($(tc-getLD) -v 2>&1 </dev/null) in
791 - *GNU*) # GNU ld
792 - echo "-Wl,--no-as-needed" ;;
793 - esac
794 -}
795 -
796 -fi