/[gentoo-x86]/eclass/flag-o-matic.eclass
Gentoo

Contents of /eclass/flag-o-matic.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.174 - (hide annotations) (download)
Tue Jun 5 02:07:44 2012 UTC (2 years, 3 months ago) by dirtyepic
Branch: MAIN
Changes since 1.173: +3 -2 lines
Add -mfloat-abi=* to ALLOWED_FLAGS (bug #419615 by Hector Martin).

1 jlec 1.171 # Copyright 1999-2012 Gentoo Foundation
2 verwilst 1.1 # Distributed under the terms of the GNU General Public License v2
3 dirtyepic 1.174 # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.173 2012/05/31 00:29:06 vapier Exp $
4 vapier 1.121
5     # @ECLASS: flag-o-matic.eclass
6     # @MAINTAINER:
7     # toolchain@gentoo.org
8     # @BLURB: common functions to manipulate and query toolchain flags
9     # @DESCRIPTION:
10     # This eclass contains a suite of functions to help developers sanely
11     # and safely manage toolchain flags in their builds.
12 vapier 1.63
13 vapier 1.160 if [[ ${___ECLASS_ONCE_FLAG_O_MATIC} != "recur -_+^+_- spank" ]] ; then
14     ___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
15    
16 eradicator 1.80 inherit eutils toolchain-funcs multilib
17 vapier 1.72
18 vapier 1.167 # Return all the flag variables that our high level funcs operate on.
19     all-flag-vars() {
20 blueness 1.169 echo {C,CPP,CXX,CCAS,F,FC,LD}FLAGS
21 vapier 1.167 }
22    
23 dberkholz 1.124 # {C,CXX,F,FC}FLAGS that we allow in strip-flags
24 vapier 1.117 # Note: shell globs and character lists are allowed
25 vapier 1.36 setup-allowed-flags() {
26 dirtyepic 1.163 ALLOWED_FLAGS="-pipe"
27     ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune"
28     ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all"
29     ALLOWED_FLAGS+=" -fbounds-checking -fno-strict-overflow"
30     ALLOWED_FLAGS+=" -fno-PIE -fno-pie -fno-unit-at-a-time"
31     ALLOWED_FLAGS+=" -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+"
32     ALLOWED_FLAGS+=" -fno-ident -fpermissive"
33     ALLOWED_FLAGS+=" -W* -w"
34    
35 vapier 1.65 # allow a bunch of flags that negate features / control ABI
36 dirtyepic 1.163 ALLOWED_FLAGS+=" -fno-stack-protector -fno-stack-protector-all \
37     -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow \
38     -fno-omit-frame-pointer"
39     ALLOWED_FLAGS+=" -mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse \
40     -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 \
41     -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt \
42     -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \
43 vapier 1.87 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
44 dirtyepic 1.149 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \
45 dirtyepic 1.163 -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat \
46     -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi \
47     -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel \
48 dirtyepic 1.174 -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -mfloat-abi=* \
49     -D* -U*"
50 vapier 1.135
51 dirtyepic 1.148 # 4.5
52 dirtyepic 1.163 ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp"
53 dirtyepic 1.149 # 4.6
54 dirtyepic 1.163 ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm"
55 dirtyepic 1.148
56 dirtyepic 1.163 export ALLOWED_FLAGS
57 vapier 1.36 return 0
58 aliz 1.24 }
59 verwilst 1.13
60 kevquinn 1.105 # inverted filters for hardened compiler. This is trying to unpick
61     # the hardened compiler defaults.
62     _filter-hardened() {
63     local f
64     for f in "$@" ; do
65     case "${f}" in
66     # Ideally we should only concern ourselves with PIE flags,
67     # not -fPIC or -fpic, but too many places filter -fPIC without
68     # thinking about -fPIE.
69     -fPIC|-fpic|-fPIE|-fpie|-Wl,pie|-pie)
70     gcc-specs-pie || continue
71     is-flagq -nopie || append-flags -nopie;;
72     -fstack-protector)
73     gcc-specs-ssp || continue
74 gengor 1.131 is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector);;
75 kevquinn 1.105 -fstack-protector-all)
76     gcc-specs-ssp-to-all || continue
77 gengor 1.131 is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all);;
78 gengor 1.128 -fno-strict-overflow)
79     gcc-specs-nostrict || continue
80 gengor 1.131 is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow);;
81 solar 1.27 esac
82     done
83 kevquinn 1.105 }
84    
85     # Remove occurrences of strings from variable given in $1
86     # Strings removed are matched as globs, so for example
87     # '-O*' would remove -O1, -O2 etc.
88     _filter-var() {
89 vapier 1.167 local f x var=$1 new=()
90     shift
91 vapier 1.36
92 vapier 1.167 for f in ${!var} ; do
93     for x in "$@" ; do
94 kevquinn 1.105 # Note this should work with globs like -O*
95     [[ ${f} == ${x} ]] && continue 2
96 agriffis 1.61 done
97 vapier 1.167 new+=( "${f}" )
98 verwilst 1.1 done
99 vapier 1.167 eval export ${var}=\""${new[*]}"\"
100 kevquinn 1.105 }
101 agriffis 1.61
102 vapier 1.121 # @FUNCTION: filter-flags
103     # @USAGE: <flags>
104     # @DESCRIPTION:
105 blueness 1.169 # Remove particular <flags> from {C,CPP,CXX,CCAS,F,FC,LD}FLAGS. Accepts shell globs.
106 kevquinn 1.105 filter-flags() {
107     _filter-hardened "$@"
108 vapier 1.164 local v
109 vapier 1.167 for v in $(all-flag-vars) ; do
110     _filter-var ${v} "$@"
111 vapier 1.164 done
112 vapier 1.36 return 0
113 verwilst 1.2 }
114    
115 vapier 1.121 # @FUNCTION: filter-lfs-flags
116     # @DESCRIPTION:
117     # Remove flags that enable Large File Support.
118 vapier 1.40 filter-lfs-flags() {
119 vapier 1.154 [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments"
120 vapier 1.153 # http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html
121     # _LARGEFILE_SOURCE: enable support for new LFS funcs (ftello/etc...)
122     # _LARGEFILE64_SOURCE: enable support for 64bit variants (off64_t/fseeko64/etc...)
123     # _FILE_OFFSET_BITS: default to 64bit variants (off_t is defined as off64_t)
124 vapier 1.40 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
125     }
126    
127 jlec 1.171 # @FUNCTION: filter-ldflags
128     # @USAGE: <flags>
129     # @DESCRIPTION:
130     # Remove particular <flags> from LDFLAGS. Accepts shell globs.
131     filter-ldflags() {
132     _filter-var LDFLAGS "$@"
133     return 0
134     }
135    
136 vapier 1.121 # @FUNCTION: append-cppflags
137     # @USAGE: <flags>
138     # @DESCRIPTION:
139     # Add extra <flags> to the current CPPFLAGS.
140 vapier 1.118 append-cppflags() {
141 vapier 1.158 [[ $# -eq 0 ]] && return 0
142 vapier 1.118 export CPPFLAGS="${CPPFLAGS} $*"
143     return 0
144     }
145    
146 vapier 1.136 # @FUNCTION: append-cflags
147     # @USAGE: <flags>
148     # @DESCRIPTION:
149     # Add extra <flags> to the current CFLAGS.
150 mr_bones_ 1.137 append-cflags() {
151 vapier 1.158 [[ $# -eq 0 ]] && return 0
152     export CFLAGS=$(test-flags-CC ${CFLAGS} "$@")
153 vapier 1.136 return 0
154     }
155    
156 gengor 1.132 # @FUNCTION: append-cxxflags
157     # @USAGE: <flags>
158     # @DESCRIPTION:
159     # Add extra <flags> to the current CXXFLAGS.
160     append-cxxflags() {
161 vapier 1.158 [[ $# -eq 0 ]] && return 0
162     export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@")
163 gengor 1.132 return 0
164     }
165    
166 dberkholz 1.124 # @FUNCTION: append-fflags
167     # @USAGE: <flags>
168     # @DESCRIPTION:
169     # Add extra <flags> to the current {F,FC}FLAGS.
170     append-fflags() {
171 vapier 1.158 [[ $# -eq 0 ]] && return 0
172     export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@")
173     export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@")
174 dberkholz 1.124 return 0
175     }
176    
177 vapier 1.121 # @FUNCTION: append-lfs-flags
178     # @DESCRIPTION:
179     # Add flags that enable Large File Support.
180 vapier 1.48 append-lfs-flags() {
181 vapier 1.154 [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments"
182 vapier 1.155 # see comments in filter-lfs-flags func for meaning of these
183 vapier 1.118 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
184 vapier 1.48 }
185    
186 jlec 1.171 # @FUNCTION: append-ldflags
187     # @USAGE: <flags>
188     # @DESCRIPTION:
189     # Add extra <flags> to the current LDFLAGS.
190     append-ldflags() {
191     [[ $# -eq 0 ]] && return 0
192     local flag
193     for flag in "$@"; do
194     [[ ${flag} == -l* ]] && \
195     ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS"
196     done
197    
198     export LDFLAGS="${LDFLAGS} $*"
199     return 0
200     }
201    
202 vapier 1.121 # @FUNCTION: append-flags
203     # @USAGE: <flags>
204     # @DESCRIPTION:
205 dberkholz 1.124 # Add extra <flags> to your current {C,CXX,F,FC}FLAGS.
206 vapier 1.18 append-flags() {
207 vapier 1.158 [[ $# -eq 0 ]] && return 0
208 vapier 1.170 case " $* " in
209     *' '-[DIU]*) eqawarn 'please use append-cppflags for preprocessor flags' ;;
210 vapier 1.172 *' '-L*|\
211 vapier 1.173 *' '-Wl,*) eqawarn 'please use append-ldflags for linker flags' ;;
212 vapier 1.170 esac
213 vapier 1.136 append-cflags "$@"
214 vapier 1.138 append-cxxflags "$@"
215 vapier 1.136 append-fflags "$@"
216 vapier 1.28 return 0
217 verwilst 1.1 }
218    
219 vapier 1.121 # @FUNCTION: replace-flags
220     # @USAGE: <old> <new>
221     # @DESCRIPTION:
222     # Replace the <old> flag with <new>. Accepts shell globs for <old>.
223 vapier 1.18 replace-flags() {
224 vapier 1.167 [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>"
225 vapier 1.93
226 vapier 1.167 local f var new
227     for var in $(all-flag-vars) ; do
228 agriffis 1.64 # Looping over the flags instead of using a global
229     # substitution ensures that we're working with flag atoms.
230     # Otherwise globs like -O* have the potential to wipe out the
231     # list of flags.
232 vapier 1.167 new=()
233     for f in ${!var} ; do
234 agriffis 1.64 # Note this should work with globs like -O*
235     [[ ${f} == ${1} ]] && f=${2}
236 vapier 1.167 new+=( "${f}" )
237 agriffis 1.64 done
238 vapier 1.167 eval export ${var}=\""${new[*]}"\"
239 agriffis 1.64 done
240    
241 vapier 1.28 return 0
242 danarmak 1.7 }
243    
244 vapier 1.121 # @FUNCTION: replace-cpu-flags
245     # @USAGE: <old> <new>
246     # @DESCRIPTION:
247     # Replace cpu flags (like -march/-mcpu/-mtune) that select the <old> cpu
248     # with flags that select the <new> cpu. Accepts shell globs for <old>.
249 vapier 1.37 replace-cpu-flags() {
250 vapier 1.70 local newcpu="$#" ; newcpu="${!newcpu}"
251     while [ $# -gt 1 ] ; do
252 agriffis 1.64 # quote to make sure that no globbing is done (particularly on
253 vapier 1.113 # ${oldcpu}) prior to calling replace-flags
254 vapier 1.70 replace-flags "-march=${1}" "-march=${newcpu}"
255     replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
256     replace-flags "-mtune=${1}" "-mtune=${newcpu}"
257     shift
258 vapier 1.37 done
259     return 0
260     }
261    
262 vapier 1.113 _is_flagq() {
263 kevquinn 1.105 local x
264 vapier 1.113 for x in ${!1} ; do
265     [[ ${x} == $2 ]] && return 0
266 kevquinn 1.105 done
267     return 1
268     }
269    
270 vapier 1.121 # @FUNCTION: is-flagq
271     # @USAGE: <flag>
272     # @DESCRIPTION:
273 dberkholz 1.124 # Returns shell true if <flag> is in {C,CXX,F,FC}FLAGS, else returns shell false. Accepts shell globs.
274 vapier 1.113 is-flagq() {
275     [[ -n $2 ]] && die "Usage: is-flag <flag>"
276 vapier 1.167
277     local var
278     for var in $(all-flag-vars) ; do
279     _is_flagq ${var} "$1" && return 0
280     done
281     return 1
282 vapier 1.113 }
283    
284 vapier 1.121 # @FUNCTION: is-flag
285     # @USAGE: <flag>
286     # @DESCRIPTION:
287 dberkholz 1.124 # Echo's "true" if flag is set in {C,CXX,F,FC}FLAGS. Accepts shell globs.
288 danarmak 1.7 is-flag() {
289 vapier 1.113 is-flagq "$@" && echo true
290 kevquinn 1.105 }
291    
292 vapier 1.121 # @FUNCTION: is-ldflagq
293     # @USAGE: <flag>
294     # @DESCRIPTION:
295     # Returns shell true if <flag> is in LDFLAGS, else returns shell false. Accepts shell globs.
296 kevquinn 1.105 is-ldflagq() {
297 vapier 1.113 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
298     _is_flagq LDFLAGS $1
299 verwilst 1.1 }
300 azarah 1.8
301 vapier 1.121 # @FUNCTION: is-ldflag
302     # @USAGE: <flag>
303     # @DESCRIPTION:
304     # Echo's "true" if flag is set in LDFLAGS. Accepts shell globs.
305 kevquinn 1.105 is-ldflag() {
306 vapier 1.113 is-ldflagq "$@" && echo true
307 kevquinn 1.105 }
308    
309 vapier 1.121 # @FUNCTION: filter-mfpmath
310     # @USAGE: <math types>
311     # @DESCRIPTION:
312     # Remove specified math types from the fpmath flag. For example, if the user
313     # has -mfpmath=sse,386, running `filter-mfpmath sse` will leave the user with
314     # -mfpmath=386.
315 vapier 1.36 filter-mfpmath() {
316 agriffis 1.58 local orig_mfpmath new_math prune_math
317    
318 vapier 1.36 # save the original -mfpmath flag
319 vapier 1.109 orig_mfpmath=$(get-flag -mfpmath)
320 vapier 1.36 # get the value of the current -mfpmath flag
321 vapier 1.109 new_math=$(get-flag mfpmath)
322     new_math=" ${new_math//,/ } "
323 vapier 1.36 # figure out which math values are to be removed
324 agriffis 1.58 prune_math=""
325 vapier 1.36 for prune_math in "$@" ; do
326 vapier 1.109 new_math=${new_math/ ${prune_math} / }
327 vapier 1.36 done
328 vapier 1.109 new_math=$(echo ${new_math})
329     new_math=${new_math// /,}
330 vapier 1.36
331 vapier 1.109 if [[ -z ${new_math} ]] ; then
332 vapier 1.36 # if we're removing all user specified math values are
333     # slated for removal, then we just filter the flag
334     filter-flags ${orig_mfpmath}
335     else
336     # if we only want to filter some of the user specified
337     # math values, then we replace the current flag
338     replace-flags ${orig_mfpmath} -mfpmath=${new_math}
339     fi
340     return 0
341     }
342    
343 vapier 1.121 # @FUNCTION: strip-flags
344     # @DESCRIPTION:
345     # Strip C[XX]FLAGS of everything except known good/safe flags.
346 azarah 1.8 strip-flags() {
347 vapier 1.167 local x y var
348 agriffis 1.58
349 vapier 1.36 setup-allowed-flags
350    
351 agriffis 1.58 set -f # disable pathname expansion
352 azarah 1.8
353 vapier 1.167 for var in $(all-flag-vars) ; do
354     local new=()
355 azarah 1.8
356 vapier 1.167 for x in ${!var} ; do
357     local flag=${x%%=*}
358     for y in ${ALLOWED_FLAGS} ; do
359     if [[ -z ${flag%%${y}} ]] ; then
360     new+=( "${x}" )
361     break
362     fi
363     done
364 azarah 1.8 done
365 azarah 1.30
366 vapier 1.167 # In case we filtered out all optimization flags fallback to -O2
367     if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*" ; then
368     new+=( -O2 )
369     fi
370 dberkholz 1.124
371 vapier 1.167 eval export ${var}=\""${new[*]}"\"
372 dberkholz 1.124 done
373    
374 agriffis 1.58 set +f # re-enable pathname expansion
375 azarah 1.8
376 vapier 1.36 return 0
377 puggy 1.29 }
378    
379 azarah 1.96 test-flag-PROG() {
380     local comp=$1
381 vapier 1.168 local flag=$2
382 azarah 1.96
383 vapier 1.168 [[ -z ${comp} || -z ${flag} ]] && return 1
384 azarah 1.96
385 vapier 1.152 # use -c so we can test the assembler as well
386 azarah 1.96 local PROG=$(tc-get${comp})
387 vapier 1.168 ${PROG} "${flag}" -c -o /dev/null -xc /dev/null \
388 azarah 1.96 > /dev/null 2>&1
389     }
390    
391 vapier 1.121 # @FUNCTION: test-flag-CC
392     # @USAGE: <flag>
393     # @DESCRIPTION:
394     # Returns shell true if <flag> is supported by the C compiler, else returns shell false.
395 azarah 1.96 test-flag-CC() { test-flag-PROG "CC" "$1"; }
396    
397 vapier 1.121 # @FUNCTION: test-flag-CXX
398     # @USAGE: <flag>
399     # @DESCRIPTION:
400     # Returns shell true if <flag> is supported by the C++ compiler, else returns shell false.
401 azarah 1.96 test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
402    
403 dberkholz 1.124 # @FUNCTION: test-flag-F77
404     # @USAGE: <flag>
405     # @DESCRIPTION:
406     # Returns shell true if <flag> is supported by the Fortran 77 compiler, else returns shell false.
407     test-flag-F77() { test-flag-PROG "F77" "$1"; }
408    
409     # @FUNCTION: test-flag-FC
410     # @USAGE: <flag>
411     # @DESCRIPTION:
412     # Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
413     test-flag-FC() { test-flag-PROG "FC" "$1"; }
414    
415 azarah 1.99 test-flags-PROG() {
416     local comp=$1
417     local flags
418 azarah 1.96 local x
419 azarah 1.99
420     shift
421    
422 vapier 1.113 [[ -z ${comp} ]] && return 1
423 swegener 1.101
424 azarah 1.96 for x in "$@" ; do
425 vapier 1.113 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
426 azarah 1.96 done
427    
428 azarah 1.99 echo "${flags}"
429 azarah 1.96
430 azarah 1.99 # Just bail if we dont have any flags
431     [[ -n ${flags} ]]
432 azarah 1.96 }
433    
434 vapier 1.121 # @FUNCTION: test-flags-CC
435     # @USAGE: <flags>
436     # @DESCRIPTION:
437     # Returns shell true if <flags> are supported by the C compiler, else returns shell false.
438 azarah 1.99 test-flags-CC() { test-flags-PROG "CC" "$@"; }
439    
440 vapier 1.121 # @FUNCTION: test-flags-CXX
441     # @USAGE: <flags>
442     # @DESCRIPTION:
443     # Returns shell true if <flags> are supported by the C++ compiler, else returns shell false.
444 azarah 1.99 test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
445    
446 dberkholz 1.124 # @FUNCTION: test-flags-F77
447     # @USAGE: <flags>
448     # @DESCRIPTION:
449     # Returns shell true if <flags> are supported by the Fortran 77 compiler, else returns shell false.
450     test-flags-F77() { test-flags-PROG "F77" "$@"; }
451    
452     # @FUNCTION: test-flags-FC
453     # @USAGE: <flags>
454     # @DESCRIPTION:
455     # Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false.
456     test-flags-FC() { test-flags-PROG "FC" "$@"; }
457    
458 vapier 1.121 # @FUNCTION: test-flags
459     # @USAGE: <flags>
460     # @DESCRIPTION:
461 azarah 1.99 # Short-hand that should hopefully work for both C and C++ compiler, but
462 azarah 1.100 # its really only present due to the append-flags() abomination.
463 azarah 1.99 test-flags() { test-flags-CC "$@"; }
464    
465 vapier 1.121 # @FUNCTION: test_version_info
466     # @USAGE: <version>
467     # @DESCRIPTION:
468     # Returns shell true if the current C compiler version matches <version>, else returns shell false.
469     # Accepts shell globs.
470 agriffis 1.58 test_version_info() {
471 vapier 1.75 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
472 agriffis 1.58 return 0
473     else
474     return 1
475     fi
476     }
477    
478 vapier 1.121 # @FUNCTION: strip-unsupported-flags
479     # @DESCRIPTION:
480 dberkholz 1.124 # Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain.
481 puggy 1.29 strip-unsupported-flags() {
482 vapier 1.113 export CFLAGS=$(test-flags-CC ${CFLAGS})
483     export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
484 dberkholz 1.124 export FFLAGS=$(test-flags-F77 ${FFLAGS})
485     export FCFLAGS=$(test-flags-FC ${FCFLAGS})
486 azarah 1.8 }
487    
488 vapier 1.121 # @FUNCTION: get-flag
489     # @USAGE: <flag>
490     # @DESCRIPTION:
491     # Find and echo the value for a particular flag. Accepts shell globs.
492 vapier 1.10 get-flag() {
493 vapier 1.167 local f var findflag="$1"
494 agriffis 1.58
495 vapier 1.36 # this code looks a little flaky but seems to work for
496     # everything we want ...
497     # for example, if CFLAGS="-march=i686":
498 agriffis 1.58 # `get-flag -march` == "-march=i686"
499     # `get-flag march` == "i686"
500 vapier 1.167 for var in $(all-flag-vars) ; do
501     for f in ${!var} ; do
502     if [ "${f/${findflag}}" != "${f}" ] ; then
503     printf "%s\n" "${f/-${findflag}=}"
504     return 0
505     fi
506     done
507 vapier 1.10 done
508 vapier 1.28 return 1
509 joker 1.16 }
510    
511 vapier 1.121 # @FUNCTION: has_m64
512     # @DESCRIPTION:
513     # This doesn't test if the flag is accepted, it tests if the flag actually
514     # WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works
515     # return code is 0, else the return code is 1.
516 lv 1.56 has_m64() {
517 vapier 1.166 eqawarn "${FUNCNAME}: don't use this anymore"
518    
519 lv 1.62 # this doesnt test if the flag is accepted, it tests if the flag
520     # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
521     # please dont replace this function with test_flag in some future
522     # clean-up!
523 swegener 1.101
524 vapier 1.72 local temp="$(emktemp)"
525 azarah 1.96 echo "int main() { return(0); }" > "${temp}".c
526 kugelfang 1.74 MY_CC=$(tc-getCC)
527 azarah 1.96 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
528 vapier 1.72 local ret=$?
529 azarah 1.96 rm -f "${temp}".c
530     [[ ${ret} != 1 ]] && return 0
531 lv 1.62 return 1
532 lv 1.56 }
533    
534     has_m32() {
535 vapier 1.166 die "${FUNCNAME}: don't use this anymore"
536 lv 1.56 }
537    
538 vapier 1.121 # @FUNCTION: replace-sparc64-flags
539     # @DESCRIPTION:
540     # Sets mcpu to v8 and uses the original value as mtune if none specified.
541 vapier 1.18 replace-sparc64-flags() {
542 fmccor 1.98 local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
543 joker 1.16
544 mr_bones_ 1.83 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
545 agriffis 1.58 for x in ${SPARC64_CPUS}; do
546 joker 1.16 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
547     done
548 mr_bones_ 1.83 else
549 swegener 1.111 for x in ${SPARC64_CPUS}; do
550 joker 1.16 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
551     done
552     fi
553 mr_bones_ 1.83
554     if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
555 agriffis 1.58 for x in ${SPARC64_CPUS}; do
556 joker 1.16 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
557     done
558     else
559 swegener 1.111 for x in ${SPARC64_CPUS}; do
560 joker 1.16 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
561     done
562     fi
563 vapier 1.59
564     export CFLAGS CXXFLAGS
565 solar 1.27 }
566    
567 abcd 1.147 # @FUNCTION: append-libs
568     # @USAGE: <libs>
569     # @DESCRIPTION:
570     # Add extra <libs> to the current LIBS.
571     append-libs() {
572 vapier 1.158 [[ $# -eq 0 ]] && return 0
573 abcd 1.147 local flag
574     for flag in "$@"; do
575     [[ ${flag} == -l* ]] && flag=${flag#-l}
576     export LIBS="${LIBS} -l${flag}"
577     done
578    
579     return 0
580     }
581    
582 vapier 1.121 # @FUNCTION: raw-ldflags
583 vapier 1.156 # @USAGE: [flags]
584 vapier 1.121 # @DESCRIPTION:
585 kevquinn 1.105 # Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
586     # are suitable for passing directly to 'ld'; note LDFLAGS is usually passed
587     # to gcc where it needs the '-Wl,'.
588 vapier 1.156 #
589     # If no flags are specified, then default to ${LDFLAGS}.
590 vapier 1.102 raw-ldflags() {
591     local x input="$@"
592     [[ -z ${input} ]] && input=${LDFLAGS}
593     set --
594     for x in ${input} ; do
595 vapier 1.103 x=${x#-Wl,}
596     set -- "$@" ${x//,/ }
597 vapier 1.102 done
598     echo "$@"
599     }
600    
601 ssuominen 1.145 # @FUNCTION: no-as-needed
602     # @RETURN: Flag to disable asneeded behavior for use with append-ldflags.
603     no-as-needed() {
604     case $($(tc-getLD) -v 2>&1 </dev/null) in
605     *GNU*) # GNU ld
606     echo "-Wl,--no-as-needed" ;;
607     esac
608     }
609 vapier 1.113
610 vapier 1.160 fi

  ViewVC Help
Powered by ViewVC 1.1.20