/[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.67 Revision 1.77
1# Copyright 1999-2004 Gentoo Foundation 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.67 2004/08/07 04:24:41 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.77 2004/11/13 07:07:08 solar 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"
9 9
10# Please leave ${IUSE} in this until portage .51 is stable, otherwise
11# IUSE gets clobbered.
12IUSE="${IUSE} debug" 10IUSE="debug"
11
12# need access to emktemp()
13inherit eutils toolchain-funcs
13 14
14# 15#
15#### filter-flags <flags> #### 16#### filter-flags <flags> ####
16# Remove particular flags from C[XX]FLAGS 17# Remove particular flags from C[XX]FLAGS
17# Matches only complete flags 18# Matches only complete flags
20# Add extra flags to your current C[XX]FLAGS 21# Add extra flags to your current C[XX]FLAGS
21# 22#
22#### replace-flags <orig.flag> <new.flag> ### 23#### replace-flags <orig.flag> <new.flag> ###
23# Replace a flag by another one 24# Replace a flag by another one
24# 25#
25#### replace-cpu-flags <new.cpu> <old.cpus> ### 26#### replace-cpu-flags <old.cpus> <new.cpu> ###
26# Replace march/mcpu flags that specify <old.cpus> 27# Replace march/mcpu flags that specify <old.cpus>
27# with flags that specify <new.cpu> 28# with flags that specify <new.cpu>
28# 29#
29#### is-flag <flag> #### 30#### is-flag <flag> ####
30# Returns "true" if flag is set in C[XX]FLAGS 31# Returns "true" if flag is set in C[XX]FLAGS
71# 72#
72 73
73# C[XX]FLAGS that we allow in strip-flags 74# C[XX]FLAGS that we allow in strip-flags
74setup-allowed-flags() { 75setup-allowed-flags() {
75 if [ -z "${ALLOWED_FLAGS}" ] ; then 76 if [ -z "${ALLOWED_FLAGS}" ] ; then
76 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-unit-at-a-time -pipe -g" 77 export ALLOWED_FLAGS="-pipe"
78 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
79 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fno-stack-protector"
80 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-pie -fno-unit-at-a-time"
81 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3"
77 case "${ARCH}" in 82 case "${ARCH}" in
78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 83 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;;
79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 84 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 85 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 86 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 87 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
83 esac 88 esac
159 164
160 return 0 165 return 0
161} 166}
162 167
163replace-cpu-flags() { 168replace-cpu-flags() {
164 local oldcpu newcpu="$1" ; shift 169 local newcpu="$#" ; newcpu="${!newcpu}"
165 for oldcpu in "$@" ; do 170 while [ $# -gt 1 ] ; do
166 # quote to make sure that no globbing is done (particularly on 171 # quote to make sure that no globbing is done (particularly on
167 # ${oldcpu} prior to calling replace-flags 172 # ${oldcpu} prior to calling replace-flags
168 replace-flags "-march=${oldcpu}" "-march=${newcpu}" 173 replace-flags "-march=${1}" "-march=${newcpu}"
169 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}" 174 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
170 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}" 175 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
176 shift
171 done 177 done
172 return 0 178 return 0
173} 179}
174 180
175is-flag() { 181is-flag() {
261 export CXXFLAGS="${NEW_CXXFLAGS}" 267 export CXXFLAGS="${NEW_CXXFLAGS}"
262 return 0 268 return 0
263} 269}
264 270
265test_flag() { 271test_flag() {
266 local cc=${CC:-gcc} ; cc=${cc%% *} 272 if $(tc-getCC) -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then
267 if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then
268 printf "%s\n" "$*" 273 printf "%s\n" "$*"
269 return 0 274 return 0
270 fi 275 fi
271 return 1 276 return 1
272} 277}
273 278
274test_version_info() { 279test_version_info() {
275 local cc=${CC:-gcc} ; cc=${cc%% *}
276 if [[ $(${cc} --version 2>&1) == *$1* ]]; then 280 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
277 return 0 281 return 0
278 else 282 else
279 return 1 283 return 1
280 fi 284 fi
281} 285}
310 done 314 done
311 return 1 315 return 1
312} 316}
313 317
314has_hardened() { 318has_hardened() {
315 test_version_info Hardened 319 test_version_info Hardened && return 0
320 # the specs file wont exist unless gcc has GCC_SPECS support
321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \
322 return 0
316 return $? 323 return 1
317} 324}
318 325
319has_pic() { 326has_pic() {
320 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 327 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
321 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 328 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
339has_m64() { 346has_m64() {
340 # this doesnt test if the flag is accepted, it tests if the flag 347 # this doesnt test if the flag is accepted, it tests if the flag
341 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 348 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
342 # please dont replace this function with test_flag in some future 349 # please dont replace this function with test_flag in some future
343 # clean-up! 350 # clean-up!
344 temp=`mktemp` 351 local temp="$(emktemp)"
345 echo "int main() { return(0); }" > ${temp}.c 352 echo "int main() { return(0); }" > ${temp}.c
346 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1 353 MY_CC=$(tc-getCC)
347 ret=$? 354 ${MY_CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
355 local ret=$?
348 rm -f ${temp}.c 356 rm -f ${temp}.c
349 [ "$ret" != "1" ] && return 0 357 [ "$ret" != "1" ] && return 0
350 return 1 358 return 1
351} 359}
352 360
353has_m32() { 361has_m32() {
354 # this doesnt test if the flag is accepted, it tests if the flag 362 # this doesnt test if the flag is accepted, it tests if the flag
355 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 363 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
356 # please dont replace this function with test_flag in some future 364 # please dont replace this function with test_flag in some future
357 # clean-up! 365 # clean-up!
358 temp=`mktemp` 366 local temp="$(emktemp)"
359 echo "int main() { return(0); }" > ${temp}.c 367 echo "int main() { return(0); }" > ${temp}.c
360 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 368 MY_CC=$(tc-getCC)
361 ret=$? 369 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
370 local ret=$?
362 rm -f ${temp}.c 371 rm -f ${temp}.c
363 [ "$ret" != "1" ] && return 0 372 [ "$ret" != "1" ] && return 0
364 return 1 373 return 1
365} 374}
366 375
411 420
412etexec-flags() { 421etexec-flags() {
413 # if you're not using a hardened compiler you wont need this 422 # if you're not using a hardened compiler you wont need this
414 # PIC/no-pic kludge in the first place. 423 # PIC/no-pic kludge in the first place.
415 has_hardened || return 0 424 has_hardened || return 0
416 # this kludge breaks on amd64, and probably other -fPIC dependant
417 # archs.
418 use amd64 && return 0 425 use amd64 && return 0
426 use mips && return 0
419 427
420 if has_pie || has_pic; then 428 if has_pie || has_pic; then
421 [ -z "`is-flag -fno-pic`" ] && 429 [ -z "`is-flag -fno-pic`" ] &&
422 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 430 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
423 [ -z "`is-flag -nopie`" ] && 431 [ -z "`is-flag -nopie`" ] &&
431 [ -z "`is-flag -fno-stack-protector`" ] && 439 [ -z "`is-flag -fno-stack-protector`" ] &&
432 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 440 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
433 fi 441 fi
434 return 0 442 return 0
435} 443}
444
445# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
446# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
447# fixes.
448#
449# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
450gcc2-flags() {
451 CFLAGS=${CFLAGS//pentium-mmx/i586}
452 CFLAGS=${CFLAGS//pentium[234]/i686}
453 CFLAGS=${CFLAGS//k6-[23]/k6}
454 CFLAGS=${CFLAGS//athlon-tbird/i686}
455 CFLAGS=${CFLAGS//athlon-4/i686}
456 CFLAGS=${CFLAGS//athlon-[xm]p/i686}
457 CFLAGS=${CFLAGS//athlon/i686}
458
459 CXXFLAGS=${CXXFLAGS//pentium-mmx/i586}
460 CXXFLAGS=${CXXFLAGS//pentium[234]/i686}
461 CXXFLAGS=${CXXFLAGS//k6-[23]/k6}
462 CXXFLAGS=${CXXFLAGS//athlon-tbird/i686}
463 CXXFLAGS=${CXXFLAGS//athlon-4/i686}
464 CXXFLAGS=${CXXFLAGS//athlon-[xm]p/i686}
465 CXXFLAGS=${CXXFLAGS//athlon/i686}
466
467 if [ "$ARCH" = alpha ]; then
468 CHOST=${CHOST/#alphaev6[78]/alphaev6}
469 CFLAGS=${CFLAGS//ev6[78]/ev6}
470 CXXFLAGS=${CXXFLAGS//ev6[78]/ev6}
471 fi
472
473 export CFLAGS CXXFLAGS
474}

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.77

  ViewVC Help
Powered by ViewVC 1.1.20