/[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.62 Revision 1.64
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.62 2004/07/15 04:59:44 lv 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
96 -fstack-protector|-fstack-protector-all) fstack-flags;; 99 -fstack-protector|-fstack-protector-all) fstack-flags;;
97 esac 100 esac
98 done 101 done
99 102
100 for fset in CFLAGS CXXFLAGS; do 103 for fset in CFLAGS CXXFLAGS; do
104 # Looping over the flags instead of using a global
105 # substitution ensures that we're working with flag atoms.
106 # Otherwise globs like -O* have the potential to wipe out the
107 # list of flags.
101 for f in ${!fset}; do 108 for f in ${!fset}; do
102 for x in "$@"; do 109 for x in "$@"; do
103 # Note this should work with globs like -O* 110 # Note this should work with globs like -O*
104 [[ ${f} == ${x} ]] && continue 2 111 [[ ${f} == ${x} ]] && continue 2
105 done 112 done
126 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 133 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
127 return 0 134 return 0
128} 135}
129 136
130replace-flags() { 137replace-flags() {
131 # we do this fancy spacing stuff so as to not filter 138 local f fset
132 # out part of a flag ... we want flag atoms ! :D 139 declare -a new_CFLAGS new_CXXFLAGS
133 CFLAGS=" ${CFLAGS} " 140
134 CXXFLAGS=" ${CXXFLAGS} " 141 for fset in CFLAGS CXXFLAGS; do
135 CFLAGS="${CFLAGS// ${1} / ${2} }" 142 # Looping over the flags instead of using a global
136 CXXFLAGS="${CXXFLAGS// ${1} / ${2} }" 143 # substitution ensures that we're working with flag atoms.
137 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 144 # Otherwise globs like -O* have the potential to wipe out the
138 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 145 # list of flags.
139 export CFLAGS CXXFLAGS 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
140 return 0 154 return 0
141} 155}
142 156
143replace-cpu-flags() { 157replace-cpu-flags() {
144 local oldcpu newcpu="$1" ; shift 158 local oldcpu newcpu="$1" ; shift
145 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
146 replace-flags -march=${oldcpu} -march=${newcpu} 162 replace-flags "-march=${oldcpu}" "-march=${newcpu}"
147 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} 163 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}"
148 replace-flags -mtune=${oldcpu} -mtune=${newcpu} 164 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}"
149 done 165 done
150 return 0 166 return 0
151} 167}
152 168
153is-flag() { 169is-flag() {
205 set -f # disable pathname expansion 221 set -f # disable pathname expansion
206 222
207 for x in ${CFLAGS}; do 223 for x in ${CFLAGS}; do
208 for y in ${ALLOWED_FLAGS}; do 224 for y in ${ALLOWED_FLAGS}; do
209 flag=${x%%=*} 225 flag=${x%%=*}
210 if [ "${flag%%${y}}" = "" ]; then 226 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then
211 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 227 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
212 break 228 break
213 fi 229 fi
214 done 230 done
215 done 231 done
216 232
217 for x in ${CXXFLAGS}; do 233 for x in ${CXXFLAGS}; do
218 for y in ${ALLOWED_FLAGS}; do 234 for y in ${ALLOWED_FLAGS}; do
219 flag=${x%%=*} 235 flag=${x%%=*}
220 if [ "${flag%%${y}}" = "" ]; then 236 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then
221 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 237 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
222 break 238 break
223 fi 239 fi
224 done 240 done
225 done 241 done

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

  ViewVC Help
Powered by ViewVC 1.1.20