/[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.111 Revision 1.119
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.111 2006/10/14 20:27:21 swegener 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: 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"
104 fi 105 fi
105 # allow a bunch of flags that negate features / control ABI 106 # allow a bunch of flags that negate features / control ABI
106 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"
107 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ 109 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \
108 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \ 110 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow \
109 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \ 111 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 \
110 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 112 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
111 -mieee -mieee-with-inexact -mschedule \ 113 -mieee -mieee-with-inexact -mschedule \
112 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ 114 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \
113 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 115 -mflat -mno-flat -mno-faster-structs -mfaster-structs \
114 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 116 -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \
115 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias" 117 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \
118 -msecure-plt -D*"
116 119
117 # 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
118 # NOTE: currently -Os have issues with gcc3 and K6* arch's 121 # NOTE: currently -Os have issues with gcc3 and K6* arch's
119 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks" 122 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
120 return 0 123 return 0
163} 166}
164 167
165filter-flags() { 168filter-flags() {
166 _filter-hardened "$@" 169 _filter-hardened "$@"
167 _filter-var CFLAGS "$@" 170 _filter-var CFLAGS "$@"
171 _filter-var CPPFLAGS "$@"
168 _filter-var CXXFLAGS "$@" 172 _filter-var CXXFLAGS "$@"
169 return 0 173 return 0
170} 174}
171 175
172filter-lfs-flags() { 176filter-lfs-flags() {
173 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments" 177 [[ -n $@ ]] && die "filter-lfs-flags takes no arguments"
174 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
175} 179}
176 180
181append-cppflags() {
182 [[ -z $* ]] && return 0
183 export CPPFLAGS="${CPPFLAGS} $*"
184 return 0
185}
186
177append-lfs-flags() { 187append-lfs-flags() {
178 [[ -n $@ ]] && die "append-lfs-flags takes no arguments" 188 [[ -n $@ ]] && die "append-lfs-flags takes no arguments"
179 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
180} 190}
181 191
182append-flags() { 192append-flags() {
183 [[ -z $* ]] && return 0 193 [[ -z $* ]] && return 0
184 export CFLAGS="${CFLAGS} $*" 194 export CFLAGS="${CFLAGS} $*"
212 222
213replace-cpu-flags() { 223replace-cpu-flags() {
214 local newcpu="$#" ; newcpu="${!newcpu}" 224 local newcpu="$#" ; newcpu="${!newcpu}"
215 while [ $# -gt 1 ] ; do 225 while [ $# -gt 1 ] ; do
216 # quote to make sure that no globbing is done (particularly on 226 # quote to make sure that no globbing is done (particularly on
217 # ${oldcpu} prior to calling replace-flags 227 # ${oldcpu}) prior to calling replace-flags
218 replace-flags "-march=${1}" "-march=${newcpu}" 228 replace-flags "-march=${1}" "-march=${newcpu}"
219 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}" 229 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
220 replace-flags "-mtune=${1}" "-mtune=${newcpu}" 230 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
221 shift 231 shift
222 done 232 done
223 return 0 233 return 0
224} 234}
225 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
226is-flagq() { 244is-flagq() {
227 local x 245 [[ -n $2 ]] && die "Usage: is-flag <flag>"
228 246 _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} 247}
237 248
238is-flag() { 249is-flag() {
239 if is-flagq ${1}; then 250 is-flagq "$@" && echo true
240 echo true
241 return 0
242 fi
243 return 1
244} 251}
245 252
246is-ldflagq() { 253is-ldflagq() {
247 local x 254 [[ -n $2 ]] && die "Usage: is-ldflag <flag>"
248 255 _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} 256}
257 257
258is-ldflag() { 258is-ldflag() {
259 if is-ldflagq ${1}; then 259 is-ldflagq "$@" && echo true
260 echo true
261 return 0
262 fi
263 return 1
264} 260}
265 261
266filter-mfpmath() { 262filter-mfpmath() {
267 local orig_mfpmath new_math prune_math 263 local orig_mfpmath new_math prune_math
268 264
364 local flags 360 local flags
365 local x 361 local x
366 362
367 shift 363 shift
368 364
369 [[ -z ${comp} ]] && \ 365 [[ -z ${comp} ]] && return 1
370 return 1
371 366
367 x=""
372 for x in "$@" ; do 368 for x in "$@" ; do
373 test-flag-${comp} "${x}" && flags="${flags} ${x}" 369 test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}"
374 done 370 done
375 371
376 echo "${flags}" 372 echo "${flags}"
377 373
378 # Just bail if we dont have any flags 374 # Just bail if we dont have any flags
403 return 1 399 return 1
404 fi 400 fi
405} 401}
406 402
407strip-unsupported-flags() { 403strip-unsupported-flags() {
408 local x NEW_CFLAGS NEW_CXXFLAGS 404 export CFLAGS=$(test-flags-CC ${CFLAGS})
409 405 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} 406}
420 407
421get-flag() { 408get-flag() {
422 local f findflag="$1" 409 local f findflag="$1"
423 410
569 for x in ${input} ; do 556 for x in ${input} ; do
570 x=${x#-Wl,} 557 x=${x#-Wl,}
571 set -- "$@" ${x//,/ } 558 set -- "$@" ${x//,/ }
572 done 559 done
573 echo "$@" 560 echo "$@"
574}
575
576# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
577# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
578# fixes.
579#
580# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
581gcc2-flags() {
582 if [[ $(tc-arch) == "x86" || $(tc-arch) == "amd64" ]] ; then
583 CFLAGS=${CFLAGS//-mtune=/-mcpu=}
584 CXXFLAGS=${CXXFLAGS//-mtune=/-mcpu=}
585 fi
586
587 replace-cpu-flags k6-{2,3} k6
588 replace-cpu-flags athlon{,-{tbird,4,xp,mp}} i686
589
590 replace-cpu-flags pentium-mmx i586
591 replace-cpu-flags pentium{2,3,4} i686
592
593 replace-cpu-flags ev6{7,8} ev6
594
595 export CFLAGS CXXFLAGS
596} 561}
597 562
598# Gets the flags needed for "NOW" binding 563# Gets the flags needed for "NOW" binding
599bindnow-flags() { 564bindnow-flags() {
600 case $($(tc-getLD) -v 2>&1 </dev/null) in 565 case $($(tc-getLD) -v 2>&1 </dev/null) in
609 echo "-Wl,-z,now" ;; 574 echo "-Wl,-z,now" ;;
610 esac 575 esac
611 ;; 576 ;;
612 esac 577 esac
613} 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.111  
changed lines
  Added in v.1.119

  ViewVC Help
Powered by ViewVC 1.1.20