| 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.40 2004/03/12 11:21:15 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.69 2004/09/14 02:06:36 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 | |
|
|
10 | # Please leave ${IUSE} in this until portage .51 is stable, otherwise |
|
|
11 | # IUSE gets clobbered. |
|
|
12 | IUSE="${IUSE} debug" |
| 9 | |
13 | |
| 10 | # |
14 | # |
| 11 | #### filter-flags <flags> #### |
15 | #### filter-flags <flags> #### |
| 12 | # Remove particular flags from C[XX]FLAGS |
16 | # Remove particular flags from C[XX]FLAGS |
| 13 | # Matches only complete flags |
17 | # Matches only complete flags |
| … | |
… | |
| 47 | # will leave the user with -mfpmath=386 |
51 | # will leave the user with -mfpmath=386 |
| 48 | # |
52 | # |
| 49 | #### append-ldflags #### |
53 | #### append-ldflags #### |
| 50 | # Add extra flags to your current LDFLAGS |
54 | # Add extra flags to your current LDFLAGS |
| 51 | # |
55 | # |
|
|
56 | #### filter-ldflags <flags> #### |
|
|
57 | # Remove particular flags from LDFLAGS |
|
|
58 | # Matches only complete flags |
|
|
59 | # |
| 52 | #### etexec-flags #### |
60 | #### etexec-flags #### |
| 53 | # hooked function for hardened-gcc that appends |
61 | # hooked function for hardened gcc that appends |
| 54 | # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed |
62 | # -fno-pic to {C,CXX,LD}FLAGS |
| 55 | # and a package is filtering -fPIC,-fpic, -fPIE, -fpie |
63 | # when a package is filtering -fpic, -fPIC, -fpie, -fPIE |
| 56 | # |
64 | # |
| 57 | #### fstack-flags #### |
65 | #### fstack-flags #### |
| 58 | # hooked function for hardened-gcc that appends |
66 | # hooked function for hardened gcc that appends |
| 59 | # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed |
67 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
| 60 | # and a package is filtering -fstack-protector, -fstack-protector-all |
68 | # when a package is filtering -fstack-protector, -fstack-protector-all |
|
|
69 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
|
|
70 | # when only -fno-stack-protector is given |
| 61 | # |
71 | # |
| 62 | |
72 | |
| 63 | # C[XX]FLAGS that we allow in strip-flags |
73 | # C[XX]FLAGS that we allow in strip-flags |
| 64 | setup-allowed-flags() { |
74 | setup-allowed-flags() { |
|
|
75 | if [ -z "${ALLOWED_FLAGS}" ] ; then |
| 65 | export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
76 | export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-stack-protector -fno-pie -fno-unit-at-a-time -pipe -g" |
|
|
77 | case "${ARCH}" in |
|
|
78 | mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; |
|
|
79 | amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; |
|
|
80 | x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; |
|
|
81 | alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
82 | ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
83 | esac |
|
|
84 | fi |
|
|
85 | # allow a bunch of flags that negate features / control ABI |
|
|
86 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" |
| 66 | case "${ARCH}" in |
87 | case "${ARCH}" in |
| 67 | mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; |
88 | x86|amd64|ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" ;; |
| 68 | amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
| 69 | alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
| 70 | ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
| 71 | esac |
89 | esac |
|
|
90 | ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs -msoft-float -mflat -mno-faster-structs -mfaster-structs -mlittle-endian -mbig-endian -mlive-g0 -mcmodel -mno-stack-bias -mstack-bias" |
| 72 | |
91 | |
| 73 | # C[XX]FLAGS that we are think is ok, but needs testing |
92 | # C[XX]FLAGS that we are think is ok, but needs testing |
| 74 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
93 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
| 75 | export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
94 | export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
| 76 | return 0 |
95 | return 0 |
| 77 | } |
96 | } |
| 78 | |
97 | |
| 79 | filter-flags() { |
98 | filter-flags() { |
|
|
99 | local x f fset |
|
|
100 | declare -a new_CFLAGS new_CXXFLAGS |
|
|
101 | |
| 80 | for x in "$@" ; do |
102 | for x in "$@" ; do |
| 81 | case "${x}" in |
103 | case "${x}" in |
| 82 | -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; |
104 | -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; |
| 83 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
105 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
| 84 | *) ;; |
|
|
| 85 | esac |
106 | esac |
| 86 | done |
107 | done |
| 87 | |
108 | |
| 88 | # we do this fancy spacing stuff so as to not filter |
109 | for fset in CFLAGS CXXFLAGS; do |
| 89 | # out part of a flag ... we want flag atoms ! :D |
110 | # Looping over the flags instead of using a global |
| 90 | CFLAGS=" ${CFLAGS} " |
111 | # substitution ensures that we're working with flag atoms. |
| 91 | CXXFLAGS=" ${CXXFLAGS} " |
112 | # Otherwise globs like -O* have the potential to wipe out the |
|
|
113 | # list of flags. |
|
|
114 | for f in ${!fset}; do |
| 92 | for x in "$@" ; do |
115 | for x in "$@"; do |
| 93 | CFLAGS="${CFLAGS// ${x} / }" |
116 | # Note this should work with globs like -O* |
| 94 | CXXFLAGS="${CXXFLAGS// ${x} / }" |
117 | [[ ${f} == ${x} ]] && continue 2 |
|
|
118 | done |
|
|
119 | eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f} |
| 95 | done |
120 | done |
| 96 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
121 | eval export ${fset}=\${new_${fset}\[*]} |
| 97 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
122 | done |
|
|
123 | |
| 98 | return 0 |
124 | return 0 |
| 99 | } |
125 | } |
| 100 | |
126 | |
| 101 | filter-lfs-flags() { |
127 | filter-lfs-flags() { |
| 102 | filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
128 | filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
| 103 | } |
129 | } |
| 104 | |
130 | |
|
|
131 | append-lfs-flags() { |
|
|
132 | append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
|
|
133 | } |
|
|
134 | |
| 105 | append-flags() { |
135 | append-flags() { |
| 106 | export CFLAGS="${CFLAGS} $@" |
136 | export CFLAGS="${CFLAGS} $*" |
| 107 | export CXXFLAGS="${CXXFLAGS} $@" |
137 | export CXXFLAGS="${CXXFLAGS} $*" |
| 108 | [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags |
138 | [ -n "`is-flag -fno-stack-protector`" -o \ |
|
|
139 | -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags |
| 109 | return 0 |
140 | return 0 |
| 110 | } |
141 | } |
| 111 | |
142 | |
| 112 | replace-flags() { |
143 | replace-flags() { |
| 113 | # we do this fancy spacing stuff so as to not filter |
144 | local f fset |
| 114 | # out part of a flag ... we want flag atoms ! :D |
145 | declare -a new_CFLAGS new_CXXFLAGS |
| 115 | CFLAGS=" ${CFLAGS} " |
146 | |
| 116 | CXXFLAGS=" ${CXXFLAGS} " |
147 | for fset in CFLAGS CXXFLAGS; do |
| 117 | CFLAGS="${CFLAGS// ${1} / ${2} }" |
148 | # Looping over the flags instead of using a global |
| 118 | CXXFLAGS="${CXXFLAGS// ${1} / ${2} }" |
149 | # substitution ensures that we're working with flag atoms. |
| 119 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
150 | # Otherwise globs like -O* have the potential to wipe out the |
| 120 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
151 | # list of flags. |
|
|
152 | for f in ${!fset}; do |
|
|
153 | # Note this should work with globs like -O* |
|
|
154 | [[ ${f} == ${1} ]] && f=${2} |
|
|
155 | eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f} |
|
|
156 | done |
|
|
157 | eval export ${fset}=\${new_${fset}\[*]} |
|
|
158 | done |
|
|
159 | |
| 121 | return 0 |
160 | return 0 |
| 122 | } |
161 | } |
| 123 | |
162 | |
| 124 | replace-cpu-flags() { |
163 | replace-cpu-flags() { |
| 125 | local newcpu="$1" ; shift |
164 | local oldcpu newcpu="$1" ; shift |
| 126 | local oldcpu="" |
|
|
| 127 | for oldcpu in "$@" ; do |
165 | for oldcpu in "$@" ; do |
|
|
166 | # quote to make sure that no globbing is done (particularly on |
|
|
167 | # ${oldcpu} prior to calling replace-flags |
| 128 | replace-flags -march=${oldcpu} -march=${newcpu} |
168 | replace-flags "-march=${oldcpu}" "-march=${newcpu}" |
| 129 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
169 | replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}" |
| 130 | replace-flags -mtune=${oldcpu} -mtune=${newcpu} |
170 | replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}" |
| 131 | done |
171 | done |
| 132 | return 0 |
172 | return 0 |
| 133 | } |
173 | } |
| 134 | |
174 | |
| 135 | is-flag() { |
175 | is-flag() { |
|
|
176 | local x |
|
|
177 | |
| 136 | for x in ${CFLAGS} ${CXXFLAGS} ; do |
178 | for x in ${CFLAGS} ${CXXFLAGS} ; do |
|
|
179 | # Note this should work with globs like -mcpu=ultrasparc* |
| 137 | if [ "${x}" == "$1" ] ; then |
180 | if [[ ${x} == ${1} ]]; then |
| 138 | echo true |
181 | echo true |
| 139 | return 0 |
182 | return 0 |
| 140 | fi |
183 | fi |
| 141 | done |
184 | done |
| 142 | return 1 |
185 | return 1 |
| 143 | } |
186 | } |
| 144 | |
187 | |
| 145 | filter-mfpmath() { |
188 | filter-mfpmath() { |
|
|
189 | local orig_mfpmath new_math prune_math |
|
|
190 | |
| 146 | # save the original -mfpmath flag |
191 | # save the original -mfpmath flag |
| 147 | local orig_mfpmath="`get-flag -mfpmath`" |
192 | orig_mfpmath="`get-flag -mfpmath`" |
| 148 | # get the value of the current -mfpmath flag |
193 | # get the value of the current -mfpmath flag |
| 149 | local new_math=" `get-flag mfpmath | tr , ' '` " |
194 | new_math=" `get-flag mfpmath | tr , ' '` " |
| 150 | # figure out which math values are to be removed |
195 | # figure out which math values are to be removed |
| 151 | local prune_math="" |
196 | prune_math="" |
| 152 | for prune_math in "$@" ; do |
197 | for prune_math in "$@" ; do |
| 153 | new_math="${new_math/ ${prune_math} / }" |
198 | new_math="${new_math/ ${prune_math} / }" |
| 154 | done |
199 | done |
| 155 | new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" |
200 | new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" |
| 156 | |
201 | |
| … | |
… | |
| 165 | fi |
210 | fi |
| 166 | return 0 |
211 | return 0 |
| 167 | } |
212 | } |
| 168 | |
213 | |
| 169 | strip-flags() { |
214 | strip-flags() { |
|
|
215 | local x y flag NEW_CFLAGS NEW_CXXFLAGS |
|
|
216 | |
| 170 | setup-allowed-flags |
217 | setup-allowed-flags |
| 171 | |
218 | |
| 172 | local NEW_CFLAGS="" |
219 | local NEW_CFLAGS="" |
| 173 | local NEW_CXXFLAGS="" |
220 | local NEW_CXXFLAGS="" |
| 174 | |
221 | |
| 175 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
222 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
| 176 | if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then |
223 | if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then |
| 177 | [ `use debug` ] && einfo "Enabling the use of some unstable flags" |
224 | use debug && einfo "Enabling the use of some unstable flags" |
| 178 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
225 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
| 179 | fi |
226 | fi |
| 180 | |
227 | |
| 181 | set -f |
228 | set -f # disable pathname expansion |
| 182 | |
229 | |
| 183 | for x in ${CFLAGS} |
230 | for x in ${CFLAGS}; do |
| 184 | do |
|
|
| 185 | for y in ${ALLOWED_FLAGS} |
231 | for y in ${ALLOWED_FLAGS}; do |
| 186 | do |
|
|
| 187 | flag=${x%%=*} |
232 | flag=${x%%=*} |
| 188 | if [ "${flag%%${y}}" = "" ] |
233 | if [ "${flag%%${y}}" = "" ] ; then |
| 189 | then |
|
|
| 190 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
234 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
| 191 | break |
235 | break |
| 192 | fi |
236 | fi |
| 193 | done |
237 | done |
| 194 | done |
238 | done |
| 195 | |
239 | |
| 196 | for x in ${CXXFLAGS} |
240 | for x in ${CXXFLAGS}; do |
| 197 | do |
|
|
| 198 | for y in ${ALLOWED_FLAGS} |
241 | for y in ${ALLOWED_FLAGS}; do |
| 199 | do |
|
|
| 200 | flag=${x%%=*} |
242 | flag=${x%%=*} |
| 201 | if [ "${flag%%${y}}" = "" ] |
243 | if [ "${flag%%${y}}" = "" ] ; then |
| 202 | then |
|
|
| 203 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
244 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
| 204 | break |
245 | break |
| 205 | fi |
246 | fi |
| 206 | done |
247 | done |
| 207 | done |
248 | done |
| … | |
… | |
| 212 | fi |
253 | fi |
| 213 | if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then |
254 | if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then |
| 214 | NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" |
255 | NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" |
| 215 | fi |
256 | fi |
| 216 | |
257 | |
| 217 | set +f |
258 | set +f # re-enable pathname expansion |
| 218 | |
|
|
| 219 | [ `use debug` ] \ |
|
|
| 220 | && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ |
|
|
| 221 | && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" |
|
|
| 222 | |
259 | |
| 223 | export CFLAGS="${NEW_CFLAGS}" |
260 | export CFLAGS="${NEW_CFLAGS}" |
| 224 | export CXXFLAGS="${NEW_CXXFLAGS}" |
261 | export CXXFLAGS="${NEW_CXXFLAGS}" |
| 225 | return 0 |
262 | return 0 |
| 226 | } |
263 | } |
| 227 | |
264 | |
| 228 | test_flag() { |
265 | test_flag() { |
|
|
266 | local cc=${CC:-gcc} ; cc=${cc%% *} |
| 229 | if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then |
267 | if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then |
| 230 | echo "$@" |
268 | printf "%s\n" "$*" |
| 231 | return 0 |
269 | return 0 |
| 232 | fi |
270 | fi |
| 233 | return 1 |
271 | return 1 |
| 234 | } |
272 | } |
| 235 | |
273 | |
|
|
274 | test_version_info() { |
|
|
275 | local cc=${CC:-gcc} ; cc=${cc%% *} |
|
|
276 | if [[ $(${cc} --version 2>&1) == *$1* ]]; then |
|
|
277 | return 0 |
|
|
278 | else |
|
|
279 | return 1 |
|
|
280 | fi |
|
|
281 | } |
|
|
282 | |
| 236 | strip-unsupported-flags() { |
283 | strip-unsupported-flags() { |
|
|
284 | local NEW_CFLAGS NEW_CXXFLAGS |
|
|
285 | |
| 237 | for x in ${CFLAGS} ; do |
286 | for x in ${CFLAGS} ; do |
| 238 | NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`" |
287 | NEW_CFLAGS="${NEW_CFLAGS} `test_flag ${x}`" |
| 239 | done |
288 | done |
| 240 | for x in ${CXXFLAGS} ; do |
289 | for x in ${CXXFLAGS} ; do |
| 241 | NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`" |
290 | NEW_CXXFLAGS="${NEW_CXXFLAGS} `test_flag ${x}`" |
| 242 | done |
291 | done |
| 243 | |
292 | |
| 244 | export CFLAGS="${NEW_CFLAGS}" |
293 | export CFLAGS="${NEW_CFLAGS}" |
| 245 | export CXXFLAGS="${NEW_CXXFLAGS}" |
294 | export CXXFLAGS="${NEW_CXXFLAGS}" |
| 246 | } |
295 | } |
| 247 | |
296 | |
| 248 | get-flag() { |
297 | get-flag() { |
|
|
298 | local f findflag="$1" |
|
|
299 | |
| 249 | # this code looks a little flaky but seems to work for |
300 | # this code looks a little flaky but seems to work for |
| 250 | # everything we want ... |
301 | # everything we want ... |
| 251 | # for example, if CFLAGS="-march=i686": |
302 | # for example, if CFLAGS="-march=i686": |
| 252 | # `get-flags -march` == "-march=i686" |
303 | # `get-flag -march` == "-march=i686" |
| 253 | # `get-flags march` == "i686" |
304 | # `get-flag march` == "i686" |
| 254 | local findflag="$1" |
|
|
| 255 | for f in ${CFLAGS} ${CXXFLAGS} ; do |
305 | for f in ${CFLAGS} ${CXXFLAGS} ; do |
| 256 | if [ "${f/${findflag}}" != "${f}" ] ; then |
306 | if [ "${f/${findflag}}" != "${f}" ] ; then |
| 257 | echo "${f/-${findflag}=}" |
307 | printf "%s\n" "${f/-${findflag}=}" |
| 258 | return 0 |
308 | return 0 |
| 259 | fi |
309 | fi |
| 260 | done |
310 | done |
| 261 | return 1 |
311 | return 1 |
| 262 | } |
312 | } |
| 263 | |
313 | |
|
|
314 | has_hardened() { |
|
|
315 | test_version_info Hardened && return 0 |
|
|
316 | # the specs file wont exist unless gcc has GCC_SPECS support |
|
|
317 | [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ |
|
|
318 | return 0 |
|
|
319 | return 1 |
|
|
320 | } |
|
|
321 | |
|
|
322 | has_pic() { |
|
|
323 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
|
|
324 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
|
|
325 | test_version_info pie && return 0 |
|
|
326 | return 1 |
|
|
327 | } |
|
|
328 | |
|
|
329 | has_pie() { |
|
|
330 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
|
|
331 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
|
|
332 | test_version_info pie && return 0 |
|
|
333 | return 1 |
|
|
334 | } |
|
|
335 | |
|
|
336 | has_ssp() { |
|
|
337 | [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 |
|
|
338 | test_version_info ssp && return 0 |
|
|
339 | return 1 |
|
|
340 | } |
|
|
341 | |
|
|
342 | has_m64() { |
|
|
343 | # this doesnt test if the flag is accepted, it tests if the flag |
|
|
344 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
|
|
345 | # please dont replace this function with test_flag in some future |
|
|
346 | # clean-up! |
|
|
347 | temp=`mktemp` |
|
|
348 | echo "int main() { return(0); }" > ${temp}.c |
|
|
349 | ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1 |
|
|
350 | ret=$? |
|
|
351 | rm -f ${temp}.c |
|
|
352 | [ "$ret" != "1" ] && return 0 |
|
|
353 | return 1 |
|
|
354 | } |
|
|
355 | |
|
|
356 | has_m32() { |
|
|
357 | # this doesnt test if the flag is accepted, it tests if the flag |
|
|
358 | # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! |
|
|
359 | # please dont replace this function with test_flag in some future |
|
|
360 | # clean-up! |
|
|
361 | temp=`mktemp` |
|
|
362 | echo "int main() { return(0); }" > ${temp}.c |
|
|
363 | ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 |
|
|
364 | ret=$? |
|
|
365 | rm -f ${temp}.c |
|
|
366 | [ "$ret" != "1" ] && return 0 |
|
|
367 | return 1 |
|
|
368 | } |
|
|
369 | |
| 264 | replace-sparc64-flags() { |
370 | replace-sparc64-flags() { |
| 265 | local SPARC64_CPUS="ultrasparc v9" |
371 | local SPARC64_CPUS="ultrasparc v9" |
| 266 | |
372 | |
| 267 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
373 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then |
| 268 | then |
|
|
| 269 | for x in ${SPARC64_CPUS} |
374 | for x in ${SPARC64_CPUS}; do |
| 270 | do |
|
|
| 271 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" |
375 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" |
| 272 | done |
376 | done |
| 273 | else |
377 | else |
| 274 | for x in ${SPARC64_CPUS} |
378 | for x in ${SPARC64_CPUS}; do |
| 275 | do |
|
|
| 276 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
379 | CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
| 277 | done |
380 | done |
| 278 | fi |
381 | fi |
| 279 | |
382 | |
| 280 | if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ] |
383 | if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then |
| 281 | then |
|
|
| 282 | for x in ${SPARC64_CPUS} |
384 | for x in ${SPARC64_CPUS}; do |
| 283 | do |
|
|
| 284 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" |
385 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" |
| 285 | done |
386 | done |
| 286 | else |
387 | else |
| 287 | for x in ${SPARC64_CPUS} |
388 | for x in ${SPARC64_CPUS}; do |
| 288 | do |
|
|
| 289 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
389 | CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" |
| 290 | done |
390 | done |
| 291 | fi |
391 | fi |
|
|
392 | |
|
|
393 | export CFLAGS CXXFLAGS |
| 292 | } |
394 | } |
| 293 | |
395 | |
| 294 | append-ldflags() { |
396 | append-ldflags() { |
|
|
397 | export LDFLAGS="${LDFLAGS} $*" |
|
|
398 | return 0 |
|
|
399 | } |
|
|
400 | |
|
|
401 | filter-ldflags() { |
|
|
402 | local x |
|
|
403 | |
|
|
404 | # we do this fancy spacing stuff so as to not filter |
|
|
405 | # out part of a flag ... we want flag atoms ! :D |
| 295 | LDFLAGS="${LDFLAGS} $@" |
406 | LDFLAGS=" ${LDFLAGS} " |
|
|
407 | for x in "$@" ; do |
|
|
408 | LDFLAGS="${LDFLAGS// ${x} / }" |
|
|
409 | done |
|
|
410 | LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" |
|
|
411 | export LDFLAGS |
| 296 | return 0 |
412 | return 0 |
| 297 | } |
413 | } |
| 298 | |
414 | |
| 299 | etexec-flags() { |
415 | etexec-flags() { |
| 300 | has_version sys-devel/hardened-gcc |
416 | # if you're not using a hardened compiler you wont need this |
| 301 | if [ $? == 0 ] ; then |
417 | # PIC/no-pic kludge in the first place. |
| 302 | if [ "`is-flag -yet_exec`" != "true" ]; then |
418 | has_hardened || return 0 |
| 303 | debug-print ">>> appending flags -yet_exec" |
419 | # this kludge breaks on amd64, and probably other -fPIC dependant |
| 304 | append-flags -yet_exec |
420 | # archs. |
| 305 | append-ldflags -yet_exec |
421 | use amd64 && return 0 |
|
|
422 | |
|
|
423 | if has_pie || has_pic; then |
|
|
424 | [ -z "`is-flag -fno-pic`" ] && |
|
|
425 | export CFLAGS="${CFLAGS} `test_flag -fno-pic`" |
|
|
426 | [ -z "`is-flag -nopie`" ] && |
|
|
427 | export CFLAGS="${CFLAGS} `test_flag -nopie`" |
| 306 | fi |
428 | fi |
| 307 | fi |
429 | return 0 |
| 308 | } |
430 | } |
| 309 | |
431 | |
| 310 | fstack-flags() { |
432 | fstack-flags() { |
| 311 | has_version sys-devel/hardened-gcc |
433 | if has_ssp; then |
| 312 | if [ $? == 0 ] ; then |
434 | [ -z "`is-flag -fno-stack-protector`" ] && |
| 313 | if [ "`is-flag -yno_propolice`" != "true" ]; then |
435 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
| 314 | debug-print ">>> appending flags -yno_propolice" |
|
|
| 315 | append-flags -yno_propolice |
|
|
| 316 | append-ldflags -yno_propolice |
|
|
| 317 | fi |
436 | fi |
| 318 | fi |
437 | return 0 |
| 319 | } |
438 | } |