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

Legend:
Removed from v.1.106  
changed lines
  Added in v.1.118

  ViewVC Help
Powered by ViewVC 1.1.20