/[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.108 Revision 1.120
1# Copyright 1999-2006 Gentoo Foundation 1# Copyright 1999-2007 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.108 2006/06/15 14:45:59 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.120 2007/07/22 08:21:09 dberkholz Exp $
4# 4#
5# Maintainer: base-system@gentoo.org 5# Maintainer: toolchain@gentoo.org
6 6
7# need access to emktemp() 7# need access to emktemp()
8inherit eutils toolchain-funcs multilib 8inherit eutils toolchain-funcs multilib
9 9
10# 10#
90# Returns true if the compiler by default or with current CFLAGS 90# Returns true if the compiler by default or with current CFLAGS
91# generates stack smash protections for most vulnerable functions 91# generates stack smash protections for most vulnerable functions
92# 92#
93 93
94# C[XX]FLAGS that we allow in strip-flags 94# C[XX]FLAGS that we allow in strip-flags
95# Note: shell globs and character lists are allowed
95setup-allowed-flags() { 96setup-allowed-flags() {
96 if [[ -z ${ALLOWED_FLAGS} ]] ; then 97 if [[ -z ${ALLOWED_FLAGS} ]] ; then
97 export ALLOWED_FLAGS="-pipe" 98 export ALLOWED_FLAGS="-pipe"
98 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune" 99 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
99 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all" 100 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all"
100 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-bounds-checking" 101 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking"
101 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time" 102 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time"
102 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3" 103 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+"
103 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident" 104 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident"
105 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w"
104 fi 106 fi
105 # allow a bunch of flags that negate features / control ABI 107 # allow a bunch of flags that negate features / control ABI
106 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" 108 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all \
109 -fno-strict-aliasing -fno-bounds-checking"
107 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ 110 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \
108 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \ 111 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \
109 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \ 112 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \
110 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 113 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
111 -mieee -mieee-with-inexact \ 114 -mieee -mieee-with-inexact -mschedule \
112 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ 115 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \
113 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 116 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
114 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 117 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
115 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias" 118 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \
119 -msecure-plt -D*"
116 120
117 # C[XX]FLAGS that we are think is ok, but needs testing 121 # C[XX]FLAGS that we are think is ok, but needs testing
118 # NOTE: currently -Os have issues with gcc3 and K6* arch's 122 # NOTE: currently -Os have issues with gcc3 and K6* arch's
119 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks" 123 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
120 return 0 124 return 0
163} 167}
164 168
165filter-flags() { 169filter-flags() {
166 _filter-hardened "$@" 170 _filter-hardened "$@"
167 _filter-var CFLAGS "$@" 171 _filter-var CFLAGS "$@"
172 _filter-var CPPFLAGS "$@"
168 _filter-var CXXFLAGS "$@" 173 _filter-var CXXFLAGS "$@"
169 return 0 174 return 0
170} 175}
171 176
172filter-lfs-flags() { 177filter-lfs-flags() {
173 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments" 178 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments"
174 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 179 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
175} 180}
176 181
182append-cppflags() {
183 [[ -z $* ]] && return 0
184 export CPPFLAGS="${CPPFLAGS} $*"
185 return 0
186}
187
177append-lfs-flags() { 188append-lfs-flags() {
178 [[ -n $@ ]] && die "append-lfs-flags takes no arguments" 189 [[ -n $@ ]] && die "append-lfs-flags takes no arguments"
179 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 190 append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
180} 191}
181 192
182append-flags() { 193append-flags() {
183 [[ -z $* ]] && return 0 194 [[ -z $* ]] && return 0
184 export CFLAGS="${CFLAGS} $*" 195 export CFLAGS="${CFLAGS} $*"
212 223
213replace-cpu-flags() { 224replace-cpu-flags() {
214 local newcpu="$#" ; newcpu="${!newcpu}" 225 local newcpu="$#" ; newcpu="${!newcpu}"
215 while [ $# -gt 1 ] ; do 226 while [ $# -gt 1 ] ; do
216 # quote to make sure that no globbing is done (particularly on 227 # quote to make sure that no globbing is done (particularly on
217 # ${oldcpu} prior to calling replace-flags 228 # ${oldcpu}) prior to calling replace-flags
218 replace-flags "-march=${1}" "-march=${newcpu}" 229 replace-flags "-march=${1}" "-march=${newcpu}"
219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}" 230 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
220 replace-flags "-mtune=${1}" "-mtune=${newcpu}" 231 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
221 shift 232 shift
222 done 233 done
223 return 0 234 return 0
224} 235}
225 236
237_is_flagq() {
238 local x
239 for x in ${!1} ; do
240 [[ ${x} == $2 ]] && return 0
241 done
242 return 1
243}
244
226is-flagq() { 245is-flagq() {
227 local x 246 [[ -n $2 ]] && die "Usage: is-flag <flag>"
228 247 _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} 248}
237 249
238is-flag() { 250is-flag() {
239 if is-flagq ${1}; then 251 is-flagq "$@" && echo true
240 echo true
241 return 0
242 fi
243 return 1
244} 252}
245 253
246is-ldflagq() { 254is-ldflagq() {
247 local x 255 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
248 256 _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} 257}
257 258
258is-ldflag() { 259is-ldflag() {
259 if is-ldflagq ${1}; then 260 is-ldflagq "$@" && echo true
260 echo true
261 return 0
262 fi
263 return 1
264} 261}
265 262
266filter-mfpmath() { 263filter-mfpmath() {
267 local orig_mfpmath new_math prune_math 264 local orig_mfpmath new_math prune_math
268 265
269 # save the original -mfpmath flag 266 # save the original -mfpmath flag
270 orig_mfpmath="`get-flag -mfpmath`" 267 orig_mfpmath=$(get-flag -mfpmath)
271 # get the value of the current -mfpmath flag 268 # get the value of the current -mfpmath flag
272 new_math=" `get-flag mfpmath | tr , ' '` " 269 new_math=$(get-flag mfpmath)
270 new_math=" ${new_math//,/ } "
273 # figure out which math values are to be removed 271 # figure out which math values are to be removed
274 prune_math="" 272 prune_math=""
275 for prune_math in "$@" ; do 273 for prune_math in "$@" ; do
276 new_math="${new_math/ ${prune_math} / }" 274 new_math=${new_math/ ${prune_math} / }
277 done 275 done
278 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" 276 new_math=$(echo ${new_math})
277 new_math=${new_math// /,}
279 278
280 if [ -z "${new_math}" ] ; then 279 if [[ -z ${new_math} ]] ; then
281 # if we're removing all user specified math values are 280 # if we're removing all user specified math values are
282 # slated for removal, then we just filter the flag 281 # slated for removal, then we just filter the flag
283 filter-flags ${orig_mfpmath} 282 filter-flags ${orig_mfpmath}
284 else 283 else
285 # if we only want to filter some of the user specified 284 # if we only want to filter some of the user specified
362 local flags 361 local flags
363 local x 362 local x
364 363
365 shift 364 shift
366 365
367 [[ -z ${comp} ]] && \ 366 [[ -z ${comp} ]] && return 1
368 return 1
369 367
368 x=""
370 for x in "$@" ; do 369 for x in "$@" ; do
371 test-flag-${comp} "${x}" && flags="${flags} ${x}" 370 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
372 done 371 done
373 372
374 echo "${flags}" 373 echo "${flags}"
375 374
376 # Just bail if we dont have any flags 375 # Just bail if we dont have any flags
401 return 1 400 return 1
402 fi 401 fi
403} 402}
404 403
405strip-unsupported-flags() { 404strip-unsupported-flags() {
406 local x NEW_CFLAGS NEW_CXXFLAGS 405 export CFLAGS=$(test-flags-CC ${CFLAGS})
407 406 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
408 for x in ${CFLAGS} ; do
409 NEW_CFLAGS="${NEW_CFLAGS} $(test-flags ${x})"
410 done
411 for x in ${CXXFLAGS} ; do
412 NEW_CXXFLAGS="${NEW_CXXFLAGS} $(test-flags ${x})"
413 done
414
415 export CFLAGS=${NEW_CFLAGS}
416 export CXXFLAGS=${NEW_CXXFLAGS}
417} 407}
418 408
419get-flag() { 409get-flag() {
420 local f findflag="$1" 410 local f findflag="$1"
421 411
524 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 514 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
525 for x in ${SPARC64_CPUS}; do 515 for x in ${SPARC64_CPUS}; do
526 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 516 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
527 done 517 done
528 else 518 else
529 for x in ${SPARC64_CPUS}; do 519 for x in ${SPARC64_CPUS}; do
530 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 520 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
531 done 521 done
532 fi 522 fi
533 523
534 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then 524 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
535 for x in ${SPARC64_CPUS}; do 525 for x in ${SPARC64_CPUS}; do
536 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 526 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
537 done 527 done
538 else 528 else
539 for x in ${SPARC64_CPUS}; do 529 for x in ${SPARC64_CPUS}; do
540 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 530 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
541 done 531 done
542 fi 532 fi
543 533
544 export CFLAGS CXXFLAGS 534 export CFLAGS CXXFLAGS
567 for x in ${input} ; do 557 for x in ${input} ; do
568 x=${x#-Wl,} 558 x=${x#-Wl,}
569 set -- "$@" ${x//,/ } 559 set -- "$@" ${x//,/ }
570 done 560 done
571 echo "$@" 561 echo "$@"
572}
573
574# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
575# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
576# fixes.
577#
578# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
579gcc2-flags() {
580 if [[ $(tc-arch) == "x86" || $(tc-arch) == "amd64" ]] ; then
581 CFLAGS=${CFLAGS//-mtune=/-mcpu=}
582 CXXFLAGS=${CXXFLAGS//-mtune=/-mcpu=}
583 fi
584
585 replace-cpu-flags k6-{2,3} k6
586 replace-cpu-flags athlon{,-{tbird,4,xp,mp}} i686
587
588 replace-cpu-flags pentium-mmx i586
589 replace-cpu-flags pentium{2,3,4} i686
590
591 replace-cpu-flags ev6{7,8} ev6
592
593 export CFLAGS CXXFLAGS
594} 562}
595 563
596# Gets the flags needed for "NOW" binding 564# Gets the flags needed for "NOW" binding
597bindnow-flags() { 565bindnow-flags() {
598 case $($(tc-getLD) -v 2>&1 </dev/null) in 566 case $($(tc-getLD) -v 2>&1 </dev/null) in
607 echo "-Wl,-z,now" ;; 575 echo "-Wl,-z,now" ;;
608 esac 576 esac
609 ;; 577 ;;
610 esac 578 esac
611} 579}
580
581
582# Some tests for when we screw with things and want to make
583# sure we didn't break anything
584#TESTS() {
585# CFLAGS="-a -b -c=1"
586# CXXFLAGS="-x -y -z=2"
587# LDFLAGS="-l -m -n=3"
588#
589# die() { exit 1; }
590# (is-flag 1 2 3) && die
591# (is-ldflag 1 2 3) && die
592#
593# is-flagq -l && die
594# is-ldflagq -a && die
595# is-flagq -a || die
596# is-flagq -x || die
597# is-ldflagq -n=* || die
598# is-ldflagq -n && die
599#
600# strip-unsupported-flags
601# [[ ${CFLAGS} == "-c=1" ]] || die
602# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
603#
604# echo "All tests pass"
605#}
606#TESTS

Legend:
Removed from v.1.108  
changed lines
  Added in v.1.120

  ViewVC Help
Powered by ViewVC 1.1.20