/[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.58 Revision 1.64
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 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.58 2004/06/10 15:28:56 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.64 2004/07/22 15:29:10 agriffis Exp $
4# 4#
5# Author Bart Verwilst <verwilst@gentoo.org> 5# Author Bart Verwilst <verwilst@gentoo.org>
6 6
7ECLASS=flag-o-matic 7ECLASS=flag-o-matic
8INHERITED="$INHERITED $ECLASS" 8INHERITED="$INHERITED $ECLASS"
9
10# Please leave ${IUSE} in this until portage .51 is stable, otherwise
11# IUSE gets clobbered.
9IUSE="$IUSE debug" 12IUSE="${IUSE} debug"
10 13
11# 14#
12#### filter-flags <flags> #### 15#### filter-flags <flags> ####
13# Remove particular flags from C[XX]FLAGS 16# Remove particular flags from C[XX]FLAGS
14# Matches only complete flags 17# Matches only complete flags
85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 88 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
86 return 0 89 return 0
87} 90}
88 91
89filter-flags() { 92filter-flags() {
90 local x 93 local x f fset
94 declare -a new_CFLAGS new_CXXFLAGS
91 95
92 for x in "$@" ; do 96 for x in "$@" ; do
93 case "${x}" in 97 case "${x}" in
94 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 98 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
95 -fstack-protector|-fstack-protector-all) fstack-flags;; 99 -fstack-protector|-fstack-protector-all) fstack-flags;;
96 *) ;;
97 esac 100 esac
98 done 101 done
99 102
100 # we do this fancy spacing stuff so as to not filter 103 for fset in CFLAGS CXXFLAGS; do
101 # out part of a flag ... we want flag atoms ! :D 104 # Looping over the flags instead of using a global
102 CFLAGS=" ${CFLAGS} " 105 # substitution ensures that we're working with flag atoms.
103 CXXFLAGS=" ${CXXFLAGS} " 106 # Otherwise globs like -O* have the potential to wipe out the
107 # list of flags.
108 for f in ${!fset}; do
104 for x in "$@" ; do 109 for x in "$@"; do
105 CFLAGS="${CFLAGS// ${x} / }" 110 # Note this should work with globs like -O*
106 CXXFLAGS="${CXXFLAGS// ${x} / }" 111 [[ ${f} == ${x} ]] && continue 2
112 done
113 eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
107 done 114 done
108 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 115 eval export ${fset}=\${new_${fset}\[*]}
109 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 116 done
117
110 return 0 118 return 0
111} 119}
112 120
113filter-lfs-flags() { 121filter-lfs-flags() {
114 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 122 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
125 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 133 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
126 return 0 134 return 0
127} 135}
128 136
129replace-flags() { 137replace-flags() {
130 # we do this fancy spacing stuff so as to not filter 138 local f fset
131 # out part of a flag ... we want flag atoms ! :D 139 declare -a new_CFLAGS new_CXXFLAGS
132 CFLAGS=" ${CFLAGS} " 140
133 CXXFLAGS=" ${CXXFLAGS} " 141 for fset in CFLAGS CXXFLAGS; do
134 CFLAGS="${CFLAGS// ${1} / ${2} }" 142 # Looping over the flags instead of using a global
135 CXXFLAGS="${CXXFLAGS// ${1} / ${2} }" 143 # substitution ensures that we're working with flag atoms.
136 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 144 # Otherwise globs like -O* have the potential to wipe out the
137 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 145 # list of flags.
146 for f in ${!fset}; do
147 # Note this should work with globs like -O*
148 [[ ${f} == ${1} ]] && f=${2}
149 eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
150 done
151 eval export ${fset}=\${new_${fset}\[*]}
152 done
153
138 return 0 154 return 0
139} 155}
140 156
141replace-cpu-flags() { 157replace-cpu-flags() {
142 local oldcpu newcpu="$1" ; shift 158 local oldcpu newcpu="$1" ; shift
143 for oldcpu in "$@" ; do 159 for oldcpu in "$@" ; do
160 # quote to make sure that no globbing is done (particularly on
161 # ${oldcpu} prior to calling replace-flags
144 replace-flags -march=${oldcpu} -march=${newcpu} 162 replace-flags "-march=${oldcpu}" "-march=${newcpu}"
145 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} 163 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}"
146 replace-flags -mtune=${oldcpu} -mtune=${newcpu} 164 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}"
147 done 165 done
148 return 0 166 return 0
149} 167}
150 168
151is-flag() { 169is-flag() {
203 set -f # disable pathname expansion 221 set -f # disable pathname expansion
204 222
205 for x in ${CFLAGS}; do 223 for x in ${CFLAGS}; do
206 for y in ${ALLOWED_FLAGS}; do 224 for y in ${ALLOWED_FLAGS}; do
207 flag=${x%%=*} 225 flag=${x%%=*}
208 if [ "${flag%%${y}}" = "" ]; then 226 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then
209 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 227 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
210 break 228 break
211 fi 229 fi
212 done 230 done
213 done 231 done
214 232
215 for x in ${CXXFLAGS}; do 233 for x in ${CXXFLAGS}; do
216 for y in ${ALLOWED_FLAGS}; do 234 for y in ${ALLOWED_FLAGS}; do
217 flag=${x%%=*} 235 flag=${x%%=*}
218 if [ "${flag%%${y}}" = "" ]; then 236 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then
219 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 237 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
220 break 238 break
221 fi 239 fi
222 done 240 done
223 done 241 done
229 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then 247 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
230 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 248 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
231 fi 249 fi
232 250
233 set +f # re-enable pathname expansion 251 set +f # re-enable pathname expansion
234
235 useq debug \
236 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
237 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
238 252
239 export CFLAGS="${NEW_CFLAGS}" 253 export CFLAGS="${NEW_CFLAGS}"
240 export CXXFLAGS="${NEW_CXXFLAGS}" 254 export CXXFLAGS="${NEW_CXXFLAGS}"
241 return 0 255 return 0
242} 256}
314 test_version_info ssp && return 0 328 test_version_info ssp && return 0
315 return 1 329 return 1
316} 330}
317 331
318has_m64() { 332has_m64() {
319 test_flag -m64 333 # this doesnt test if the flag is accepted, it tests if the flag
334 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
335 # please dont replace this function with test_flag in some future
336 # clean-up!
337 temp=`mktemp`
338 echo "int main() { return(0); }" > ${temp}.c
339 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1
340 ret=$?
341 rm -f ${temp}.c
342 [ "$ret" != "1" ] && return 0
320 return $? 343 return 1
321} 344}
322 345
323has_m32() { 346has_m32() {
324 test_flag -m32 347 # 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!
349 # please dont replace this function with test_flag in some future
350 # clean-up!
351 temp=`mktemp`
352 echo "int main() { return(0); }" > ${temp}.c
353 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1
354 ret=$?
355 rm -f ${temp}.c
356 [ "$ret" != "1" ] && return 0
325 return $? 357 return 1
326} 358}
327 359
328replace-sparc64-flags() { 360replace-sparc64-flags() {
329 local SPARC64_CPUS="ultrasparc v9" 361 local SPARC64_CPUS="ultrasparc v9"
330 362
345 else 377 else
346 for x in ${SPARC64_CPUS}; do 378 for x in ${SPARC64_CPUS}; do
347 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 379 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
348 done 380 done
349 fi 381 fi
382
383 export CFLAGS CXXFLAGS
350} 384}
351 385
352append-ldflags() { 386append-ldflags() {
353 LDFLAGS="${LDFLAGS} $*" 387 export LDFLAGS="${LDFLAGS} $*"
354 return 0 388 return 0
355} 389}
356 390
357filter-ldflags() { 391filter-ldflags() {
358 local x 392 local x
362 LDFLAGS=" ${LDFLAGS} " 396 LDFLAGS=" ${LDFLAGS} "
363 for x in "$@" ; do 397 for x in "$@" ; do
364 LDFLAGS="${LDFLAGS// ${x} / }" 398 LDFLAGS="${LDFLAGS// ${x} / }"
365 done 399 done
366 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 400 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
401 export LDFLAGS
367 return 0 402 return 0
368} 403}
369 404
370etexec-flags() { 405etexec-flags() {
371 # if you're not using a hardened compiler you wont need this 406 # if you're not using a hardened compiler you wont need this

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.64

  ViewVC Help
Powered by ViewVC 1.1.20