/[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.112 Revision 1.113
1# Copyright 1999-2006 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.112 2006/11/15 22:17:56 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# Maintainer: base-system@gentoo.org 5# Maintainer: base-system@gentoo.org
6 6
7# need access to emktemp() 7# need access to emktemp()
8inherit eutils toolchain-funcs multilib 8inherit eutils toolchain-funcs multilib
212 212
213replace-cpu-flags() { 213replace-cpu-flags() {
214 local newcpu="$#" ; newcpu="${!newcpu}" 214 local newcpu="$#" ; newcpu="${!newcpu}"
215 while [ $# -gt 1 ] ; do 215 while [ $# -gt 1 ] ; do
216 # quote to make sure that no globbing is done (particularly on 216 # quote to make sure that no globbing is done (particularly on
217 # ${oldcpu} prior to calling replace-flags 217 # ${oldcpu}) prior to calling replace-flags
218 replace-flags "-march=${1}" "-march=${newcpu}" 218 replace-flags "-march=${1}" "-march=${newcpu}"
219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}" 219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
220 replace-flags "-mtune=${1}" "-mtune=${newcpu}" 220 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
221 shift 221 shift
222 done 222 done
223 return 0 223 return 0
224} 224}
225 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
226is-flagq() { 234is-flagq() {
227 local x 235 [[ -n $2 ]] && die "Usage: is-flag <flag>"
228 236 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1
229 for x in ${CFLAGS} ${CXXFLAGS} ; do
230 # Note this should work with globs like -mcpu=ultrasparc*
231 if [[ ${x} == ${1} ]]; then
232 return 0
233 fi
234 done
235 return 1
236} 237}
237 238
238is-flag() { 239is-flag() {
239 if is-flagq ${1}; then 240 is-flagq "$@" && echo true
240 echo true
241 return 0
242 fi
243 return 1
244} 241}
245 242
246is-ldflagq() { 243is-ldflagq() {
247 local x 244 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
248 245 _is_flagq LDFLAGS $1
249 for x in ${LDFLAGS} ; do
250 # Note this should work with globs like -mcpu=ultrasparc*
251 if [[ ${x} == ${1} ]]; then
252 return 0
253 fi
254 done
255 return 1
256} 246}
257 247
258is-ldflag() { 248is-ldflag() {
259 if is-ldflagq ${1}; then 249 is-ldflagq "$@" && echo true
260 echo true
261 return 0
262 fi
263 return 1
264} 250}
265 251
266filter-mfpmath() { 252filter-mfpmath() {
267 local orig_mfpmath new_math prune_math 253 local orig_mfpmath new_math prune_math
268 254
364 local flags 350 local flags
365 local x 351 local x
366 352
367 shift 353 shift
368 354
369 [[ -z ${comp} ]] && \ 355 [[ -z ${comp} ]] && return 1
370 return 1
371 356
357 x=""
372 for x in "$@" ; do 358 for x in "$@" ; do
373 test-flag-${comp} "${x}" && flags="${flags} ${x}" 359 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
374 done 360 done
375 361
376 echo "${flags}" 362 echo "${flags}"
377 363
378 # Just bail if we dont have any flags 364 # Just bail if we dont have any flags
403 return 1 389 return 1
404 fi 390 fi
405} 391}
406 392
407strip-unsupported-flags() { 393strip-unsupported-flags() {
408 local x NEW_CFLAGS NEW_CXXFLAGS 394 export CFLAGS=$(test-flags-CC ${CFLAGS})
409 395 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
410 for x in ${CFLAGS} ; do
411 NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
412 done
413 for x in ${CXXFLAGS} ; do
414 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
415 done
416
417 export CFLAGS=${NEW_CFLAGS}
418 export CXXFLAGS=${NEW_CXXFLAGS}
419} 396}
420 397
421get-flag() { 398get-flag() {
422 local f findflag="$1" 399 local f findflag="$1"
423 400
587 echo "-Wl,-z,now" ;; 564 echo "-Wl,-z,now" ;;
588 esac 565 esac
589 ;; 566 ;;
590 esac 567 esac
591} 568}
569
570
571# Some tests for when we screw with things and want to make
572# sure we didn't break anything
573#TESTS() {
574# CFLAGS="-a -b -c=1"
575# CXXFLAGS="-x -y -z=2"
576# LDFLAGS="-l -m -n=3"
577#
578# die() { exit 1; }
579# (is-flag 1 2 3) && die
580# (is-ldflag 1 2 3) && die
581#
582# is-flagq -l && die
583# is-ldflagq -a && die
584# is-flagq -a || die
585# is-flagq -x || die
586# is-ldflagq -n=* || die
587# is-ldflagq -n && die
588#
589# strip-unsupported-flags
590# [[ ${CFLAGS} == "-c=1" ]] || die
591# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
592#
593# echo "All tests pass"
594#}
595#TESTS

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

  ViewVC Help
Powered by ViewVC 1.1.20