/[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.60 Revision 1.67
1# Copyright 1999-2004 Gentoo Foundation 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.60 2004/06/25 00:39:48 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.67 2004/08/07 04:24:41 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
74 case "${ARCH}" in 77 case "${ARCH}" in
75 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
76 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
77 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
78 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
79 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
80 esac 83 esac
81 fi 84 fi
85 # allow a bunch of flags that negate features / control ABI
86 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
87 case "${ARCH}" in
88 x86|amd64|ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" ;;
89 esac
90 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"
82 91
83 # C[XX]FLAGS that we are think is ok, but needs testing 92 # C[XX]FLAGS that we are think is ok, but needs testing
84 # NOTE: currently -Os have issues with gcc3 and K6* arch's 93 # NOTE: currently -Os have issues with gcc3 and K6* arch's
85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 94 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
86 return 0 95 return 0
87} 96}
88 97
89filter-flags() { 98filter-flags() {
90 local x 99 local x f fset
100 declare -a new_CFLAGS new_CXXFLAGS
91 101
92 for x in "$@" ; do 102 for x in "$@" ; do
93 case "${x}" in 103 case "${x}" in
94 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 104 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
95 -fstack-protector|-fstack-protector-all) fstack-flags;; 105 -fstack-protector|-fstack-protector-all) fstack-flags;;
96 *) ;;
97 esac 106 esac
98 done 107 done
99 108
100 # we do this fancy spacing stuff so as to not filter 109 for fset in CFLAGS CXXFLAGS; do
101 # out part of a flag ... we want flag atoms ! :D 110 # Looping over the flags instead of using a global
102 CFLAGS=" ${CFLAGS} " 111 # substitution ensures that we're working with flag atoms.
103 CXXFLAGS=" ${CXXFLAGS} " 112 # Otherwise globs like -O* have the potential to wipe out the
113 # list of flags.
114 for f in ${!fset}; do
104 for x in "$@" ; do 115 for x in "$@"; do
105 CFLAGS="${CFLAGS// ${x} / }" 116 # Note this should work with globs like -O*
106 CXXFLAGS="${CXXFLAGS// ${x} / }" 117 [[ ${f} == ${x} ]] && continue 2
118 done
119 eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
107 done 120 done
108 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 121 eval export ${fset}=\${new_${fset}\[*]}
109 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 122 done
110 export CFLAGS CXXFLAGS 123
111 return 0 124 return 0
112} 125}
113 126
114filter-lfs-flags() { 127filter-lfs-flags() {
115 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 128 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
126 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 139 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
127 return 0 140 return 0
128} 141}
129 142
130replace-flags() { 143replace-flags() {
131 # we do this fancy spacing stuff so as to not filter 144 local f fset
132 # out part of a flag ... we want flag atoms ! :D 145 declare -a new_CFLAGS new_CXXFLAGS
133 CFLAGS=" ${CFLAGS} " 146
134 CXXFLAGS=" ${CXXFLAGS} " 147 for fset in CFLAGS CXXFLAGS; do
135 CFLAGS="${CFLAGS// ${1} / ${2} }" 148 # Looping over the flags instead of using a global
136 CXXFLAGS="${CXXFLAGS// ${1} / ${2} }" 149 # substitution ensures that we're working with flag atoms.
137 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 150 # Otherwise globs like -O* have the potential to wipe out the
138 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 151 # list of flags.
139 export CFLAGS CXXFLAGS 152 for f in ${!fset}; do
153 # Note this should work with globs like -O*
154 [[ ${f} == ${1} ]] && f=${2}
155 eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f}
156 done
157 eval export ${fset}=\${new_${fset}\[*]}
158 done
159
140 return 0 160 return 0
141} 161}
142 162
143replace-cpu-flags() { 163replace-cpu-flags() {
144 local oldcpu newcpu="$1" ; shift 164 local oldcpu newcpu="$1" ; shift
145 for oldcpu in "$@" ; do 165 for oldcpu in "$@" ; do
166 # quote to make sure that no globbing is done (particularly on
167 # ${oldcpu} prior to calling replace-flags
146 replace-flags -march=${oldcpu} -march=${newcpu} 168 replace-flags "-march=${oldcpu}" "-march=${newcpu}"
147 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} 169 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}"
148 replace-flags -mtune=${oldcpu} -mtune=${newcpu} 170 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}"
149 done 171 done
150 return 0 172 return 0
151} 173}
152 174
153is-flag() { 175is-flag() {
154 local x 176 local x
155 177
156 for x in ${CFLAGS} ${CXXFLAGS} ; do 178 for x in ${CFLAGS} ${CXXFLAGS} ; do
179 # Note this should work with globs like -mcpu=ultrasparc*
157 if [ "${x}" == "$1" ] ; then 180 if [[ ${x} == ${1} ]]; then
158 echo true 181 echo true
159 return 0 182 return 0
160 fi 183 fi
161 done 184 done
162 return 1 185 return 1
205 set -f # disable pathname expansion 228 set -f # disable pathname expansion
206 229
207 for x in ${CFLAGS}; do 230 for x in ${CFLAGS}; do
208 for y in ${ALLOWED_FLAGS}; do 231 for y in ${ALLOWED_FLAGS}; do
209 flag=${x%%=*} 232 flag=${x%%=*}
210 if [ "${flag%%${y}}" = "" ]; then 233 if [ "${flag%%${y}}" = "" ] ; then
211 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 234 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
212 break 235 break
213 fi 236 fi
214 done 237 done
215 done 238 done
216 239
217 for x in ${CXXFLAGS}; do 240 for x in ${CXXFLAGS}; do
218 for y in ${ALLOWED_FLAGS}; do 241 for y in ${ALLOWED_FLAGS}; do
219 flag=${x%%=*} 242 flag=${x%%=*}
220 if [ "${flag%%${y}}" = "" ]; then 243 if [ "${flag%%${y}}" = "" ] ; then
221 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 244 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
222 break 245 break
223 fi 246 fi
224 done 247 done
225 done 248 done
312 test_version_info ssp && return 0 335 test_version_info ssp && return 0
313 return 1 336 return 1
314} 337}
315 338
316has_m64() { 339has_m64() {
317 test_flag -m64 340 # this doesnt test if the flag is accepted, it tests if the flag
341 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
342 # please dont replace this function with test_flag in some future
343 # clean-up!
344 temp=`mktemp`
345 echo "int main() { return(0); }" > ${temp}.c
346 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1
347 ret=$?
348 rm -f ${temp}.c
349 [ "$ret" != "1" ] && return 0
318 return $? 350 return 1
319} 351}
320 352
321has_m32() { 353has_m32() {
322 test_flag -m32 354 # this doesnt test if the flag is accepted, it tests if the flag
355 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
356 # please dont replace this function with test_flag in some future
357 # clean-up!
358 temp=`mktemp`
359 echo "int main() { return(0); }" > ${temp}.c
360 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1
361 ret=$?
362 rm -f ${temp}.c
363 [ "$ret" != "1" ] && return 0
323 return $? 364 return 1
324} 365}
325 366
326replace-sparc64-flags() { 367replace-sparc64-flags() {
327 local SPARC64_CPUS="ultrasparc v9" 368 local SPARC64_CPUS="ultrasparc v9"
328 369
370 411
371etexec-flags() { 412etexec-flags() {
372 # if you're not using a hardened compiler you wont need this 413 # if you're not using a hardened compiler you wont need this
373 # PIC/no-pic kludge in the first place. 414 # PIC/no-pic kludge in the first place.
374 has_hardened || return 0 415 has_hardened || return 0
416 # this kludge breaks on amd64, and probably other -fPIC dependant
417 # archs.
418 use amd64 && return 0
375 419
376 if has_pie || has_pic; then 420 if has_pie || has_pic; then
377 [ -z "`is-flag -fno-pic`" ] && 421 [ -z "`is-flag -fno-pic`" ] &&
378 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 422 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
379 [ -z "`is-flag -nopie`" ] && 423 [ -z "`is-flag -nopie`" ] &&

Legend:
Removed from v.1.60  
changed lines
  Added in v.1.67

  ViewVC Help
Powered by ViewVC 1.1.20