/[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.159 Revision 1.166
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2011 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.159 2011/12/07 06:42:40 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.166 2012/01/14 08:22:13 vapier Exp $
4 4
5# @ECLASS: flag-o-matic.eclass 5# @ECLASS: flag-o-matic.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# toolchain@gentoo.org 7# toolchain@gentoo.org
8# @BLURB: common functions to manipulate and query toolchain flags 8# @BLURB: common functions to manipulate and query toolchain flags
9# @DESCRIPTION: 9# @DESCRIPTION:
10# This eclass contains a suite of functions to help developers sanely 10# This eclass contains a suite of functions to help developers sanely
11# and safely manage toolchain flags in their builds. 11# and safely manage toolchain flags in their builds.
12 12
13if [[ ${___ECLASS_ONCE_FLAG_O_MATIC} != "recur -_+^+_- spank" ]] ; then
14___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
15
13inherit eutils toolchain-funcs multilib 16inherit eutils toolchain-funcs multilib
14
15################ DEPRECATED functions ################
16# The following are still present to avoid breaking existing
17# code more than necessary; however they are deprecated. Please
18# use gcc-specs-* from toolchain-funcs.eclass instead, if you
19# need to know which hardened techs are active in the compiler.
20# See bug #100974
21#
22# has_hardened
23# has_pie
24# has_pic
25# has_ssp_all
26# has_ssp
27
28 17
29# {C,CXX,F,FC}FLAGS that we allow in strip-flags 18# {C,CXX,F,FC}FLAGS that we allow in strip-flags
30# Note: shell globs and character lists are allowed 19# Note: shell globs and character lists are allowed
31setup-allowed-flags() { 20setup-allowed-flags() {
32 if [[ -z ${ALLOWED_FLAGS} ]] ; then
33 export ALLOWED_FLAGS="-pipe" 21 ALLOWED_FLAGS="-pipe"
34 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune" 22 ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune"
35 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all" 23 ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all"
36 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-strict-overflow" 24 ALLOWED_FLAGS+=" -fbounds-checking -fno-strict-overflow"
37 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time" 25 ALLOWED_FLAGS+=" -fno-PIE -fno-pie -fno-unit-at-a-time"
38 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+" 26 ALLOWED_FLAGS+=" -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+"
39 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident -fpermissive" 27 ALLOWED_FLAGS+=" -fno-ident -fpermissive"
40 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w" 28 ALLOWED_FLAGS+=" -W* -w"
41 fi 29
42 # allow a bunch of flags that negate features / control ABI 30 # allow a bunch of flags that negate features / control ABI
43 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all \ 31 ALLOWED_FLAGS+=" -fno-stack-protector -fno-stack-protector-all \
44 -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer" 32 -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow \
33 -fno-omit-frame-pointer"
45 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs \ 34 ALLOWED_FLAGS+=" -mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse \
46 -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 \ 35 -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 \
47 -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow \ 36 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt \
48 -mno-popcnt -mno-abm \
49 -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \ 37 -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt \
50 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \ 38 -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu \
51 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \ 39 -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe \
52 -mtls-direct-seg-refs -mno-tls-direct-seg-refs \ 40 -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat \
53 -mflat -mno-flat -mno-faster-structs -mfaster-structs \ 41 -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi \
54 -m32 -m64 -mx32 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC \ 42 -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel \
55 -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias \ 43 -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -D* -U*"
56 -msecure-plt -m*-toc -D* -U*"
57 44
58 # 4.5 45 # 4.5
59 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fma4 -mno-movbe -mno-xop -mno-lwp" 46 ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp"
60 # 4.6 47 # 4.6
61 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fsgsbase -mno-rdrnd -mno-f16c \ 48 ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm"
62 -mno-bmi -mno-tbm"
63 49
64 # {C,CXX,F,FC}FLAGS that we are think is ok, but needs testing 50 export ALLOWED_FLAGS
65 # NOTE: currently -Os have issues with gcc3 and K6* arch's
66 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks"
67 return 0 51 return 0
68} 52}
69 53
70# inverted filters for hardened compiler. This is trying to unpick 54# inverted filters for hardened compiler. This is trying to unpick
71# the hardened compiler defaults. 55# the hardened compiler defaults.
113} 97}
114 98
115# @FUNCTION: filter-flags 99# @FUNCTION: filter-flags
116# @USAGE: <flags> 100# @USAGE: <flags>
117# @DESCRIPTION: 101# @DESCRIPTION:
118# Remove particular <flags> from {C,CPP,CXX,F,FC}FLAGS. Accepts shell globs. 102# Remove particular <flags> from {C,CPP,CXX,F,FC,LD}FLAGS. Accepts shell globs.
119filter-flags() { 103filter-flags() {
120 _filter-hardened "$@" 104 _filter-hardened "$@"
105 local v
106 for v in C CPP CXX F FC LD ; do
121 _filter-var CFLAGS "$@" 107 _filter-var ${v}FLAGS "$@"
122 _filter-var CPPFLAGS "$@" 108 done
123 _filter-var CXXFLAGS "$@"
124 _filter-var FFLAGS "$@"
125 _filter-var FCFLAGS "$@"
126 return 0 109 return 0
127} 110}
128 111
129# @FUNCTION: filter-lfs-flags 112# @FUNCTION: filter-lfs-flags
130# @DESCRIPTION: 113# @DESCRIPTION:
333 local NEW_CFLAGS="" 316 local NEW_CFLAGS=""
334 local NEW_CXXFLAGS="" 317 local NEW_CXXFLAGS=""
335 local NEW_FFLAGS="" 318 local NEW_FFLAGS=""
336 local NEW_FCFLAGS="" 319 local NEW_FCFLAGS=""
337 320
338 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
339 if has "~$(tc-arch)" ${ACCEPT_KEYWORDS} ; then
340 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
341 fi
342
343 set -f # disable pathname expansion 321 set -f # disable pathname expansion
344 322
345 for x in ${CFLAGS}; do 323 for x in ${CFLAGS}; do
346 for y in ${ALLOWED_FLAGS}; do 324 for y in ${ALLOWED_FLAGS}; do
347 flag=${x%%=*} 325 flag=${x%%=*}
533 fi 511 fi
534 done 512 done
535 return 1 513 return 1
536} 514}
537 515
538# DEAD FUNCS. Remove by Dec 2011.
539test_flag() { die "$0: deprecated, please use test-flags()!" ; }
540has_hardened() { die "$0: deprecated, please use gcc-specs-{relro,now}()!" ; }
541has_pic() { die "$0: deprecated, please use gcc-specs-pie()!" ; }
542has_pie() { die "$0: deprecated, please use gcc-specs-pie()!" ; }
543has_ssp_all() { die "$0: deprecated, please use gcc-specs-ssp()!" ; }
544has_ssp() { die "$0: deprecated, please use gcc-specs-ssp()!" ; }
545
546# @FUNCTION: has_m64 516# @FUNCTION: has_m64
547# @DESCRIPTION: 517# @DESCRIPTION:
548# This doesn't test if the flag is accepted, it tests if the flag actually 518# This doesn't test if the flag is accepted, it tests if the flag actually
549# WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works 519# WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works
550# return code is 0, else the return code is 1. 520# return code is 0, else the return code is 1.
551has_m64() { 521has_m64() {
522 eqawarn "${FUNCNAME}: don't use this anymore"
523
552 # this doesnt test if the flag is accepted, it tests if the flag 524 # this doesnt test if the flag is accepted, it tests if the flag
553 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 525 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
554 # please dont replace this function with test_flag in some future 526 # please dont replace this function with test_flag in some future
555 # clean-up! 527 # clean-up!
556 528
562 rm -f "${temp}".c 534 rm -f "${temp}".c
563 [[ ${ret} != 1 ]] && return 0 535 [[ ${ret} != 1 ]] && return 0
564 return 1 536 return 1
565} 537}
566 538
567# @FUNCTION: has_m32
568# @DESCRIPTION:
569# This doesn't test if the flag is accepted, it tests if the flag actually
570# WORKS. Non-mulilib gcc will take both -m32 and -64. If the flag works return
571# code is 0, else return code is 1.
572has_m32() { 539has_m32() {
573 # this doesnt test if the flag is accepted, it tests if the flag 540 die "${FUNCNAME}: don't use this anymore"
574 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
575 # please dont replace this function with test_flag in some future
576 # clean-up!
577
578 [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0
579
580 local temp=$(emktemp)
581 echo "int main() { return(0); }" > "${temp}".c
582 MY_CC=$(tc-getCC)
583 ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1
584 local ret=$?
585 rm -f "${temp}".c
586 [[ ${ret} != 1 ]] && return 0
587 return 1
588} 541}
589 542
590# @FUNCTION: replace-sparc64-flags 543# @FUNCTION: replace-sparc64-flags
591# @DESCRIPTION: 544# @DESCRIPTION:
592# Sets mcpu to v8 and uses the original value as mtune if none specified. 545# Sets mcpu to v8 and uses the original value as mtune if none specified.
682 *GNU*) # GNU ld 635 *GNU*) # GNU ld
683 echo "-Wl,--no-as-needed" ;; 636 echo "-Wl,--no-as-needed" ;;
684 esac 637 esac
685} 638}
686 639
687# Some tests for when we screw with things and want to make 640fi
688# sure we didn't break anything
689#TESTS() {
690# CFLAGS="-a -b -c=1"
691# CXXFLAGS="-x -y -z=2"
692# LDFLAGS="-l -m -n=3"
693#
694# die() { exit 1; }
695# (is-flag 1 2 3) && die
696# (is-ldflag 1 2 3) && die
697#
698# is-flagq -l && die
699# is-ldflagq -a && die
700# is-flagq -a || die
701# is-flagq -x || die
702# is-ldflagq -n=* || die
703# is-ldflagq -n && die
704#
705# strip-unsupported-flags
706# [[ ${CFLAGS} == "-c=1" ]] || die
707# [[ ${CXXFLAGS} == "-y -z=2" ]] || die
708#
709# echo "All tests pass"
710#}
711#TESTS

Legend:
Removed from v.1.159  
changed lines
  Added in v.1.166

  ViewVC Help
Powered by ViewVC 1.1.20