/[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.106 Revision 1.113
1# Copyright 1999-2005 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.106 2006/02/19 23:18:30 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 6
6# need access to emktemp() 7# need access to emktemp()
7inherit eutils toolchain-funcs multilib 8inherit eutils toolchain-funcs multilib
8 9
9# 10#
97 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune" 98 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
98 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all" 99 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all"
99 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-bounds-checking" 100 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-bounds-checking"
100 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time" 101 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time"
101 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3" 102 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3"
103 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident"
102 fi 104 fi
103 # allow a bunch of flags that negate features / control ABI 105 # allow a bunch of flags that negate features / control ABI
104 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" 106 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
105 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ 107 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \
106 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \ 108 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \
107 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \ 109 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \
108 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 110 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
109 -mieee -mieee-with-inexact \ 111 -mieee -mieee-with-inexact -mschedule \
110 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ 112 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \
111 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 113 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
112 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 114 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
113 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias" 115 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias"
114 116
210 212
211replace-cpu-flags() { 213replace-cpu-flags() {
212 local newcpu="$#" ; newcpu="${!newcpu}" 214 local newcpu="$#" ; newcpu="${!newcpu}"
213 while [ $# -gt 1 ] ; do 215 while [ $# -gt 1 ] ; do
214 # quote to make sure that no globbing is done (particularly on 216 # quote to make sure that no globbing is done (particularly on
215 # ${oldcpu} prior to calling replace-flags 217 # ${oldcpu}) prior to calling replace-flags
216 replace-flags "-march=${1}" "-march=${newcpu}" 218 replace-flags "-march=${1}" "-march=${newcpu}"
217 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}" 219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
218 replace-flags "-mtune=${1}" "-mtune=${newcpu}" 220 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
219 shift 221 shift
220 done 222 done
221 return 0 223 return 0
222} 224}
223 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
224is-flagq() { 234is-flagq() {
225 local x 235 [[ -n $2 ]] && die "Usage: is-flag <flag>"
226 236 _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1
227 for x in ${CFLAGS} ${CXXFLAGS} ; do
228 # Note this should work with globs like -mcpu=ultrasparc*
229 if [[ ${x} == ${1} ]]; then
230 return 0
231 fi
232 done
233 return 1
234} 237}
235 238
236is-flag() { 239is-flag() {
237 if is-flagq ${1}; then 240 is-flagq "$@" && echo true
238 echo true
239 return 0
240 fi
241 return 1
242} 241}
243 242
244is-ldflagq() { 243is-ldflagq() {
245 local x 244 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
246 245 _is_flagq LDFLAGS $1
247 for x in ${LDFLAGS} ; do
248 # Note this should work with globs like -mcpu=ultrasparc*
249 if [[ ${x} == ${1} ]]; then
250 return 0
251 fi
252 done
253 return 1
254} 246}
255 247
256is-ldflag() { 248is-ldflag() {
257 if is-ldflagq ${1}; then 249 is-ldflagq "$@" && echo true
258 echo true
259 return 0
260 fi
261 return 1
262} 250}
263 251
264filter-mfpmath() { 252filter-mfpmath() {
265 local orig_mfpmath new_math prune_math 253 local orig_mfpmath new_math prune_math
266 254
267 # save the original -mfpmath flag 255 # save the original -mfpmath flag
268 orig_mfpmath="`get-flag -mfpmath`" 256 orig_mfpmath=$(get-flag -mfpmath)
269 # get the value of the current -mfpmath flag 257 # get the value of the current -mfpmath flag
270 new_math=" `get-flag mfpmath | tr , ' '` " 258 new_math=$(get-flag mfpmath)
259 new_math=" ${new_math//,/ } "
271 # figure out which math values are to be removed 260 # figure out which math values are to be removed
272 prune_math="" 261 prune_math=""
273 for prune_math in "$@" ; do 262 for prune_math in "$@" ; do
274 new_math="${new_math/ ${prune_math} / }" 263 new_math=${new_math/ ${prune_math} / }
275 done 264 done
276 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" 265 new_math=$(echo ${new_math})
266 new_math=${new_math// /,}
277 267
278 if [ -z "${new_math}" ] ; then 268 if [[ -z ${new_math} ]] ; then
279 # if we're removing all user specified math values are 269 # if we're removing all user specified math values are
280 # slated for removal, then we just filter the flag 270 # slated for removal, then we just filter the flag
281 filter-flags ${orig_mfpmath} 271 filter-flags ${orig_mfpmath}
282 else 272 else
283 # if we only want to filter some of the user specified 273 # if we only want to filter some of the user specified
360 local flags 350 local flags
361 local x 351 local x
362 352
363 shift 353 shift
364 354
365 [[ -z ${comp} ]] && \ 355 [[ -z ${comp} ]] && return 1
366 return 1
367 356
357 x=""
368 for x in "$@" ; do 358 for x in "$@" ; do
369 test-flag-${comp} "${x}" && flags="${flags} ${x}" 359 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
370 done 360 done
371 361
372 echo "${flags}" 362 echo "${flags}"
373 363
374 # Just bail if we dont have any flags 364 # Just bail if we dont have any flags
399 return 1 389 return 1
400 fi 390 fi
401} 391}
402 392
403strip-unsupported-flags() { 393strip-unsupported-flags() {
404 local x NEW_CFLAGS NEW_CXXFLAGS 394 export CFLAGS=$(test-flags-CC ${CFLAGS})
405 395 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
406 for x in ${CFLAGS} ; do
407 NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
408 done
409 for x in ${CXXFLAGS} ; do
410 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
411 done
412
413 export CFLAGS=${NEW_CFLAGS}
414 export CXXFLAGS=${NEW_CXXFLAGS}
415} 396}
416 397
417get-flag() { 398get-flag() {
418 local f findflag="$1" 399 local f findflag="$1"
419 400
522 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 503 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
523 for x in ${SPARC64_CPUS}; do 504 for x in ${SPARC64_CPUS}; do
524 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 505 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
525 done 506 done
526 else 507 else
527 for x in ${SPARC64_CPUS}; do 508 for x in ${SPARC64_CPUS}; do
528 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 509 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
529 done 510 done
530 fi 511 fi
531 512
532 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then 513 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
533 for x in ${SPARC64_CPUS}; do 514 for x in ${SPARC64_CPUS}; do
534 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 515 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
535 done 516 done
536 else 517 else
537 for x in ${SPARC64_CPUS}; do 518 for x in ${SPARC64_CPUS}; do
538 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 519 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
539 done 520 done
540 fi 521 fi
541 522
542 export CFLAGS CXXFLAGS 523 export CFLAGS CXXFLAGS
565 for x in ${input} ; do 546 for x in ${input} ; do
566 x=${x#-Wl,} 547 x=${x#-Wl,}
567 set -- "$@" ${x//,/ } 548 set -- "$@" ${x//,/ }
568 done 549 done
569 echo "$@" 550 echo "$@"
570}
571
572# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
573# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
574# fixes.
575#
576# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
577gcc2-flags() {
578 if [[ $(tc-arch) == "x86" || $(tc-arch) == "amd64" ]] ; then
579 CFLAGS=${CFLAGS//-mtune=/-mcpu=}
580 CXXFLAGS=${CXXFLAGS//-mtune=/-mcpu=}
581 fi
582
583 replace-cpu-flags k6-{2,3} k6
584 replace-cpu-flags athlon{,-{tbird,4,xp,mp}} i686
585
586 replace-cpu-flags pentium-mmx i586
587 replace-cpu-flags pentium{2,3,4} i686
588
589 replace-cpu-flags ev6{7,8} ev6
590
591 export CFLAGS CXXFLAGS
592} 551}
593 552
594# Gets the flags needed for "NOW" binding 553# Gets the flags needed for "NOW" binding
595bindnow-flags() { 554bindnow-flags() {
596 case $($(tc-getLD) -v 2>&1 </dev/null) in 555 case $($(tc-getLD) -v 2>&1 </dev/null) in
605 echo "-Wl,-z,now" ;; 564 echo "-Wl,-z,now" ;;
606 esac 565 esac
607 ;; 566 ;;
608 esac 567 esac
609} 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.106  
changed lines
  Added in v.1.113

  ViewVC Help
Powered by ViewVC 1.1.20