/[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.75
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.75 2004/10/28 01:38:31 vapier 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="-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 case "${ARCH}" in
78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 79 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;;
79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 80 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 81 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 82 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 83 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
83 esac 84 esac
159 160
160 return 0 161 return 0
161} 162}
162 163
163replace-cpu-flags() { 164replace-cpu-flags() {
164 local oldcpu newcpu="$1" ; shift 165 local newcpu="$#" ; newcpu="${!newcpu}"
165 for oldcpu in "$@" ; do 166 while [ $# -gt 1 ] ; do
166 # quote to make sure that no globbing is done (particularly on 167 # quote to make sure that no globbing is done (particularly on
167 # ${oldcpu} prior to calling replace-flags 168 # ${oldcpu} prior to calling replace-flags
168 replace-flags "-march=${oldcpu}" "-march=${newcpu}" 169 replace-flags "-march=${1}" "-march=${newcpu}"
169 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}" 170 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
170 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}" 171 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
172 shift
171 done 173 done
172 return 0 174 return 0
173} 175}
174 176
175is-flag() { 177is-flag() {
261 export CXXFLAGS="${NEW_CXXFLAGS}" 263 export CXXFLAGS="${NEW_CXXFLAGS}"
262 return 0 264 return 0
263} 265}
264 266
265test_flag() { 267test_flag() {
266 local cc=${CC:-gcc} ; cc=${cc%% *} 268 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" "$*" 269 printf "%s\n" "$*"
269 return 0 270 return 0
270 fi 271 fi
271 return 1 272 return 1
272} 273}
273 274
274test_version_info() { 275test_version_info() {
275 local cc=${CC:-gcc} ; cc=${cc%% *}
276 if [[ $(${cc} --version 2>&1) == *$1* ]]; then 276 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
277 return 0 277 return 0
278 else 278 else
279 return 1 279 return 1
280 fi 280 fi
281} 281}
310 done 310 done
311 return 1 311 return 1
312} 312}
313 313
314has_hardened() { 314has_hardened() {
315 test_version_info 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
316 return $? 319 return 1
317} 320}
318 321
319has_pic() { 322has_pic() {
320 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 323 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
321 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 324 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
339has_m64() { 342has_m64() {
340 # this doesnt test if the flag is accepted, it tests if the flag 343 # 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! 344 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
342 # please dont replace this function with test_flag in some future 345 # please dont replace this function with test_flag in some future
343 # clean-up! 346 # clean-up!
344 temp=`mktemp` 347 local temp="$(emktemp)"
345 echo "int main() { return(0); }" > ${temp}.c 348 echo "int main() { return(0); }" > ${temp}.c
346 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1 349 MY_CC=$(tc-getCC)
347 ret=$? 350 ${MY_CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
351 local ret=$?
348 rm -f ${temp}.c 352 rm -f ${temp}.c
349 [ "$ret" != "1" ] && return 0 353 [ "$ret" != "1" ] && return 0
350 return 1 354 return 1
351} 355}
352 356
353has_m32() { 357has_m32() {
354 # this doesnt test if the flag is accepted, it tests if the flag 358 # 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! 359 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
356 # please dont replace this function with test_flag in some future 360 # please dont replace this function with test_flag in some future
357 # clean-up! 361 # clean-up!
358 temp=`mktemp` 362 local temp="$(emktemp)"
359 echo "int main() { return(0); }" > ${temp}.c 363 echo "int main() { return(0); }" > ${temp}.c
360 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 364 MY_CC=$(tc-getCC)
361 ret=$? 365 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
366 local ret=$?
362 rm -f ${temp}.c 367 rm -f ${temp}.c
363 [ "$ret" != "1" ] && return 0 368 [ "$ret" != "1" ] && return 0
364 return 1 369 return 1
365} 370}
366 371
431 [ -z "`is-flag -fno-stack-protector`" ] && 436 [ -z "`is-flag -fno-stack-protector`" ] &&
432 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 437 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
433 fi 438 fi
434 return 0 439 return 0
435} 440}
441
442# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
443# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
444# fixes.
445#
446# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
447gcc2-flags() {
448 CFLAGS=${CFLAGS//pentium-mmx/i586}
449 CFLAGS=${CFLAGS//pentium[234]/i686}
450 CFLAGS=${CFLAGS//k6-[23]/k6}
451 CFLAGS=${CFLAGS//athlon-tbird/i686}
452 CFLAGS=${CFLAGS//athlon-4/i686}
453 CFLAGS=${CFLAGS//athlon-[xm]p/i686}
454 CFLAGS=${CFLAGS//athlon/i686}
455
456 CXXFLAGS=${CXXFLAGS//pentium-mmx/i586}
457 CXXFLAGS=${CXXFLAGS//pentium[234]/i686}
458 CXXFLAGS=${CXXFLAGS//k6-[23]/k6}
459 CXXFLAGS=${CXXFLAGS//athlon-tbird/i686}
460 CXXFLAGS=${CXXFLAGS//athlon-4/i686}
461 CXXFLAGS=${CXXFLAGS//athlon-[xm]p/i686}
462 CXXFLAGS=${CXXFLAGS//athlon/i686}
463
464 if [ "$ARCH" = alpha ]; then
465 CHOST=${CHOST/#alphaev6[78]/alphaev6}
466 CFLAGS=${CFLAGS//ev6[78]/ev6}
467 CXXFLAGS=${CXXFLAGS//ev6[78]/ev6}
468 fi
469
470 export CFLAGS CXXFLAGS
471}

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

  ViewVC Help
Powered by ViewVC 1.1.20