/[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.73 Revision 1.113
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2006 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.73 2004/10/13 14:11:52 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.113 2006/11/15 22:46:52 vapier Exp $
4# 4#
5# Author Bart Verwilst <verwilst@gentoo.org> 5# Maintainer: base-system@gentoo.org
6
7ECLASS=flag-o-matic
8INHERITED="$INHERITED $ECLASS"
9
10# Please leave ${IUSE} in this until portage .51 is stable, otherwise
11# IUSE gets clobbered.
12IUSE="${IUSE} debug"
13 6
14# need access to emktemp() 7# need access to emktemp()
15inherit eutils 8inherit eutils toolchain-funcs multilib
16 9
17# 10#
18#### filter-flags <flags> #### 11#### filter-flags <flags> ####
19# Remove particular flags from C[XX]FLAGS 12# Remove particular flags from C[XX]FLAGS
20# Matches only complete flags 13# Matches only complete flags
27# 20#
28#### replace-cpu-flags <old.cpus> <new.cpu> ### 21#### replace-cpu-flags <old.cpus> <new.cpu> ###
29# Replace march/mcpu flags that specify <old.cpus> 22# Replace march/mcpu flags that specify <old.cpus>
30# with flags that specify <new.cpu> 23# with flags that specify <new.cpu>
31# 24#
32#### is-flag <flag> #### 25#### is-flag[q] <flag> ####
33# Returns "true" if flag is set in C[XX]FLAGS 26# Returns "true" if flag is set in C[XX]FLAGS
34# Matches only complete a flag 27# Matches only complete a flag
28# q version sets return code but doesn't echo
29#
30#### is-ldflag[q] <flag> ####
31# Returns "true" if flag is set in LDFLAGS
32# Matches only complete a flag
33# q version sets return code but doesn't echo
35# 34#
36#### strip-flags #### 35#### strip-flags ####
37# Strip C[XX]FLAGS of everything except known 36# Strip C[XX]FLAGS of everything except known
38# good options. 37# good options.
39# 38#
58# 57#
59#### filter-ldflags <flags> #### 58#### filter-ldflags <flags> ####
60# Remove particular flags from LDFLAGS 59# Remove particular flags from LDFLAGS
61# Matches only complete flags 60# Matches only complete flags
62# 61#
63#### etexec-flags #### 62#### bindnow-flags ####
64# hooked function for hardened gcc that appends 63# Returns the flags to enable "now" binding in the current selected linker.
65# -fno-pic to {C,CXX,LD}FLAGS
66# when a package is filtering -fpic, -fPIC, -fpie, -fPIE
67# 64#
68#### fstack-flags #### 65################ DEPRECATED functions ################
69# hooked function for hardened gcc that appends 66# The following are still present to avoid breaking existing
70# -fno-stack-protector to {C,CXX,LD}FLAGS 67# code more than necessary; however they are deprecated. Please
71# when a package is filtering -fstack-protector, -fstack-protector-all 68# use gcc-specs-* from toolchain-funcs.eclass instead, if you
72# notice: modern automatic specs files will also suppress -fstack-protector-all 69# need to know which hardened techs are active in the compiler.
73# when only -fno-stack-protector is given 70# See bug #100974
71#
72#### has_hardened ####
73# Returns true if the compiler has 'Hardened' in its version string,
74# (note; switched-spec vanilla compilers satisfy this condition) or
75# the specs file name contains 'hardened'.
76#
77#### has_pie ####
78# Returns true if the compiler by default or with current CFLAGS
79# builds position-independent code.
80#
81#### has_pic ####
82# Returns true if the compiler by default or with current CFLAGS
83# builds position-independent code.
84#
85#### has_ssp_all ####
86# Returns true if the compiler by default or with current CFLAGS
87# generates stack smash protections for all functions
88#
89#### has_ssp ####
90# Returns true if the compiler by default or with current CFLAGS
91# generates stack smash protections for most vulnerable functions
74# 92#
75 93
76# C[XX]FLAGS that we allow in strip-flags 94# C[XX]FLAGS that we allow in strip-flags
77setup-allowed-flags() { 95setup-allowed-flags() {
78 if [ -z "${ALLOWED_FLAGS}" ] ; then 96 if [[ -z ${ALLOWED_FLAGS} ]] ; then
79 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-stack-protector -fno-pie -fno-unit-at-a-time -pipe -g" 97 export ALLOWED_FLAGS="-pipe"
80 case "${ARCH}" in 98 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
81 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;; 99 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all"
82 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 100 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-bounds-checking"
83 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 101 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time"
84 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 102 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3"
85 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 103 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident"
86 esac
87 fi 104 fi
88 # allow a bunch of flags that negate features / control ABI 105 # allow a bunch of flags that negate features / control ABI
89 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" 106 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
90 case "${ARCH}" in 107 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \
91 x86|amd64|ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" ;; 108 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \
92 esac 109 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \
93 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs -msoft-float -mflat -mno-faster-structs -mfaster-structs -mlittle-endian -mbig-endian -mlive-g0 -mcmodel -mno-stack-bias -mstack-bias" 110 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
111 -mieee -mieee-with-inexact -mschedule \
112 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \
113 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
114 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
115 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias"
94 116
95 # C[XX]FLAGS that we are think is ok, but needs testing 117 # C[XX]FLAGS that we are think is ok, but needs testing
96 # NOTE: currently -Os have issues with gcc3 and K6* arch's 118 # NOTE: currently -Os have issues with gcc3 and K6* arch's
97 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 119 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
98 return 0 120 return 0
121}
122
123# inverted filters for hardened compiler. This is trying to unpick
124# the hardened compiler defaults.
125_filter-hardened() {
126 local f
127 for f in "$@" ; do
128 case "${f}" in
129 # Ideally we should only concern ourselves with PIE flags,
130 # not -fPIC or -fpic, but too many places filter -fPIC without
131 # thinking about -fPIE.
132 -fPIC|-fpic|-fPIE|-fpie|-Wl,pie|-pie)
133 gcc-specs-pie || continue
134 is-flagq -nopie || append-flags -nopie;;
135 -fstack-protector)
136 gcc-specs-ssp || continue
137 is-flagq -fno-stack-protector || append-flags -fno-stack-protector;;
138 -fstack-protector-all)
139 gcc-specs-ssp-to-all || continue
140 is-flagq -fno-stack-protector-all || append-flags -fno-stack-protector-all;;
141 esac
142 done
143}
144
145# Remove occurrences of strings from variable given in $1
146# Strings removed are matched as globs, so for example
147# '-O*' would remove -O1, -O2 etc.
148_filter-var() {
149 local f x VAR VAL
150 declare -a new
151
152 VAR=$1
153 shift
154 eval VAL=\${${VAR}}
155 for f in ${VAL}; do
156 for x in "$@"; do
157 # Note this should work with globs like -O*
158 [[ ${f} == ${x} ]] && continue 2
159 done
160 eval new\[\${\#new\[@]}]=\${f}
161 done
162 eval export ${VAR}=\${new\[*]}
99} 163}
100 164
101filter-flags() { 165filter-flags() {
102 local x f fset 166 _filter-hardened "$@"
103 declare -a new_CFLAGS new_CXXFLAGS 167 _filter-var CFLAGS "$@"
104 168 _filter-var CXXFLAGS "$@"
105 for x in "$@" ; do
106 case "${x}" in
107 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
108 -fstack-protector|-fstack-protector-all) fstack-flags;;
109 esac
110 done
111
112 for fset in CFLAGS CXXFLAGS; do
113 # Looping over the flags instead of using a global
114 # substitution ensures that we're working with flag atoms.
115 # Otherwise globs like -O* have the potential to wipe out the
116 # list of flags.
117 for f in ${!fset}; do
118 for x in "$@"; do
119 # Note this should work with globs like -O*
120 [[ ${f} == ${x} ]] && continue 2
121 done
122 eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
123 done
124 eval export ${fset}=\${new_${fset}\[*]}
125 done
126
127 return 0 169 return 0
128} 170}
129 171
130filter-lfs-flags() { 172filter-lfs-flags() {
173 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments"
131 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 174 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
132} 175}
133 176
134append-lfs-flags() { 177append-lfs-flags() {
178 [[ -n $@ ]] && die "append-lfs-flags takes no arguments"
135 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 179 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
136} 180}
137 181
138append-flags() { 182append-flags() {
183 [[ -z $* ]] && return 0
139 export CFLAGS="${CFLAGS} $*" 184 export CFLAGS="${CFLAGS} $*"
140 export CXXFLAGS="${CXXFLAGS} $*" 185 export CXXFLAGS="${CXXFLAGS} $*"
141 [ -n "`is-flag -fno-stack-protector`" -o \
142 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
143 return 0 186 return 0
144} 187}
145 188
146replace-flags() { 189replace-flags() {
190 [[ $# != 2 ]] \
191 && echo && eerror "Usage: replace-flags <old flag> <new flag>" \
192 && die "replace-flags takes 2 arguments, not $#"
193
147 local f fset 194 local f fset
148 declare -a new_CFLAGS new_CXXFLAGS 195 declare -a new_CFLAGS new_CXXFLAGS
149 196
150 for fset in CFLAGS CXXFLAGS; do 197 for fset in CFLAGS CXXFLAGS; do
151 # Looping over the flags instead of using a global 198 # Looping over the flags instead of using a global
152 # substitution ensures that we're working with flag atoms. 199 # substitution ensures that we're working with flag atoms.
165 212
166replace-cpu-flags() { 213replace-cpu-flags() {
167 local newcpu="$#" ; newcpu="${!newcpu}" 214 local newcpu="$#" ; newcpu="${!newcpu}"
168 while [ $# -gt 1 ] ; do 215 while [ $# -gt 1 ] ; do
169 # quote to make sure that no globbing is done (particularly on 216 # quote to make sure that no globbing is done (particularly on
170 # ${oldcpu} prior to calling replace-flags 217 # ${oldcpu}) prior to calling replace-flags
171 replace-flags "-march=${1}" "-march=${newcpu}" 218 replace-flags "-march=${1}" "-march=${newcpu}"
172 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}" 219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
173 replace-flags "-mtune=${1}" "-mtune=${newcpu}" 220 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
174 shift 221 shift
175 done 222 done
176 return 0 223 return 0
177} 224}
178 225
226_is_flagq() {
227 local x
228 for x in ${!1} ; do
229 [[ ${x} == $2 ]] && return 0
230 done
231 return 1
232}
233
234is-flagq() {
235 [[ -n $2 ]] && die "Usage: is-flag <flag>"
236 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1
237}
238
179is-flag() { 239is-flag() {
180 local x 240 is-flagq "$@" && echo true
241}
181 242
182 for x in ${CFLAGS} ${CXXFLAGS} ; do 243is-ldflagq() {
183 # Note this should work with globs like -mcpu=ultrasparc* 244 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
184 if [[ ${x} == ${1} ]]; then 245 _is_flagq LDFLAGS $1
185 echo true 246}
186 return 0 247
187 fi 248is-ldflag() {
188 done 249 is-ldflagq "$@" && echo true
189 return 1
190} 250}
191 251
192filter-mfpmath() { 252filter-mfpmath() {
193 local orig_mfpmath new_math prune_math 253 local orig_mfpmath new_math prune_math
194 254
195 # save the original -mfpmath flag 255 # save the original -mfpmath flag
196 orig_mfpmath="`get-flag -mfpmath`" 256 orig_mfpmath=$(get-flag -mfpmath)
197 # get the value of the current -mfpmath flag 257 # get the value of the current -mfpmath flag
198 new_math=" `get-flag mfpmath | tr , ' '` " 258 new_math=$(get-flag mfpmath)
259 new_math=" ${new_math//,/ } "
199 # figure out which math values are to be removed 260 # figure out which math values are to be removed
200 prune_math="" 261 prune_math=""
201 for prune_math in "$@" ; do 262 for prune_math in "$@" ; do
202 new_math="${new_math/ ${prune_math} / }" 263 new_math=${new_math/ ${prune_math} / }
203 done 264 done
204 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" 265 new_math=$(echo ${new_math})
266 new_math=${new_math// /,}
205 267
206 if [ -z "${new_math}" ] ; then 268 if [[ -z ${new_math} ]] ; then
207 # if we're removing all user specified math values are 269 # if we're removing all user specified math values are
208 # slated for removal, then we just filter the flag 270 # slated for removal, then we just filter the flag
209 filter-flags ${orig_mfpmath} 271 filter-flags ${orig_mfpmath}
210 else 272 else
211 # if we only want to filter some of the user specified 273 # if we only want to filter some of the user specified
222 284
223 local NEW_CFLAGS="" 285 local NEW_CFLAGS=""
224 local NEW_CXXFLAGS="" 286 local NEW_CXXFLAGS=""
225 287
226 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 288 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
227 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then 289 if has ~$(tc-arch) ${ACCEPT_KEYWORDS} ; then
228 use debug && einfo "Enabling the use of some unstable flags"
229 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 290 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
230 fi 291 fi
231 292
232 set -f # disable pathname expansion 293 set -f # disable pathname expansion
233 294
264 export CFLAGS="${NEW_CFLAGS}" 325 export CFLAGS="${NEW_CFLAGS}"
265 export CXXFLAGS="${NEW_CXXFLAGS}" 326 export CXXFLAGS="${NEW_CXXFLAGS}"
266 return 0 327 return 0
267} 328}
268 329
330test-flag-PROG() {
331 local comp=$1
332 local flags="$2"
333
334 [[ -z ${comp} || -z ${flags} ]] && \
335 return 1
336
337 local PROG=$(tc-get${comp})
338 ${PROG} ${flags} -S -o /dev/null -xc /dev/null \
339 > /dev/null 2>&1
340}
341
342# Returns true if C compiler support given flag
343test-flag-CC() { test-flag-PROG "CC" "$1"; }
344
345# Returns true if C++ compiler support given flag
346test-flag-CXX() { test-flag-PROG "CXX" "$1"; }
347
348test-flags-PROG() {
349 local comp=$1
350 local flags
351 local x
352
353 shift
354
355 [[ -z ${comp} ]] && return 1
356
357 x=""
358 for x in "$@" ; do
359 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
360 done
361
362 echo "${flags}"
363
364 # Just bail if we dont have any flags
365 [[ -n ${flags} ]]
366}
367
368# Returns (echo's) the given flags supported by the C compiler
369test-flags-CC() { test-flags-PROG "CC" "$@"; }
370
371# Returns (echo's) the given flags supported by the C++ compiler
372test-flags-CXX() { test-flags-PROG "CXX" "$@"; }
373
374# Short-hand that should hopefully work for both C and C++ compiler, but
375# its really only present due to the append-flags() abomination.
376test-flags() { test-flags-CC "$@"; }
377
378# Depriciated, use test-flags()
269test_flag() { 379test_flag() {
270 local cc=${CC:-gcc} ; cc=${cc%% *} 380 ewarn "test_flag: deprecated, please use test-flags()!" >&2
271 if ${cc} -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then 381
272 printf "%s\n" "$*" 382 test-flags-CC "$@"
273 return 0
274 fi
275 return 1
276} 383}
277 384
278test_version_info() { 385test_version_info() {
279 local cc=${CC:-gcc} ; cc=${cc%% *}
280 if [[ $(${cc} --version 2>&1) == *$1* ]]; then 386 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
281 return 0 387 return 0
282 else 388 else
283 return 1 389 return 1
284 fi 390 fi
285} 391}
286 392
287strip-unsupported-flags() { 393strip-unsupported-flags() {
288 local NEW_CFLAGS NEW_CXXFLAGS 394 export CFLAGS=$(test-flags-CC ${CFLAGS})
289 395 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
290 for x in ${CFLAGS} ; do
291 NEW_CFLAGS="${NEW_CFLAGS} `test_flag ${x}`"
292 done
293 for x in ${CXXFLAGS} ; do
294 NEW_CXXFLAGS="${NEW_CXXFLAGS} `test_flag ${x}`"
295 done
296
297 export CFLAGS="${NEW_CFLAGS}"
298 export CXXFLAGS="${NEW_CXXFLAGS}"
299} 396}
300 397
301get-flag() { 398get-flag() {
302 local f findflag="$1" 399 local f findflag="$1"
303 400
313 fi 410 fi
314 done 411 done
315 return 1 412 return 1
316} 413}
317 414
415# DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs
318has_hardened() { 416has_hardened() {
417 ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" >&2
418
319 test_version_info Hardened && return 0 419 test_version_info Hardened && return 0
320 # the specs file wont exist unless gcc has GCC_SPECS support 420 # The specs file wont exist unless gcc has GCC_SPECS support
321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 421 [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
322 return 0
323 return 1
324} 422}
325 423
424# DEPRECATED - use gcc-specs-pie from toolchain-funcs
425# indicate whether PIC is set
326has_pic() { 426has_pic() {
327 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 427 ewarn "has_pic: deprecated, please use gcc-specs-pie()!" >&2
328 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
329 test_version_info pie && return 0
330 return 1
331}
332 428
429 [[ ${CFLAGS/-fPIC} != ${CFLAGS} || \
430 ${CFLAGS/-fpic} != ${CFLAGS} ]] || \
431 gcc-specs-pie
432}
433
434# DEPRECATED - use gcc-specs-pie from toolchain-funcs
435# indicate whether PIE is set
333has_pie() { 436has_pie() {
334 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 437 ewarn "has_pie: deprecated, please use gcc-specs-pie()!" >&2
335 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 438
336 test_version_info pie && return 0 439 [[ ${CFLAGS/-fPIE} != ${CFLAGS} || \
337 return 1 440 ${CFLAGS/-fpie} != ${CFLAGS} ]] || \
441 gcc-specs-pie
338} 442}
339 443
444# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
445# indicate whether code for SSP is being generated for all functions
446has_ssp_all() {
447 ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" >&2
448
449 # note; this matches only -fstack-protector-all
450 [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || \
451 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || \
452 gcc-specs-ssp-all
453}
454
455# DEPRECATED - use gcc-specs-ssp from toolchain-funcs
456# indicate whether code for SSP is being generated
340has_ssp() { 457has_ssp() {
458 ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" >&2
459
460 # note; this matches both -fstack-protector and -fstack-protector-all
341 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 461 [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || \
342 test_version_info ssp && return 0 462 -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || \
343 return 1 463 gcc-specs-ssp
344} 464}
345 465
346has_m64() { 466has_m64() {
347 # this doesnt test if the flag is accepted, it tests if the flag 467 # this doesnt test if the flag is accepted, it tests if the flag
348 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 468 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
349 # please dont replace this function with test_flag in some future 469 # please dont replace this function with test_flag in some future
350 # clean-up! 470 # clean-up!
471
351 local temp="$(emktemp)" 472 local temp="$(emktemp)"
352 echo "int main() { return(0); }" > ${temp}.c 473 echo "int main() { return(0); }" > "${temp}".c
474 MY_CC=$(tc-getCC)
353 ${CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 475 ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
354 local ret=$? 476 local ret=$?
355 rm -f ${temp}.c 477 rm -f "${temp}".c
356 [ "$ret" != "1" ] && return 0 478 [[ ${ret} != 1 ]] && return 0
357 return 1 479 return 1
358} 480}
359 481
360has_m32() { 482has_m32() {
361 # this doesnt test if the flag is accepted, it tests if the flag 483 # this doesnt test if the flag is accepted, it tests if the flag
362 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 484 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
363 # please dont replace this function with test_flag in some future 485 # please dont replace this function with test_flag in some future
364 # clean-up! 486 # clean-up!
487
488 [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0
489
365 local temp="$(emktemp)" 490 local temp=$(emktemp)
366 echo "int main() { return(0); }" > ${temp}.c 491 echo "int main() { return(0); }" > "${temp}".c
492 MY_CC=$(tc-getCC)
367 ${CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 493 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
368 local ret=$? 494 local ret=$?
369 rm -f ${temp}.c 495 rm -f "${temp}".c
370 [ "$ret" != "1" ] && return 0 496 [[ ${ret} != 1 ]] && return 0
371 return 1 497 return 1
372} 498}
373 499
374replace-sparc64-flags() { 500replace-sparc64-flags() {
375 local SPARC64_CPUS="ultrasparc v9" 501 local SPARC64_CPUS="ultrasparc3 ultrasparc v9"
376 502
377 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 503 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
378 for x in ${SPARC64_CPUS}; do 504 for x in ${SPARC64_CPUS}; do
379 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 505 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
380 done 506 done
381 else 507 else
382 for x in ${SPARC64_CPUS}; do 508 for x in ${SPARC64_CPUS}; do
383 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 509 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
384 done 510 done
385 fi 511 fi
386 512
387 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then 513 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
388 for x in ${SPARC64_CPUS}; do 514 for x in ${SPARC64_CPUS}; do
389 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 515 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
390 done 516 done
391 else 517 else
392 for x in ${SPARC64_CPUS}; do 518 for x in ${SPARC64_CPUS}; do
393 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 519 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
394 done 520 done
395 fi 521 fi
396 522
397 export CFLAGS CXXFLAGS 523 export CFLAGS CXXFLAGS
398} 524}
399 525
400append-ldflags() { 526append-ldflags() {
527 [[ -z $* ]] && return 0
401 export LDFLAGS="${LDFLAGS} $*" 528 export LDFLAGS="${LDFLAGS} $*"
402 return 0 529 return 0
403} 530}
404 531
532# Remove flags from LDFLAGS - it's up to the ebuild to filter
533# CFLAGS and CXXFLAGS via filter-flags if they need to.
405filter-ldflags() { 534filter-ldflags() {
406 local x 535 _filter-var LDFLAGS "$@"
536 return 0
537}
407 538
408 # we do this fancy spacing stuff so as to not filter 539# Turn C style ldflags (-Wl,-foo) into straight ldflags - the results
409 # out part of a flag ... we want flag atoms ! :D 540# are suitable for passing directly to 'ld'; note LDFLAGS is usually passed
410 LDFLAGS=" ${LDFLAGS} " 541# to gcc where it needs the '-Wl,'.
542raw-ldflags() {
543 local x input="$@"
544 [[ -z ${input} ]] && input=${LDFLAGS}
545 set --
411 for x in "$@" ; do 546 for x in ${input} ; do
412 LDFLAGS="${LDFLAGS// ${x} / }" 547 x=${x#-Wl,}
548 set -- "$@" ${x//,/ }
413 done 549 done
414 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 550 echo "$@"
415 export LDFLAGS
416 return 0
417} 551}
418 552
419etexec-flags() { 553# Gets the flags needed for "NOW" binding
420 # if you're not using a hardened compiler you wont need this 554bindnow-flags() {
421 # PIC/no-pic kludge in the first place. 555 case $($(tc-getLD) -v 2>&1 </dev/null) in
422 has_hardened || return 0 556 *GNU* | *'with BFD'*) # GNU ld
423 # this kludge breaks on amd64, and probably other -fPIC dependant 557 echo "-Wl,-z,now" ;;
424 # archs. 558 *Apple*) # Darwin ld
425 use amd64 && return 0 559 echo "-bind_at_load" ;;
426 560 *)
427 if has_pie || has_pic; then 561 # Some linkers just recognize -V instead of -v
428 [ -z "`is-flag -fno-pic`" ] && 562 case $($(tc-getLD) -V 2>&1 </dev/null) in
429 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 563 *Solaris*) # Solaris accept almost the same GNU options
430 [ -z "`is-flag -nopie`" ] && 564 echo "-Wl,-z,now" ;;
431 export CFLAGS="${CFLAGS} `test_flag -nopie`" 565 esac
432 fi 566 ;;
433 return 0 567 esac
434} 568}
435 569
436fstack-flags() {
437 if has_ssp; then
438 [ -z "`is-flag -fno-stack-protector`" ] &&
439 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
440 fi
441 return 0
442}
443 570
444# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>, 571# Some tests for when we screw with things and want to make
445# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more 572# sure we didn't break anything
446# fixes. 573#TESTS() {
574# CFLAGS="-a -b -c=1"
575# CXXFLAGS="-x -y -z=2"
576# LDFLAGS="-l -m -n=3"
447# 577#
448# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3 578# die() { exit 1; }
449gcc2-flags() { 579# (is-flag 1 2 3) && die
450 CFLAGS=${CFLAGS//pentium-mmx/i586} 580# (is-ldflag 1 2 3) && die
451 CFLAGS=${CFLAGS//pentium[234]/i686} 581#
452 CFLAGS=${CFLAGS//k6-[23]/k6} 582# is-flagq -l && die
453 CFLAGS=${CFLAGS//athlon-tbird/i686} 583# is-ldflagq -a && die
454 CFLAGS=${CFLAGS//athlon-4/i686} 584# is-flagq -a || die
455 CFLAGS=${CFLAGS//athlon-[xm]p/i686} 585# is-flagq -x || die
456 CFLAGS=${CFLAGS//athlon/i686} 586# is-ldflagq -n=* || die
457 587# is-ldflagq -n && die
458 CXXFLAGS=${CXXFLAGS//pentium-mmx/i586} 588#
459 CXXFLAGS=${CXXFLAGS//pentium[234]/i686} 589# strip-unsupported-flags
460 CXXFLAGS=${CXXFLAGS//k6-[23]/k6} 590# [[ ${CFLAGS} == "-c=1" ]] || die
461 CXXFLAGS=${CXXFLAGS//athlon-tbird/i686} 591# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
462 CXXFLAGS=${CXXFLAGS//athlon-4/i686} 592#
463 CXXFLAGS=${CXXFLAGS//athlon-[xm]p/i686} 593# echo "All tests pass"
464 CXXFLAGS=${CXXFLAGS//athlon/i686} 594#}
465 595#TESTS
466 if [ "$ARCH" = alpha ]; then
467 CHOST=${CHOST/#alphaev6[78]/alphaev6}
468 CFLAGS=${CFLAGS//ev6[78]/ev6}
469 CXXFLAGS=${CXXFLAGS//ev6[78]/ev6}
470 fi
471
472 export CFLAGS CXXFLAGS
473}

Legend:
Removed from v.1.73  
changed lines
  Added in v.1.113

  ViewVC Help
Powered by ViewVC 1.1.20