| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2004 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.28 2003/10/26 00:40:52 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.62 2004/07/15 04:59:44 lv Exp $ |
| 4 | # |
4 | # |
| 5 | # Author Bart Verwilst <verwilst@gentoo.org> |
5 | # Author Bart Verwilst <verwilst@gentoo.org> |
| 6 | |
6 | |
| 7 | ECLASS=flag-o-matic |
7 | ECLASS=flag-o-matic |
| 8 | INHERITED="$INHERITED $ECLASS" |
8 | INHERITED="$INHERITED $ECLASS" |
|
|
9 | IUSE="$IUSE debug" |
| 9 | |
10 | |
| 10 | # |
11 | # |
| 11 | #### filter-flags <flags> #### |
12 | #### filter-flags <flags> #### |
| 12 | # Remove particular flags from C[XX]FLAGS |
13 | # Remove particular flags from C[XX]FLAGS |
| 13 | # Matches only complete flags |
14 | # Matches only complete flags |
| … | |
… | |
| 16 | # Add extra flags to your current C[XX]FLAGS |
17 | # Add extra flags to your current C[XX]FLAGS |
| 17 | # |
18 | # |
| 18 | #### replace-flags <orig.flag> <new.flag> ### |
19 | #### replace-flags <orig.flag> <new.flag> ### |
| 19 | # Replace a flag by another one |
20 | # Replace a flag by another one |
| 20 | # |
21 | # |
|
|
22 | #### replace-cpu-flags <new.cpu> <old.cpus> ### |
|
|
23 | # Replace march/mcpu flags that specify <old.cpus> |
|
|
24 | # with flags that specify <new.cpu> |
|
|
25 | # |
| 21 | #### is-flag <flag> #### |
26 | #### is-flag <flag> #### |
| 22 | # Returns "true" if flag is set in C[XX]FLAGS |
27 | # Returns "true" if flag is set in C[XX]FLAGS |
| 23 | # Matches only complete a flag |
28 | # Matches only complete a flag |
| 24 | # |
29 | # |
| 25 | #### strip-flags #### |
30 | #### strip-flags #### |
| 26 | # Strip C[XX]FLAGS of everything except known |
31 | # Strip C[XX]FLAGS of everything except known |
| 27 | # good options. |
32 | # good options. |
|
|
33 | # |
|
|
34 | #### strip-unsupported-flags #### |
|
|
35 | # Strip C[XX]FLAGS of any flags not supported by |
|
|
36 | # installed version of gcc |
| 28 | # |
37 | # |
| 29 | #### get-flag <flag> #### |
38 | #### get-flag <flag> #### |
| 30 | # Find and echo the value for a particular flag |
39 | # Find and echo the value for a particular flag |
| 31 | # |
40 | # |
| 32 | #### replace-sparc64-flags #### |
41 | #### replace-sparc64-flags #### |
| … | |
… | |
| 39 | # will leave the user with -mfpmath=386 |
48 | # will leave the user with -mfpmath=386 |
| 40 | # |
49 | # |
| 41 | #### append-ldflags #### |
50 | #### append-ldflags #### |
| 42 | # Add extra flags to your current LDFLAGS |
51 | # Add extra flags to your current LDFLAGS |
| 43 | # |
52 | # |
|
|
53 | #### filter-ldflags <flags> #### |
|
|
54 | # Remove particular flags from LDFLAGS |
|
|
55 | # Matches only complete flags |
|
|
56 | # |
| 44 | #### etexec-flags #### |
57 | #### etexec-flags #### |
| 45 | # hooked function for hardened-gcc that appends |
58 | # hooked function for hardened gcc that appends |
| 46 | # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed |
59 | # -fno-pic to {C,CXX,LD}FLAGS |
| 47 | # and a package is filtering -fPIC |
60 | # when a package is filtering -fpic, -fPIC, -fpie, -fPIE |
| 48 | # |
61 | # |
| 49 | #### fstack-flags #### |
62 | #### fstack-flags #### |
| 50 | # hooked function for hardened-gcc that appends |
63 | # hooked function for hardened gcc that appends |
| 51 | # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed |
64 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
| 52 | # and a package is filtering -fstack-protector |
65 | # when a package is filtering -fstack-protector, -fstack-protector-all |
|
|
66 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
|
|
67 | # when only -fno-stack-protector is given |
| 53 | # |
68 | # |
| 54 | |
69 | |
| 55 | # C[XX]FLAGS that we allow in strip-flags |
70 | # C[XX]FLAGS that we allow in strip-flags |
|
|
71 | setup-allowed-flags() { |
|
|
72 | if [ -z "${ALLOWED_FLAGS}" ] ; then |
| 56 | ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
73 | export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-unit-at-a-time -pipe -g" |
| 57 | case "${ARCH}" in |
74 | case "${ARCH}" in |
| 58 | mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; |
75 | mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; |
| 59 | amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
76 | amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; |
|
|
77 | x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; |
| 60 | alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
78 | alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
79 | ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
| 61 | esac |
80 | esac |
|
|
81 | fi |
| 62 | |
82 | |
| 63 | # C[XX]FLAGS that we are think is ok, but needs testing |
83 | # C[XX]FLAGS that we are think is ok, but needs testing |
| 64 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
84 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
| 65 | UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
85 | export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
| 66 | |
86 | return 0 |
| 67 | filter-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 | } |
87 | } |
| 86 | |
88 | |
| 87 | filter-flags() { |
89 | filter-flags() { |
| 88 | # we do two loops to avoid the first and last char from being chomped. |
90 | local x f fset |
|
|
91 | declare -a new_CFLAGS new_CXXFLAGS |
|
|
92 | |
| 89 | for x in $@ ; do |
93 | for x in "$@" ; do |
| 90 | case "${x}" in |
94 | case "${x}" in |
| 91 | -fPIC) etexec-flags;; |
95 | -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; |
| 92 | -fstack-protector) fstack-flags;; |
96 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
| 93 | *) ;; |
|
|
| 94 | esac |
97 | esac |
| 95 | done |
98 | done |
|
|
99 | |
|
|
100 | for fset in CFLAGS CXXFLAGS; do |
|
|
101 | for f in ${!fset}; do |
|
|
102 | for x in "$@"; do |
|
|
103 | # Note this should work with globs like -O* |
|
|
104 | [[ ${f} == ${x} ]] && continue 2 |
|
|
105 | done |
|
|
106 | eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f} |
|
|
107 | done |
|
|
108 | eval export ${fset}=\${new_${fset}\[*]} |
|
|
109 | done |
|
|
110 | |
|
|
111 | return 0 |
|
|
112 | } |
|
|
113 | |
|
|
114 | filter-lfs-flags() { |
|
|
115 | filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
|
|
116 | } |
|
|
117 | |
|
|
118 | append-lfs-flags() { |
|
|
119 | append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
|
|
120 | } |
|
|
121 | |
|
|
122 | append-flags() { |
|
|
123 | export CFLAGS="${CFLAGS} $*" |
|
|
124 | export CXXFLAGS="${CXXFLAGS} $*" |
|
|
125 | [ -n "`is-flag -fno-stack-protector`" -o \ |
|
|
126 | -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags |
|
|
127 | return 0 |
|
|
128 | } |
|
|
129 | |
|
|
130 | replace-flags() { |
| 96 | # we do this fancy spacing stuff so as to not filter |
131 | # we do this fancy spacing stuff so as to not filter |
| 97 | # out part of a flag ... we want flag atoms ! :D |
132 | # out part of a flag ... we want flag atoms ! :D |
| 98 | CFLAGS=" ${CFLAGS} " |
133 | CFLAGS=" ${CFLAGS} " |
| 99 | CXXFLAGS=" ${CXXFLAGS} " |
134 | CXXFLAGS=" ${CXXFLAGS} " |
| 100 | for x in $@ ; do |
|
|
| 101 | CFLAGS="${CFLAGS/ ${x} / }" |
135 | CFLAGS="${CFLAGS// ${1} / ${2} }" |
| 102 | CXXFLAGS="${CXXFLAGS/ ${x} / }" |
136 | CXXFLAGS="${CXXFLAGS// ${1} / ${2} }" |
| 103 | done |
|
|
| 104 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
137 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
| 105 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
138 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
| 106 | } |
139 | export CFLAGS CXXFLAGS |
| 107 | |
|
|
| 108 | append-flags() { |
|
|
| 109 | CFLAGS="${CFLAGS} $@" |
|
|
| 110 | CXXFLAGS="${CXXFLAGS} $@" |
|
|
| 111 | for x in $@; do |
|
|
| 112 | [ "${x}" = "-fno-stack-protector" ] && fstack-flags |
|
|
| 113 | done |
|
|
| 114 | return 0 |
140 | return 0 |
| 115 | } |
141 | } |
| 116 | |
142 | |
| 117 | replace-flags() { |
143 | replace-cpu-flags() { |
| 118 | CFLAGS="${CFLAGS/${1}/${2} }" |
144 | local oldcpu newcpu="$1" ; shift |
| 119 | CXXFLAGS="${CXXFLAGS/${1}/${2} }" |
145 | for oldcpu in "$@" ; do |
|
|
146 | replace-flags -march=${oldcpu} -march=${newcpu} |
|
|
147 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
|
|
148 | replace-flags -mtune=${oldcpu} -mtune=${newcpu} |
|
|
149 | done |
| 120 | return 0 |
150 | return 0 |
| 121 | } |
151 | } |
| 122 | |
152 | |
| 123 | is-flag() { |
153 | is-flag() { |
|
|
154 | local x |
|
|
155 | |
| 124 | for x in ${CFLAGS} ${CXXFLAGS} ; do |
156 | for x in ${CFLAGS} ${CXXFLAGS} ; do |
| 125 | if [ "${x}" == "$1" ] ; then |
157 | if [ "${x}" == "$1" ] ; then |
| 126 | echo true |
158 | echo true |
| 127 | return 0 |
159 | return 0 |
| 128 | fi |
160 | fi |
| 129 | done |
161 | done |
| 130 | return 1 |
162 | return 1 |
| 131 | } |
163 | } |
| 132 | |
164 | |
|
|
165 | filter-mfpmath() { |
|
|
166 | local orig_mfpmath new_math prune_math |
|
|
167 | |
|
|
168 | # save the original -mfpmath flag |
|
|
169 | orig_mfpmath="`get-flag -mfpmath`" |
|
|
170 | # get the value of the current -mfpmath flag |
|
|
171 | new_math=" `get-flag mfpmath | tr , ' '` " |
|
|
172 | # figure out which math values are to be removed |
|
|
173 | prune_math="" |
|
|
174 | for prune_math in "$@" ; do |
|
|
175 | new_math="${new_math/ ${prune_math} / }" |
|
|
176 | done |
|
|
177 | new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" |
|
|
178 | |
|
|
179 | if [ -z "${new_math}" ] ; then |
|
|
180 | # if we're removing all user specified math values are |
|
|
181 | # slated for removal, then we just filter the flag |
|
|
182 | filter-flags ${orig_mfpmath} |
|
|
183 | else |
|
|
184 | # if we only want to filter some of the user specified |
|
|
185 | # math values, then we replace the current flag |
|
|
186 | replace-flags ${orig_mfpmath} -mfpmath=${new_math} |
|
|
187 | fi |
|
|
188 | return 0 |
|
|
189 | } |
|
|
190 | |
| 133 | strip-flags() { |
191 | strip-flags() { |
|
|
192 | local x y flag NEW_CFLAGS NEW_CXXFLAGS |
|
|
193 | |
|
|
194 | setup-allowed-flags |
|
|
195 | |
| 134 | local NEW_CFLAGS="" |
196 | local NEW_CFLAGS="" |
| 135 | local NEW_CXXFLAGS="" |
197 | local NEW_CXXFLAGS="" |
| 136 | |
198 | |
| 137 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
199 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
| 138 | if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then |
200 | if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then |
| 139 | [ `use debug` ] && einfo "Enabling the use of some unstable flags" |
201 | use debug && einfo "Enabling the use of some unstable flags" |
| 140 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
202 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
| 141 | fi |
203 | fi |
| 142 | |
204 | |
| 143 | set -f |
205 | set -f # disable pathname expansion |
| 144 | |
206 | |
| 145 | for x in ${CFLAGS} |
207 | for x in ${CFLAGS}; do |
| 146 | do |
|
|
| 147 | for y in ${ALLOWED_FLAGS} |
208 | for y in ${ALLOWED_FLAGS}; do |
| 148 | do |
|
|
| 149 | flag=${x%%=*} |
209 | flag=${x%%=*} |
| 150 | if [ "${flag%%${y}}" = "" ] |
210 | if [ "${flag%%${y}}" = "" ]; then |
| 151 | then |
|
|
| 152 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
211 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
| 153 | break |
212 | break |
| 154 | fi |
213 | fi |
| 155 | done |
214 | done |
| 156 | done |
215 | done |
| 157 | |
216 | |
| 158 | for x in ${CXXFLAGS} |
217 | for x in ${CXXFLAGS}; do |
| 159 | do |
|
|
| 160 | for y in ${ALLOWED_FLAGS} |
218 | for y in ${ALLOWED_FLAGS}; do |
| 161 | do |
|
|
| 162 | flag=${x%%=*} |
219 | flag=${x%%=*} |
| 163 | if [ "${flag%%${y}}" = "" ] |
220 | if [ "${flag%%${y}}" = "" ]; then |
| 164 | then |
|
|
| 165 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
221 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
| 166 | break |
222 | break |
| 167 | fi |
223 | fi |
| 168 | done |
224 | done |
| 169 | done |
225 | done |
| 170 | |
226 | |
| 171 | set +f |
227 | # In case we filtered out all optimization flags fallback to -O2 |
|
|
228 | if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then |
|
|
229 | NEW_CFLAGS="${NEW_CFLAGS} -O2" |
|
|
230 | fi |
|
|
231 | if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then |
|
|
232 | NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" |
|
|
233 | fi |
| 172 | |
234 | |
| 173 | [ `use debug` ] \ |
235 | set +f # re-enable pathname expansion |
| 174 | && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ |
|
|
| 175 | && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" |
|
|
| 176 | |
236 | |
| 177 | export CFLAGS="${NEW_CFLAGS}" |
237 | export CFLAGS="${NEW_CFLAGS}" |
| 178 | export CXXFLAGS="${NEW_CXXFLAGS}" |
238 | export CXXFLAGS="${NEW_CXXFLAGS}" |
|
|
239 | return 0 |
|
|
240 | } |
|
|
241 | |
|
|
242 | test_flag() { |
|
|
243 | local cc=${CC:-gcc} ; cc=${cc%% *} |
|
|
244 | if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then |
|
|
245 | printf "%s\n" "$*" |
|
|
246 | return 0 |
|
|
247 | fi |
|
|
248 | return 1 |
|
|
249 | } |
|
|
250 | |
|
|
251 | test_version_info() { |
|
|
252 | local cc=${CC:-gcc} ; cc=${cc%% *} |
|
|
253 | if [[ $(${cc} --version 2>&1) == *$1* ]]; then |
|
|
254 | return 0 |
|
|
255 | else |
|
|
256 | return 1 |
|
|
257 | fi |
|
|
258 | } |
|
|
259 | |
|
|
260 | strip-unsupported-flags() { |
|
|
261 | local NEW_CFLAGS NEW_CXXFLAGS |
|
|
262 | |
|
|
263 | for x in ${CFLAGS} ; do |
|
|
264 | NEW_CFLAGS="${NEW_CFLAGS} `test_flag ${x}`" |
|
|
265 | done |
|
|
266 | for x in ${CXXFLAGS} ; do |
|
|
267 | NEW_CXXFLAGS="${NEW_CXXFLAGS} `test_flag ${x}`" |
|
|
268 | done |
|
|
269 | |
|
|
270 | export CFLAGS="${NEW_CFLAGS}" |
|
|
271 | export CXXFLAGS="${NEW_CXXFLAGS}" |
| 179 | } |
272 | } |
| 180 | |
273 | |
| 181 | get-flag() { |
274 | get-flag() { |
| 182 | local findflag="$1" |
275 | local f findflag="$1" |
|
|
276 | |
|
|
277 | # this code looks a little flaky but seems to work for |
|
|
278 | # everything we want ... |
|
|
279 | # for example, if CFLAGS="-march=i686": |
|
|
280 | # `get-flag -march` == "-march=i686" |
|
|
281 | # `get-flag march` == "i686" |
| 183 | for f in ${CFLAGS} ${CXXFLAGS} ; do |
282 | for f in ${CFLAGS} ${CXXFLAGS} ; do |
| 184 | if [ "${f/${findflag}}" != "${f}" ] ; then |
283 | if [ "${f/${findflag}}" != "${f}" ] ; then |
| 185 | echo "${f/-${findflag}=}" |
284 | printf "%s\n" "${f/-${findflag}=}" |
| 186 | return 0 |
285 | return 0 |
| 187 | fi |
286 | fi |
| 188 | done |
287 | done |
| 189 | return 1 |
288 | return 1 |
| 190 | } |
289 | } |
| 191 | |
290 | |
|
|
291 | has_hardened() { |
|
|
292 | test_version_info Hardened |
|
|
293 | return $? |
|
|
294 | } |
|
|
295 | |
|
|
296 | has_pic() { |
|
|
297 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
|
|
298 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
|
|
299 | test_version_info pie && return 0 |
|
|
300 | return 1 |
|
|
301 | } |
|
|
302 | |
|
|
303 | has_pie() { |
|
|
304 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
|
|
305 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
|
|
306 | test_version_info pie && return 0 |
|
|
307 | return 1 |
|
|
308 | } |
|
|
309 | |
|
|
310 | has_ssp() { |
|
|
311 | [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 |
|
|
312 | test_version_info ssp && return 0 |
|
|
313 | return 1 |
|
|
314 | } |
|
|
315 | |
|
|
316 | has_m64() { |
|
|
317 | # this doesnt test if the flag is accepted, it tests if the flag |
|
|
318 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
|
|
319 | # please dont replace this function with test_flag in some future |
|
|
320 | # clean-up! |
|
|
321 | temp=`mktemp` |
|
|
322 | echo "int main() { return(0); }" > ${temp}.c |
|
|
323 | ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1 |
|
|
324 | ret=$? |
|
|
325 | rm -f ${temp}.c |
|
|
326 | [ "$ret" != "1" ] && return 0 |
|
|
327 | return 1 |
|
|
328 | } |
|
|
329 | |
|
|
330 | has_m32() { |
|
|
331 | # this doesnt test if the flag is accepted, it tests if the flag |
|
|
332 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
|
|
333 | # please dont replace this function with test_flag in some future |
|
|
334 | # clean-up! |
|
|
335 | temp=`mktemp` |
|
|
336 | echo "int main() { return(0); }" > ${temp}.c |
|
|
337 | ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 |
|
|
338 | ret=$? |
|
|
339 | rm -f ${temp}.c |
|
|
340 | [ "$ret" != "1" ] && return 0 |
|
|
341 | return 1 |
|
|
342 | } |
|
|
343 | |
| 192 | replace-sparc64-flags() { |
344 | replace-sparc64-flags() { |
| 193 | local SPARC64_CPUS="ultrasparc v9" |
345 | local SPARC64_CPUS="ultrasparc v9" |
| 194 | |
346 | |
| 195 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
347 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then |
| 196 | then |
|
|
| 197 | for x in ${SPARC64_CPUS} |
348 | for x in ${SPARC64_CPUS}; do |
| 198 | do |
|
|
| 199 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" |
349 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" |
| 200 | done |
350 | done |
| 201 | else |
351 | else |
| 202 | for x in ${SPARC64_CPUS} |
352 | for x in ${SPARC64_CPUS}; do |
| 203 | do |
|
|
| 204 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
353 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
| 205 | done |
354 | done |
| 206 | fi |
355 | fi |
| 207 | |
356 | |
| 208 | if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ] |
357 | if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then |
| 209 | then |
|
|
| 210 | for x in ${SPARC64_CPUS} |
358 | for x in ${SPARC64_CPUS}; do |
| 211 | do |
|
|
| 212 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" |
359 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" |
| 213 | done |
360 | done |
| 214 | else |
361 | else |
| 215 | for x in ${SPARC64_CPUS} |
362 | for x in ${SPARC64_CPUS}; do |
| 216 | do |
|
|
| 217 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
363 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
| 218 | done |
364 | done |
| 219 | fi |
365 | fi |
|
|
366 | |
|
|
367 | export CFLAGS CXXFLAGS |
| 220 | } |
368 | } |
| 221 | |
369 | |
| 222 | append-ldflags() { |
370 | append-ldflags() { |
|
|
371 | export LDFLAGS="${LDFLAGS} $*" |
|
|
372 | return 0 |
|
|
373 | } |
|
|
374 | |
|
|
375 | filter-ldflags() { |
|
|
376 | local x |
|
|
377 | |
|
|
378 | # we do this fancy spacing stuff so as to not filter |
|
|
379 | # out part of a flag ... we want flag atoms ! :D |
| 223 | LDFLAGS="${LDFLAGS} $@" |
380 | LDFLAGS=" ${LDFLAGS} " |
|
|
381 | for x in "$@" ; do |
|
|
382 | LDFLAGS="${LDFLAGS// ${x} / }" |
|
|
383 | done |
|
|
384 | LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" |
|
|
385 | export LDFLAGS |
| 224 | return 0 |
386 | return 0 |
| 225 | } |
387 | } |
| 226 | |
388 | |
| 227 | etexec-flags() { |
389 | etexec-flags() { |
| 228 | has_version 'sys-devel/hardened-gcc' && { |
390 | # if you're not using a hardened compiler you wont need this |
| 229 | debug-print ">>> appending flags -yet_exec" |
391 | # PIC/no-pic kludge in the first place. |
| 230 | append-flags -yet_exec |
392 | has_hardened || return 0 |
| 231 | append-ldflags -yet_exec |
393 | |
| 232 | } |
394 | if has_pie || has_pic; then |
|
|
395 | [ -z "`is-flag -fno-pic`" ] && |
|
|
396 | export CFLAGS="${CFLAGS} `test_flag -fno-pic`" |
|
|
397 | [ -z "`is-flag -nopie`" ] && |
|
|
398 | export CFLAGS="${CFLAGS} `test_flag -nopie`" |
|
|
399 | fi |
|
|
400 | return 0 |
| 233 | } |
401 | } |
| 234 | |
402 | |
| 235 | fstack-flags() { |
403 | fstack-flags() { |
| 236 | has_version 'sys-devel/hardened-gcc' && { |
404 | if has_ssp; then |
| 237 | debug-print ">>> appending flags -yno_propolice" |
405 | [ -z "`is-flag -fno-stack-protector`" ] && |
| 238 | append-flags -yno_propolice |
406 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
| 239 | append-ldflags -yno_propolice |
407 | fi |
| 240 | } |
408 | return 0 |
| 241 | } |
409 | } |