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

Legend:
Removed from v.1.107  
changed lines
  Added in v.1.119

  ViewVC Help
Powered by ViewVC 1.1.20