/[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.57 Revision 1.58
1# Copyright 1999-2003 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.57 2004/06/10 00:41:44 lv Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.58 2004/06/10 15:28:56 agriffis Exp $
4# 4#
5# Author Bart Verwilst <verwilst@gentoo.org> 5# Author Bart Verwilst <verwilst@gentoo.org>
6 6
7ECLASS=flag-o-matic 7ECLASS=flag-o-matic
8INHERITED="$INHERITED $ECLASS" 8INHERITED="$INHERITED $ECLASS"
85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
86 return 0 86 return 0
87} 87}
88 88
89filter-flags() { 89filter-flags() {
90 local x
91
90 for x in "$@" ; do 92 for x in "$@" ; do
91 case "${x}" in 93 case "${x}" in
92 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 94 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
93 -fstack-protector|-fstack-protector-all) fstack-flags;; 95 -fstack-protector|-fstack-protector-all) fstack-flags;;
94 *) ;; 96 *) ;;
115append-lfs-flags() { 117append-lfs-flags() {
116 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 118 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
117} 119}
118 120
119append-flags() { 121append-flags() {
120 export CFLAGS="${CFLAGS} $@" 122 export CFLAGS="${CFLAGS} $*"
121 export CXXFLAGS="${CXXFLAGS} $@" 123 export CXXFLAGS="${CXXFLAGS} $*"
122 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags 124 [ -n "`is-flag -fno-stack-protector`" -o \
125 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
123 return 0 126 return 0
124} 127}
125 128
126replace-flags() { 129replace-flags() {
127 # we do this fancy spacing stuff so as to not filter 130 # we do this fancy spacing stuff so as to not filter
134 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 137 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
135 return 0 138 return 0
136} 139}
137 140
138replace-cpu-flags() { 141replace-cpu-flags() {
139 local newcpu="$1" ; shift 142 local oldcpu newcpu="$1" ; shift
140 local oldcpu=""
141 for oldcpu in "$@" ; do 143 for oldcpu in "$@" ; do
142 replace-flags -march=${oldcpu} -march=${newcpu} 144 replace-flags -march=${oldcpu} -march=${newcpu}
143 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} 145 replace-flags -mcpu=${oldcpu} -mcpu=${newcpu}
144 replace-flags -mtune=${oldcpu} -mtune=${newcpu} 146 replace-flags -mtune=${oldcpu} -mtune=${newcpu}
145 done 147 done
146 return 0 148 return 0
147} 149}
148 150
149is-flag() { 151is-flag() {
152 local x
153
150 for x in ${CFLAGS} ${CXXFLAGS} ; do 154 for x in ${CFLAGS} ${CXXFLAGS} ; do
151 if [ "${x}" == "$1" ] ; then 155 if [ "${x}" == "$1" ] ; then
152 echo true 156 echo true
153 return 0 157 return 0
154 fi 158 fi
155 done 159 done
156 return 1 160 return 1
157} 161}
158 162
159filter-mfpmath() { 163filter-mfpmath() {
164 local orig_mfpmath new_math prune_math
165
160 # save the original -mfpmath flag 166 # save the original -mfpmath flag
161 local orig_mfpmath="`get-flag -mfpmath`" 167 orig_mfpmath="`get-flag -mfpmath`"
162 # get the value of the current -mfpmath flag 168 # get the value of the current -mfpmath flag
163 local new_math=" `get-flag mfpmath | tr , ' '` " 169 new_math=" `get-flag mfpmath | tr , ' '` "
164 # figure out which math values are to be removed 170 # figure out which math values are to be removed
165 local prune_math="" 171 prune_math=""
166 for prune_math in "$@" ; do 172 for prune_math in "$@" ; do
167 new_math="${new_math/ ${prune_math} / }" 173 new_math="${new_math/ ${prune_math} / }"
168 done 174 done
169 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`" 175 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`"
170 176
179 fi 185 fi
180 return 0 186 return 0
181} 187}
182 188
183strip-flags() { 189strip-flags() {
190 local x y flag NEW_CFLAGS NEW_CXXFLAGS
191
184 setup-allowed-flags 192 setup-allowed-flags
185 193
186 local NEW_CFLAGS="" 194 local NEW_CFLAGS=""
187 local NEW_CXXFLAGS="" 195 local NEW_CXXFLAGS=""
188 196
190 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then 198 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then
191 use debug && einfo "Enabling the use of some unstable flags" 199 use debug && einfo "Enabling the use of some unstable flags"
192 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 200 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
193 fi 201 fi
194 202
195 set -f 203 set -f # disable pathname expansion
196 204
197 for x in ${CFLAGS} 205 for x in ${CFLAGS}; do
198 do
199 for y in ${ALLOWED_FLAGS} 206 for y in ${ALLOWED_FLAGS}; do
200 do
201 flag=${x%%=*} 207 flag=${x%%=*}
202 if [ "${flag%%${y}}" = "" ] 208 if [ "${flag%%${y}}" = "" ]; then
203 then
204 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 209 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
205 break 210 break
206 fi 211 fi
207 done 212 done
208 done 213 done
209 214
210 for x in ${CXXFLAGS} 215 for x in ${CXXFLAGS}; do
211 do
212 for y in ${ALLOWED_FLAGS} 216 for y in ${ALLOWED_FLAGS}; do
213 do
214 flag=${x%%=*} 217 flag=${x%%=*}
215 if [ "${flag%%${y}}" = "" ] 218 if [ "${flag%%${y}}" = "" ]; then
216 then
217 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 219 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
218 break 220 break
219 fi 221 fi
220 done 222 done
221 done 223 done
226 fi 228 fi
227 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then 229 if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
228 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 230 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
229 fi 231 fi
230 232
231 set +f 233 set +f # re-enable pathname expansion
232 234
233 use debug \ 235 useq debug \
234 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ 236 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
235 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" 237 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
236 238
237 export CFLAGS="${NEW_CFLAGS}" 239 export CFLAGS="${NEW_CFLAGS}"
238 export CXXFLAGS="${NEW_CXXFLAGS}" 240 export CXXFLAGS="${NEW_CXXFLAGS}"
239 return 0 241 return 0
240} 242}
241 243
242test_flag() { 244test_flag() {
245 local cc=${CC:-gcc} ; cc=${cc%% *}
243 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then 246 if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then
244 echo "$@" 247 printf "%s\n" "$*"
245 return 0 248 return 0
246 fi 249 fi
247 return 1 250 return 1
248} 251}
249 252
253test_version_info() {
254 local cc=${CC:-gcc} ; cc=${cc%% *}
255 if [[ $(${cc} --version 2>&1) == *$1* ]]; then
256 return 0
257 else
258 return 1
259 fi
260}
261
250strip-unsupported-flags() { 262strip-unsupported-flags() {
263 local NEW_CFLAGS NEW_CXXFLAGS
264
251 for x in ${CFLAGS} ; do 265 for x in ${CFLAGS} ; do
252 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`" 266 NEW_CFLAGS="${NEW_CFLAGS} `test_flag ${x}`"
253 done 267 done
254 for x in ${CXXFLAGS} ; do 268 for x in ${CXXFLAGS} ; do
255 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`" 269 NEW_CXXFLAGS="${NEW_CXXFLAGS} `test_flag ${x}`"
256 done 270 done
257 271
258 export CFLAGS="${NEW_CFLAGS}" 272 export CFLAGS="${NEW_CFLAGS}"
259 export CXXFLAGS="${NEW_CXXFLAGS}" 273 export CXXFLAGS="${NEW_CXXFLAGS}"
260} 274}
261 275
262get-flag() { 276get-flag() {
277 local f findflag="$1"
278
263 # this code looks a little flaky but seems to work for 279 # this code looks a little flaky but seems to work for
264 # everything we want ... 280 # everything we want ...
265 # for example, if CFLAGS="-march=i686": 281 # for example, if CFLAGS="-march=i686":
266 # `get-flags -march` == "-march=i686" 282 # `get-flag -march` == "-march=i686"
267 # `get-flags march` == "i686" 283 # `get-flag march` == "i686"
268 local findflag="$1"
269 for f in ${CFLAGS} ${CXXFLAGS} ; do 284 for f in ${CFLAGS} ${CXXFLAGS} ; do
270 if [ "${f/${findflag}}" != "${f}" ] ; then 285 if [ "${f/${findflag}}" != "${f}" ] ; then
271 echo "${f/-${findflag}=}" 286 printf "%s\n" "${f/-${findflag}=}"
272 return 0 287 return 0
273 fi 288 fi
274 done 289 done
275 return 1 290 return 1
276} 291}
277 292
278has_hardened() { 293has_hardened() {
279 local cc=${CC:-gcc} 294 test_version_info Hardened
280 [[ $(${cc%% *} --version 2>&1) == *Hardened* ]]
281 return $? 295 return $?
282} 296}
283 297
284has_pic() { 298has_pic() {
285 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 299 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
286 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 300 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
287 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 301 test_version_info pie && return 0
288 return 1 302 return 1
289} 303}
290 304
291has_pie() { 305has_pie() {
292 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 306 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
293 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 307 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
294 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 308 test_version_info pie && return 0
295 return 1 309 return 1
296} 310}
297 311
298has_ssp() { 312has_ssp() {
299 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 313 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
300 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0 314 test_version_info ssp && return 0
301 return 1 315 return 1
302} 316}
303 317
304has_m64() { 318has_m64() {
305 temp=`mktemp` 319 test_flag -m64
306 echo "int main() { return(0); }" > ${temp}.c
307 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1
308 ret=$?
309 rm -f ${temp}.c
310 [ "$ret" != "1" ] && return 0
311 return 1 320 return $?
312} 321}
313 322
314has_m32() { 323has_m32() {
315 temp=`mktemp` 324 test_flag -m32
316 echo "int main() { return(0); }" > ${temp}.c
317 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1
318 ret=$?
319 rm -f ${temp}.c
320 [ "$ret" != "1" ] && return 0
321 return 1 325 return $?
322} 326}
323 327
324replace-sparc64-flags() { 328replace-sparc64-flags() {
325 local SPARC64_CPUS="ultrasparc v9" 329 local SPARC64_CPUS="ultrasparc v9"
326 330
327 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] 331 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
328 then
329 for x in ${SPARC64_CPUS} 332 for x in ${SPARC64_CPUS}; do
330 do
331 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 333 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
332 done 334 done
333 else 335 else
334 for x in ${SPARC64_CPUS} 336 for x in ${SPARC64_CPUS}; do
335 do
336 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 337 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
337 done 338 done
338 fi 339 fi
339 340
340 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ] 341 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
341 then
342 for x in ${SPARC64_CPUS} 342 for x in ${SPARC64_CPUS}; do
343 do
344 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 343 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
345 done 344 done
346 else 345 else
347 for x in ${SPARC64_CPUS} 346 for x in ${SPARC64_CPUS}; do
348 do
349 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 347 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
350 done 348 done
351 fi 349 fi
352} 350}
353 351
354append-ldflags() { 352append-ldflags() {
355 LDFLAGS="${LDFLAGS} $@" 353 LDFLAGS="${LDFLAGS} $*"
356 return 0 354 return 0
357} 355}
358 356
359filter-ldflags() { 357filter-ldflags() {
358 local x
359
360 # we do this fancy spacing stuff so as to not filter 360 # we do this fancy spacing stuff so as to not filter
361 # out part of a flag ... we want flag atoms ! :D 361 # out part of a flag ... we want flag atoms ! :D
362 LDFLAGS=" ${LDFLAGS} " 362 LDFLAGS=" ${LDFLAGS} "
363 for x in "$@" ; do 363 for x in "$@" ; do
364 LDFLAGS="${LDFLAGS// ${x} / }" 364 LDFLAGS="${LDFLAGS// ${x} / }"
366 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 366 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
367 return 0 367 return 0
368} 368}
369 369
370etexec-flags() { 370etexec-flags() {
371 # if your not using a hardened compiler you wont need this 371 # if you're not using a hardened compiler you wont need this
372 # PIC/no-pic kludge in the first place. 372 # PIC/no-pic kludge in the first place.
373 has_hardened || return 373 has_hardened || return 0
374 374
375 has_pie || has_pic 375 if has_pie || has_pic; then
376 if [ $? == 0 ] ; then
377 [ -z "`is-flag -fno-pic`" ] && 376 [ -z "`is-flag -fno-pic`" ] &&
378 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 377 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
379
380 [ -z "`is-flag -nopie`" ] && 378 [ -z "`is-flag -nopie`" ] &&
381 export CFLAGS="${CFLAGS} `test_flag -nopie`" 379 export CFLAGS="${CFLAGS} `test_flag -nopie`"
382 fi 380 fi
381 return 0
383} 382}
384 383
385fstack-flags() { 384fstack-flags() {
386 has_ssp 385 if has_ssp; then
387 if [ $? == 0 ] ; then
388 [ -z "`is-flag -fno-stack-protector`" ] && 386 [ -z "`is-flag -fno-stack-protector`" ] &&
389 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 387 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
390 fi 388 fi
389 return 0
391} 390}
392

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

  ViewVC Help
Powered by ViewVC 1.1.20