/[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.77 Revision 1.83
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.77 2004/11/13 07:07:08 solar Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.83 2005/02/19 07:11:31 mr_bones_ 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
10IUSE="debug" 10IUSE="debug"
11 11
12# need access to emktemp() 12# need access to emktemp()
13inherit eutils toolchain-funcs 13inherit eutils toolchain-funcs multilib
14 14
15# 15#
16#### filter-flags <flags> #### 16#### filter-flags <flags> ####
17# Remove particular flags from C[XX]FLAGS 17# Remove particular flags from C[XX]FLAGS
18# Matches only complete flags 18# Matches only complete flags
55# Add extra flags to your current LDFLAGS 55# Add extra flags to your current LDFLAGS
56# 56#
57#### filter-ldflags <flags> #### 57#### filter-ldflags <flags> ####
58# Remove particular flags from LDFLAGS 58# Remove particular flags from LDFLAGS
59# Matches only complete flags 59# Matches only complete flags
60#
61#### etexec-flags ####
62# hooked function for hardened gcc that appends
63# -fno-pic to {C,CXX,LD}FLAGS
64# when a package is filtering -fpic, -fPIC, -fpie, -fPIE
65# 60#
66#### fstack-flags #### 61#### fstack-flags ####
67# hooked function for hardened gcc that appends 62# hooked function for hardened gcc that appends
68# -fno-stack-protector to {C,CXX,LD}FLAGS 63# -fno-stack-protector to {C,CXX,LD}FLAGS
69# when a package is filtering -fstack-protector, -fstack-protector-all 64# when a package is filtering -fstack-protector, -fstack-protector-all
83 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;; 78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;;
84 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
85 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
86 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
87 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
83 sparc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32 -m64" ;;
84 ppc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mabi" ;;
88 esac 85 esac
89 fi 86 fi
90 # allow a bunch of flags that negate features / control ABI 87 # allow a bunch of flags that negate features / control ABI
91 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" 88 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
92 case "${ARCH}" in 89 case "${ARCH}" in
99 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 96 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
100 return 0 97 return 0
101} 98}
102 99
103filter-flags() { 100filter-flags() {
104 local x f fset 101 local x f fset
105 declare -a new_CFLAGS new_CXXFLAGS 102 declare -a new_CFLAGS new_CXXFLAGS
106 103
107 for x in "$@" ; do 104 for x in "$@" ; do
108 case "${x}" in 105 case "${x}" in
109 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 106 -fPIC|-fpic|-fPIE|-fpie|-pie)
107 append-flags `test_flag -fno-pie`;;
110 -fstack-protector|-fstack-protector-all) fstack-flags;; 108 -fstack-protector|-fstack-protector-all)
109 fstack-flags;;
111 esac 110 esac
112 done 111 done
113 112
114 for fset in CFLAGS CXXFLAGS; do 113 for fset in CFLAGS CXXFLAGS; do
115 # Looping over the flags instead of using a global 114 # Looping over the flags instead of using a global
136append-lfs-flags() { 135append-lfs-flags() {
137 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 136 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
138} 137}
139 138
140append-flags() { 139append-flags() {
140 [[ -z $* ]] && return 0
141 export CFLAGS="${CFLAGS} $*" 141 export CFLAGS="${CFLAGS} $*"
142 export CXXFLAGS="${CXXFLAGS} $*" 142 export CXXFLAGS="${CXXFLAGS} $*"
143 [ -n "`is-flag -fno-stack-protector`" -o \ 143 [ -n "`is-flag -fno-stack-protector`" -o \
144 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 144 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
145 return 0 145 return 0
146} 146}
147 147
148replace-flags() { 148replace-flags() {
149 local f fset 149 local f fset
150 declare -a new_CFLAGS new_CXXFLAGS 150 declare -a new_CFLAGS new_CXXFLAGS
151 151
152 for fset in CFLAGS CXXFLAGS; do 152 for fset in CFLAGS CXXFLAGS; do
153 # Looping over the flags instead of using a global 153 # Looping over the flags instead of using a global
154 # substitution ensures that we're working with flag atoms. 154 # substitution ensures that we're working with flag atoms.
321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \
322 return 0 322 return 0
323 return 1 323 return 1
324} 324}
325 325
326# indicate whether PIC is set
326has_pic() { 327has_pic() {
327 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 328 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
328 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 329 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
330 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0
329 test_version_info pie && return 0 331 test_version_info pie && return 0
330 return 1 332 return 1
331} 333}
332 334
335# indicate whether PIE is set
333has_pie() { 336has_pie() {
334 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 337 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
335 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 338 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
336 test_version_info pie && return 0 339 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0
340 # test PIC while waiting for specs to be updated to generate __PIE__
341 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0
337 return 1 342 return 1
338} 343}
339 344
345# indicate whether code for SSP is being generated
340has_ssp() { 346has_ssp() {
347 # note; this matches both -fstack-protector and -fstack-protector-all
341 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 348 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
342 test_version_info ssp && return 0 349 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0
343 return 1 350 return 1
344} 351}
345 352
346has_m64() { 353has_m64() {
347 # this doesnt test if the flag is accepted, it tests if the flag 354 # this doesnt test if the flag is accepted, it tests if the flag
361has_m32() { 368has_m32() {
362 # this doesnt test if the flag is accepted, it tests if the flag 369 # this doesnt test if the flag is accepted, it tests if the flag
363 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 370 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
364 # please dont replace this function with test_flag in some future 371 # please dont replace this function with test_flag in some future
365 # clean-up! 372 # clean-up!
373
374 [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0
375
366 local temp="$(emktemp)" 376 local temp="$(emktemp)"
367 echo "int main() { return(0); }" > ${temp}.c 377 echo "int main() { return(0); }" > ${temp}.c
368 MY_CC=$(tc-getCC) 378 MY_CC=$(tc-getCC)
369 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 379 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
370 local ret=$? 380 local ret=$?
374} 384}
375 385
376replace-sparc64-flags() { 386replace-sparc64-flags() {
377 local SPARC64_CPUS="ultrasparc v9" 387 local SPARC64_CPUS="ultrasparc v9"
378 388
379 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 389 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
380 for x in ${SPARC64_CPUS}; do 390 for x in ${SPARC64_CPUS}; do
381 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 391 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
382 done 392 done
383 else 393 else
384 for x in ${SPARC64_CPUS}; do 394 for x in ${SPARC64_CPUS}; do
385 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 395 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
386 done 396 done
387 fi 397 fi
388 398
389 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then 399 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
390 for x in ${SPARC64_CPUS}; do 400 for x in ${SPARC64_CPUS}; do
391 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 401 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
392 done 402 done
393 else 403 else
394 for x in ${SPARC64_CPUS}; do 404 for x in ${SPARC64_CPUS}; do
416 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 426 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
417 export LDFLAGS 427 export LDFLAGS
418 return 0 428 return 0
419} 429}
420 430
421etexec-flags() {
422 # if you're not using a hardened compiler you wont need this
423 # PIC/no-pic kludge in the first place.
424 has_hardened || return 0
425 use amd64 && return 0
426 use mips && return 0
427
428 if has_pie || has_pic; then
429 [ -z "`is-flag -fno-pic`" ] &&
430 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
431 [ -z "`is-flag -nopie`" ] &&
432 export CFLAGS="${CFLAGS} `test_flag -nopie`"
433 fi
434 return 0
435}
436
437fstack-flags() { 431fstack-flags() {
438 if has_ssp; then 432 if has_ssp; then
439 [ -z "`is-flag -fno-stack-protector`" ] && 433 [ -z "`is-flag -fno-stack-protector`" ] &&
440 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 434 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
441 fi 435 fi
442 return 0 436 return 0
443} 437}
444 438

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

  ViewVC Help
Powered by ViewVC 1.1.20