/[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.11 Revision 1.27
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
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.27 2003/09/24 05:51:32 solar Exp $
4#
3# Author Bart Verwilst <verwilst@gentoo.org> 5# Author Bart Verwilst <verwilst@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.11 2002/12/22 12:11:56 cretin Exp $
5 6
6ECLASS=flag-o-matic 7ECLASS=flag-o-matic
7INHERITED="$INHERITED $ECLASS" 8INHERITED="$INHERITED $ECLASS"
8 9
9# 10#
10#### filter-flags <flag> #### 11#### filter-flags <flags> ####
11# Remove particular flags from C[XX]FLAGS 12# Remove particular flags from C[XX]FLAGS
13# Matches only complete flags
12# 14#
13#### append-flags <flag> #### 15#### append-flags <flags> ####
14# Add extra flags to your current C[XX]FLAGS 16# Add extra flags to your current C[XX]FLAGS
15# 17#
16#### replace-flags <orig.flag> <new.flag> ### 18#### replace-flags <orig.flag> <new.flag> ###
17# Replace a flag by another one 19# Replace a flag by another one
18# 20#
19#### is-flag <flag> #### 21#### is-flag <flag> ####
20# Returns "true" if flag is set in C[XX]FLAGS 22# Returns "true" if flag is set in C[XX]FLAGS
21# Matches only complete flag 23# Matches only complete a flag
22# 24#
23#### strip-flags #### 25#### strip-flags ####
24# Strip C[XX]FLAGS of everything except known 26# Strip C[XX]FLAGS of everything except known
25# good options. 27# good options.
26# 28#
27#### get-flag <flag> #### 29#### get-flag <flag> ####
28# Find and echo the value for a particular flag 30# Find and echo the value for a particular flag
29# 31#
32#### replace-sparc64-flags ####
33# Sets mcpu to v8 and uses the original value
34# as mtune if none specified.
35#
36#### filter-mfpmath <math types> ####
37# Remove specified math types from the fpmath specification
38# If the user has -mfpmath=sse,386, running `filter-mfpmath sse`
39# will leave the user with -mfpmath=386
40#
41#### append-ldflags ####
42# Add extra flags to your current LDFLAGS
43#
44#### etexec-flags ####
45# hooked function for hardened-gcc that appends
46# -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed
47# and a package is filtering -fPIC
48#
49#### fstack-flags ####
50# hooked function for hardened-gcc that appends
51# -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed
52# and a package is filtering -fstack-protector
53#
30 54
55# C[XX]FLAGS that we allow in strip-flags
56ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
57case "${ARCH}" in
58 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
59 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
60 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
61esac
62
63# C[XX]FLAGS that we are think is ok, but needs testing
64# NOTE: currently -Os have issues with gcc3 and K6* arch's
65UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
66
67filter-mfpmath() {
68 for a in $CFLAGS; do
69 if [ "${a:0:8}" == "-mfpmath" ]; then
70 orig_mfpmath=$a
71 fi
72 done
73
74 mfpmath="$( echo $orig_mfpmath | awk -F '=' '{print $2}' | tr "," " " )"
75 for b in $@; do
76 mfpmath="${mfpmath/$b}"
77 done
78
79 if [ -z "${mfpmath/ }" ]; then
80 filter-flags "$orig_mfpmath"
81 else
82 new_mfpmath="-mfpmath=$( echo $mfpmath | sed -e "s/ /,/g" -e "s/,,/,/g" )"
83 replace-flags "$orig_mfpmath" "$new_mfpmath"
84 fi
85}
86
31filter-flags () { 87filter-flags() {
32 88 # we do two loops to avoid the first and last char from being chomped.
33 for x in $1 89 for x in $@ ; do
90 case "${x}" in
91 -fPIC) etexec-flags;;
92 -fstack-protector) fstack-flags;;
93 *) ;;
94 esac
34 do 95 done
96 # we do this fancy spacing stuff so as to not filter
97 # out part of a flag ... we want flag atoms ! :D
98 CFLAGS=" ${CFLAGS} "
99 CXXFLAGS=" ${CXXFLAGS} "
100 for x in $@ ; do
35 export CFLAGS="${CFLAGS/${x}}" 101 CFLAGS="${CFLAGS/ ${x} / }"
36 export CXXFLAGS="${CXXFLAGS/${x}}" 102 CXXFLAGS="${CXXFLAGS/ ${x} / }"
37 done 103 done
38 104 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
105 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
39} 106}
40 107
41append-flags () { 108append-flags() {
42
43 CFLAGS="${CFLAGS} $1" 109 CFLAGS="${CFLAGS} $@"
44 CXXFLAGS="${CXXFLAGS} $1" 110 CXXFLAGS="${CXXFLAGS} $@"
45 111 for x in $@; do
112 [ "${x}" = "-fno-stack-protector" ] &&
113 fstack-flags
114 done
46} 115}
47 116
48replace-flags () { 117replace-flags() {
49
50 CFLAGS="${CFLAGS/${1}/${2} }" 118 CFLAGS="${CFLAGS/${1}/${2} }"
51 CXXFLAGS="${CXXFLAGS/${1}/${2} }" 119 CXXFLAGS="${CXXFLAGS/${1}/${2} }"
52
53} 120}
54 121
55is-flag() { 122is-flag() {
56
57 for x in ${CFLAGS} ${CXXFLAGS} 123 for x in ${CFLAGS} ${CXXFLAGS} ; do
58 do
59 if [ "${x}" = "$1" ] 124 if [ "${x}" == "$1" ] ; then
60 then
61 echo true 125 echo true
62 break 126 return 0
63 fi 127 fi
64 done 128 done
65 129 return 1
66} 130}
67 131
68strip-flags() { 132strip-flags() {
69
70 local NEW_CFLAGS="" 133 local NEW_CFLAGS=""
71 local NEW_CXXFLAGS="" 134 local NEW_CXXFLAGS=""
72 135
73 local ALLOWED_FLAGS="-O -mcpu -march -pipe -g" 136 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
137 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then
138 [ `use debug` ] && einfo "Enabling the use of some unstable flags"
139 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
140 fi
74 141
75 set -f 142 set -f
76 143
77 for x in ${CFLAGS} 144 for x in ${CFLAGS}
78 do 145 do
79 for y in ${ALLOWED_FLAGS} 146 for y in ${ALLOWED_FLAGS}
80 do 147 do
148 flag=${x%%=*}
81 if [ "${x/${y}}" != "${x}" ] 149 if [ "${flag%%${y}}" = "" ]
82 then 150 then
83 if [ -z "${NEW_CFLAGS}" ]
84 then
85 NEW_CFLAGS="${x}"
86 else
87 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 151 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
88 fi 152 break
89 fi 153 fi
90 done 154 done
91 done 155 done
92 156
93 for x in ${CXXFLAGS} 157 for x in ${CXXFLAGS}
94 do 158 do
95 for y in ${ALLOWED_FLAGS} 159 for y in ${ALLOWED_FLAGS}
96 do 160 do
161 flag=${x%%=*}
97 if [ "${x/${y}}" != "${x}" ] 162 if [ "${flag%%${y}}" = "" ]
98 then 163 then
99 if [ -z "${NEW_CXXFLAGS}" ]
100 then
101 NEW_CXXFLAGS="${x}"
102 else
103 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 164 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
104 fi 165 break
105 fi 166 fi
106 done 167 done
107 done 168 done
108 169
109 set +f 170 set +f
171
172 [ `use debug` ] \
173 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
174 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
110 175
111 export CFLAGS="${NEW_CFLAGS}" 176 export CFLAGS="${NEW_CFLAGS}"
112 export CXXFLAGS="${NEW_CXXFLAGS}" 177 export CXXFLAGS="${NEW_CXXFLAGS}"
113} 178}
114 179
120 echo "${f/-${findflag}=}" 185 echo "${f/-${findflag}=}"
121 return 186 return
122 fi 187 fi
123 done 188 done
124} 189}
190
191replace-sparc64-flags() {
192 local SPARC64_CPUS="ultrasparc v9"
193
194 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
195 then
196 for x in ${SPARC64_CPUS}
197 do
198 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
199 done
200 else
201 for x in ${SPARC64_CPUS}
202 do
203 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
204 done
205 fi
206
207 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]
208 then
209 for x in ${SPARC64_CPUS}
210 do
211 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
212 done
213 else
214 for x in ${SPARC64_CPUS}
215 do
216 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
217 done
218 fi
219}
220
221append-ldflags() {
222 LDFLAGS="${LDFLAGS} $@"
223}
224
225etexec-flags() {
226 has_version 'sys-devel/hardened-gcc' && {
227 debug-print ">>> appending flags -yet_exec"
228 append-flags -yet_exec
229 append-ldflags -yet_exec
230 }
231}
232
233fstack-flags() {
234 has_version 'sys-devel/hardened-gcc' && {
235 debug-print ">>> appending flags -yno_propolice"
236 append-flags -yno_propolice
237 append-ldflags -yno_propolice
238 }
239}

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.20