/[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.53 Revision 1.58
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
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.53 2004/06/01 04:28:38 solar Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.58 2004/06/10 15:28:56 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"
9IUSE="$IUSE debug"
9 10
10# 11#
11#### filter-flags <flags> #### 12#### filter-flags <flags> ####
12# Remove particular flags from C[XX]FLAGS 13# Remove particular flags from C[XX]FLAGS
13# Matches only complete flags 14# Matches only complete flags
84 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
85 return 0 86 return 0
86} 87}
87 88
88filter-flags() { 89filter-flags() {
90 local x
91
89 for x in "$@" ; do 92 for x in "$@" ; do
90 case "${x}" in 93 case "${x}" in
91 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 94 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
92 -fstack-protector|-fstack-protector-all) fstack-flags;; 95 -fstack-protector|-fstack-protector-all) fstack-flags;;
93 *) ;; 96 *) ;;
114append-lfs-flags() { 117append-lfs-flags() {
115 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 118 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
116} 119}
117 120
118append-flags() { 121append-flags() {
119 export CFLAGS="${CFLAGS} $@" 122 export CFLAGS="${CFLAGS} $*"
120 export CXXFLAGS="${CXXFLAGS} $@" 123 export CXXFLAGS="${CXXFLAGS} $*"
121 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags 124 [ -n "`is-flag -fno-stack-protector`" -o \
125 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
122 return 0 126 return 0
123} 127}
124 128
125replace-flags() { 129replace-flags() {
126 # we do this fancy spacing stuff so as to not filter 130 # we do this fancy spacing stuff so as to not filter
133 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 137 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
134 return 0 138 return 0
135} 139}
136 140
137replace-cpu-flags() { 141replace-cpu-flags() {
138 local newcpu="$1" ; shift 142 local oldcpu newcpu="$1" ; shift
139 local oldcpu=""
140 for oldcpu in "$@" ; do 143 for oldcpu in "$@" ; do
141 replace-flags -march=${oldcpu} -march=${newcpu} 144 replace-flags -march=${oldcpu} -march=${newcpu}
142 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} 145 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu}
143 replace-flags -mtune=${oldcpu} -mtune=${newcpu} 146 replace-flags -mtune=${oldcpu} -mtune=${newcpu}
144 done 147 done
145 return 0 148 return 0
146} 149}
147 150
148is-flag() { 151is-flag() {
152 local x
153
149 for x in ${CFLAGS} ${CXXFLAGS} ; do 154 for x in ${CFLAGS} ${CXXFLAGS} ; do
150 if [ "${x}" == "$1" ] ; then 155 if [ "${x}" == "$1" ] ; then
151 echo true 156 echo true
152 return 0 157 return 0
153 fi 158 fi
154 done 159 done
155 return 1 160 return 1
156} 161}
157 162
158filter-mfpmath() { 163filter-mfpmath() {
164 local orig_mfpmath new_math prune_math
165
159 # save the original -mfpmath flag 166 # save the original -mfpmath flag
160 local orig_mfpmath="`get-flag -mfpmath`" 167 orig_mfpmath="`get-flag -mfpmath`"
161 # get the value of the current -mfpmath flag 168 # get the value of the current -mfpmath flag
162 local new_math=" `get-flag mfpmath | tr , ' '` " 169 new_math=" `get-flag mfpmath | tr , ' '` "
163 # figure out which math values are to be removed 170 # figure out which math values are to be removed
164 local prune_math="" 171 prune_math=""
165 for prune_math in "$@" ; do 172 for prune_math in "$@" ; do
166 new_math="${new_math/ ${prune_math} / }" 173 new_math="${new_math/ ${prune_math} / }"
167 done 174 done
168 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" 175 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`"
169 176
178 fi 185 fi
179 return 0 186 return 0
180} 187}
181 188
182strip-flags() { 189strip-flags() {
190 local x y flag NEW_CFLAGS NEW_CXXFLAGS
191
183 setup-allowed-flags 192 setup-allowed-flags
184 193
185 local NEW_CFLAGS="" 194 local NEW_CFLAGS=""
186 local NEW_CXXFLAGS="" 195 local NEW_CXXFLAGS=""
187 196
189 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then 198 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then
190 use debug && einfo "Enabling the use of some unstable flags" 199 use debug && einfo "Enabling the use of some unstable flags"
191 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 200 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
192 fi 201 fi
193 202
194 set -f 203 set -f # disable pathname expansion
195 204
196 for x in ${CFLAGS} 205 for x in ${CFLAGS}; do
197 do
198 for y in ${ALLOWED_FLAGS} 206 for y in ${ALLOWED_FLAGS}; do
199 do
200 flag=${x%%=*} 207 flag=${x%%=*}
201 if [ "${flag%%${y}}" = "" ] 208 if [ "${flag%%${y}}" = "" ]; then
202 then
203 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 209 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
204 break 210 break
205 fi 211 fi
206 done 212 done
207 done 213 done
208 214
209 for x in ${CXXFLAGS} 215 for x in ${CXXFLAGS}; do
210 do
211 for y in ${ALLOWED_FLAGS} 216 for y in ${ALLOWED_FLAGS}; do
212 do
213 flag=${x%%=*} 217 flag=${x%%=*}
214 if [ "${flag%%${y}}" = "" ] 218 if [ "${flag%%${y}}" = "" ]; then
215 then
216 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 219 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
217 break 220 break
218 fi 221 fi
219 done 222 done
220 done 223 done
225 fi 228 fi
226 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then 229 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
227 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 230 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
228 fi 231 fi
229 232
230 set +f 233 set +f # re-enable pathname expansion
231 234
232 use debug \ 235 useq debug \
233 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ 236 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
234 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" 237 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
235 238
236 export CFLAGS="${NEW_CFLAGS}" 239 export CFLAGS="${NEW_CFLAGS}"
237 export CXXFLAGS="${NEW_CXXFLAGS}" 240 export CXXFLAGS="${NEW_CXXFLAGS}"
238 return 0 241 return 0
239} 242}
240 243
241test_flag() { 244test_flag() {
245 local cc=${CC:-gcc} ; cc=${cc%% *}
242 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then 246 if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then
243 echo "$@" 247 printf "%s\n" "$*"
244 return 0 248 return 0
245 fi 249 fi
246 return 1 250 return 1
247} 251}
248 252
253test_version_info() {
254 local cc=${CC:-gcc} ; cc=${cc%% *}
255 if [[ $(${cc} --version 2>&1) == *$1* ]]; then
256 return 0
257 else
258 return 1
259 fi
260}
261
249strip-unsupported-flags() { 262strip-unsupported-flags() {
263 local NEW_CFLAGS NEW_CXXFLAGS
264
250 for x in ${CFLAGS} ; do 265 for x in ${CFLAGS} ; do
251 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`" 266 NEW_CFLAGS="${NEW_CFLAGS} `test_flag ${x}`"
252 done 267 done
253 for x in ${CXXFLAGS} ; do 268 for x in ${CXXFLAGS} ; do
254 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`" 269 NEW_CXXFLAGS="${NEW_CXXFLAGS} `test_flag ${x}`"
255 done 270 done
256 271
257 export CFLAGS="${NEW_CFLAGS}" 272 export CFLAGS="${NEW_CFLAGS}"
258 export CXXFLAGS="${NEW_CXXFLAGS}" 273 export CXXFLAGS="${NEW_CXXFLAGS}"
259} 274}
260 275
261get-flag() { 276get-flag() {
277 local f findflag="$1"
278
262 # this code looks a little flaky but seems to work for 279 # this code looks a little flaky but seems to work for
263 # everything we want ... 280 # everything we want ...
264 # for example, if CFLAGS="-march=i686": 281 # for example, if CFLAGS="-march=i686":
265 # `get-flags -march` == "-march=i686" 282 # `get-flag -march` == "-march=i686"
266 # `get-flags march` == "i686" 283 # `get-flag march` == "i686"
267 local findflag="$1"
268 for f in ${CFLAGS} ${CXXFLAGS} ; do 284 for f in ${CFLAGS} ${CXXFLAGS} ; do
269 if [ "${f/${findflag}}" != "${f}" ] ; then 285 if [ "${f/${findflag}}" != "${f}" ] ; then
270 echo "${f/-${findflag}=}" 286 printf "%s\n" "${f/-${findflag}=}"
271 return 0 287 return 0
272 fi 288 fi
273 done 289 done
274 return 1 290 return 1
275} 291}
276 292
277has_hardened() { 293has_hardened() {
278 local cc=${CC:-gcc} 294 test_version_info Hardened
279 [[ $(${cc%% *} --version 2>&1) == *Hardened* ]]
280 return $? 295 return $?
281} 296}
282 297
283has_pic() { 298has_pic() {
284 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 299 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
285 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 300 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
286 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 301 test_version_info pie && return 0
287 return 1 302 return 1
288} 303}
289 304
290has_pie() { 305has_pie() {
291 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 306 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
292 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 307 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
293 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 308 test_version_info pie && return 0
294 return 1 309 return 1
295} 310}
296 311
297has_ssp() { 312has_ssp() {
298 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 313 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
299 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0 314 test_version_info ssp && return 0
315 return 1
316}
317
318has_m64() {
319 test_flag -m64
300 return 1 320 return $?
321}
322
323has_m32() {
324 test_flag -m32
325 return $?
301} 326}
302 327
303replace-sparc64-flags() { 328replace-sparc64-flags() {
304 local SPARC64_CPUS="ultrasparc v9" 329 local SPARC64_CPUS="ultrasparc v9"
305 330
306 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] 331 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
307 then
308 for x in ${SPARC64_CPUS} 332 for x in ${SPARC64_CPUS}; do
309 do
310 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 333 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
311 done 334 done
312 else 335 else
313 for x in ${SPARC64_CPUS} 336 for x in ${SPARC64_CPUS}; do
314 do
315 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 337 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
316 done 338 done
317 fi 339 fi
318 340
319 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ] 341 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
320 then
321 for x in ${SPARC64_CPUS} 342 for x in ${SPARC64_CPUS}; do
322 do
323 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 343 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
324 done 344 done
325 else 345 else
326 for x in ${SPARC64_CPUS} 346 for x in ${SPARC64_CPUS}; do
327 do
328 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 347 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
329 done 348 done
330 fi 349 fi
331} 350}
332 351
333append-ldflags() { 352append-ldflags() {
334 LDFLAGS="${LDFLAGS} $@" 353 LDFLAGS="${LDFLAGS} $*"
335 return 0 354 return 0
336} 355}
337 356
338filter-ldflags() { 357filter-ldflags() {
358 local x
359
339 # we do this fancy spacing stuff so as to not filter 360 # we do this fancy spacing stuff so as to not filter
340 # out part of a flag ... we want flag atoms ! :D 361 # out part of a flag ... we want flag atoms ! :D
341 LDFLAGS=" ${LDFLAGS} " 362 LDFLAGS=" ${LDFLAGS} "
342 for x in "$@" ; do 363 for x in "$@" ; do
343 LDFLAGS="${LDFLAGS// ${x} / }" 364 LDFLAGS="${LDFLAGS// ${x} / }"
345 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 366 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
346 return 0 367 return 0
347} 368}
348 369
349etexec-flags() { 370etexec-flags() {
350 # if your not using a hardened compiler you wont need this 371 # if you're not using a hardened compiler you wont need this
351 # PIC/no-pic kludge in the first place. 372 # PIC/no-pic kludge in the first place.
352 has_hardened || return 373 has_hardened || return 0
353 374
354 has_pie || has_pic 375 if has_pie || has_pic; then
355 if [ $? == 0 ] ; then
356 [ -z "`is-flag -fno-pic`" ] && 376 [ -z "`is-flag -fno-pic`" ] &&
357 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 377 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
358
359 [ -z "`is-flag -nopie`" ] && 378 [ -z "`is-flag -nopie`" ] &&
360 export CFLAGS="${CFLAGS} `test_flag -nopie`" 379 export CFLAGS="${CFLAGS} `test_flag -nopie`"
361 fi 380 fi
381 return 0
362} 382}
363 383
364fstack-flags() { 384fstack-flags() {
365 has_ssp 385 if has_ssp; then
366 if [ $? == 0 ] ; then
367 [ -z "`is-flag -fno-stack-protector`" ] && 386 [ -z "`is-flag -fno-stack-protector`" ] &&
368 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 387 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
369 fi 388 fi
389 return 0
370} 390}

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

  ViewVC Help
Powered by ViewVC 1.1.20