/[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.68 Revision 1.73
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.68 2004/08/08 21:07:21 lv Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.73 2004/10/13 14:11:52 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 10# Please leave ${IUSE} in this until portage .51 is stable, otherwise
11# IUSE gets clobbered. 11# IUSE gets clobbered.
12IUSE="${IUSE} debug" 12IUSE="${IUSE} debug"
13 13
14# need access to emktemp()
15inherit eutils
16
14# 17#
15#### filter-flags <flags> #### 18#### filter-flags <flags> ####
16# Remove particular flags from C[XX]FLAGS 19# Remove particular flags from C[XX]FLAGS
17# Matches only complete flags 20# Matches only complete flags
18# 21#
20# Add extra flags to your current C[XX]FLAGS 23# Add extra flags to your current C[XX]FLAGS
21# 24#
22#### replace-flags <orig.flag> <new.flag> ### 25#### replace-flags <orig.flag> <new.flag> ###
23# Replace a flag by another one 26# Replace a flag by another one
24# 27#
25#### replace-cpu-flags <new.cpu> <old.cpus> ### 28#### replace-cpu-flags <old.cpus> <new.cpu> ###
26# Replace march/mcpu flags that specify <old.cpus> 29# Replace march/mcpu flags that specify <old.cpus>
27# with flags that specify <new.cpu> 30# with flags that specify <new.cpu>
28# 31#
29#### is-flag <flag> #### 32#### is-flag <flag> ####
30# Returns "true" if flag is set in C[XX]FLAGS 33# Returns "true" if flag is set in C[XX]FLAGS
73# C[XX]FLAGS that we allow in strip-flags 76# C[XX]FLAGS that we allow in strip-flags
74setup-allowed-flags() { 77setup-allowed-flags() {
75 if [ -z "${ALLOWED_FLAGS}" ] ; then 78 if [ -z "${ALLOWED_FLAGS}" ] ; then
76 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-stack-protector -fno-pie -fno-unit-at-a-time -pipe -g" 79 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 80 case "${ARCH}" in
78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 81 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;;
79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 82 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 83 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 84 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 85 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
83 esac 86 esac
159 162
160 return 0 163 return 0
161} 164}
162 165
163replace-cpu-flags() { 166replace-cpu-flags() {
164 local oldcpu newcpu="$1" ; shift 167 local newcpu="$#" ; newcpu="${!newcpu}"
165 for oldcpu in "$@" ; do 168 while [ $# -gt 1 ] ; do
166 # quote to make sure that no globbing is done (particularly on 169 # quote to make sure that no globbing is done (particularly on
167 # ${oldcpu} prior to calling replace-flags 170 # ${oldcpu} prior to calling replace-flags
168 replace-flags "-march=${oldcpu}" "-march=${newcpu}" 171 replace-flags "-march=${1}" "-march=${newcpu}"
169 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}" 172 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
170 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}" 173 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
174 shift
171 done 175 done
172 return 0 176 return 0
173} 177}
174 178
175is-flag() { 179is-flag() {
262 return 0 266 return 0
263} 267}
264 268
265test_flag() { 269test_flag() {
266 local cc=${CC:-gcc} ; cc=${cc%% *} 270 local cc=${CC:-gcc} ; cc=${cc%% *}
267 if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then 271 if ${cc} -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then
268 printf "%s\n" "$*" 272 printf "%s\n" "$*"
269 return 0 273 return 0
270 fi 274 fi
271 return 1 275 return 1
272} 276}
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 ${CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
347 ret=$? 354 local ret=$?
348 rm -f ${temp}.c 355 rm -f ${temp}.c
349 [ "$ret" != "1" ] && return 0 356 [ "$ret" != "1" ] && return 0
350 return 1 357 return 1
351} 358}
352 359
353has_m32() { 360has_m32() {
354 # this doesnt test if the flag is accepted, it tests if the flag 361 # 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! 362 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
356 # please dont replace this function with test_flag in some future 363 # please dont replace this function with test_flag in some future
357 # clean-up! 364 # clean-up!
358 temp=`mktemp` 365 local temp="$(emktemp)"
359 echo "int main() { return(0); }" > ${temp}.c 366 echo "int main() { return(0); }" > ${temp}.c
360 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 367 ${CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
361 ret=$? 368 local ret=$?
362 rm -f ${temp}.c 369 rm -f ${temp}.c
363 [ "$ret" != "1" ] && return 0 370 [ "$ret" != "1" ] && return 0
364 return 1 371 return 1
365} 372}
366 373
431 [ -z "`is-flag -fno-stack-protector`" ] && 438 [ -z "`is-flag -fno-stack-protector`" ] &&
432 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 439 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
433 fi 440 fi
434 return 0 441 return 0
435} 442}
443
444# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
445# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
446# fixes.
447#
448# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
449gcc2-flags() {
450 CFLAGS=${CFLAGS//pentium-mmx/i586}
451 CFLAGS=${CFLAGS//pentium[234]/i686}
452 CFLAGS=${CFLAGS//k6-[23]/k6}
453 CFLAGS=${CFLAGS//athlon-tbird/i686}
454 CFLAGS=${CFLAGS//athlon-4/i686}
455 CFLAGS=${CFLAGS//athlon-[xm]p/i686}
456 CFLAGS=${CFLAGS//athlon/i686}
457
458 CXXFLAGS=${CXXFLAGS//pentium-mmx/i586}
459 CXXFLAGS=${CXXFLAGS//pentium[234]/i686}
460 CXXFLAGS=${CXXFLAGS//k6-[23]/k6}
461 CXXFLAGS=${CXXFLAGS//athlon-tbird/i686}
462 CXXFLAGS=${CXXFLAGS//athlon-4/i686}
463 CXXFLAGS=${CXXFLAGS//athlon-[xm]p/i686}
464 CXXFLAGS=${CXXFLAGS//athlon/i686}
465
466 if [ "$ARCH" = alpha ]; then
467 CHOST=${CHOST/#alphaev6[78]/alphaev6}
468 CFLAGS=${CFLAGS//ev6[78]/ev6}
469 CXXFLAGS=${CXXFLAGS//ev6[78]/ev6}
470 fi
471
472 export CFLAGS CXXFLAGS
473}

Legend:
Removed from v.1.68  
changed lines
  Added in v.1.73

  ViewVC Help
Powered by ViewVC 1.1.20