/[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.78 Revision 1.82
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.78 2004/12/22 21:18:35 eradicator Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.82 2005/02/07 17:50:24 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
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
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" ;;
88 sparc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32 -m64" ;; 83 sparc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32 -m64" ;;
84 ppc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mabi" ;;
89 esac 85 esac
90 fi 86 fi
91 # allow a bunch of flags that negate features / control ABI 87 # allow a bunch of flags that negate features / control ABI
92 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all" 88 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
93 case "${ARCH}" in 89 case "${ARCH}" in
105 local x f fset 101 local x f fset
106 declare -a new_CFLAGS new_CXXFLAGS 102 declare -a new_CFLAGS new_CXXFLAGS
107 103
108 for x in "$@" ; do 104 for x in "$@" ; do
109 case "${x}" in 105 case "${x}" in
110 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 106 -fPIC|-fpic|-fPIE|-fpie|-pie)
107 append-flags `test_flag -fno-pie`;;
111 -fstack-protector|-fstack-protector-all) fstack-flags;; 108 -fstack-protector|-fstack-protector-all)
109 fstack-flags;;
112 esac 110 esac
113 done 111 done
114 112
115 for fset in CFLAGS CXXFLAGS; do 113 for fset in CFLAGS CXXFLAGS; do
116 # Looping over the flags instead of using a global 114 # Looping over the flags instead of using a global
137append-lfs-flags() { 135append-lfs-flags() {
138 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
139} 137}
140 138
141append-flags() { 139append-flags() {
140 [[ -z $* ]] && return 0
142 export CFLAGS="${CFLAGS} $*" 141 export CFLAGS="${CFLAGS} $*"
143 export CXXFLAGS="${CXXFLAGS} $*" 142 export CXXFLAGS="${CXXFLAGS} $*"
144 [ -n "`is-flag -fno-stack-protector`" -o \ 143 [ -n "`is-flag -fno-stack-protector`" -o \
145 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 144 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
146 return 0 145 return 0
322 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \
323 return 0 322 return 0
324 return 1 323 return 1
325} 324}
326 325
326# indicate whether PIC is set
327has_pic() { 327has_pic() {
328 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 328 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
329 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 329 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
330 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0
330 test_version_info pie && return 0 331 test_version_info pie && return 0
331 return 1 332 return 1
332} 333}
333 334
335# indicate whether PIE is set
334has_pie() { 336has_pie() {
335 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 337 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
336 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 338 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
337 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
338 return 1 342 return 1
339} 343}
340 344
345# indicate whether code for SSP is being generated
341has_ssp() { 346has_ssp() {
347 # note; this matches both -fstack-protector and -fstack-protector-all
342 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 348 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
343 test_version_info ssp && return 0 349 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0
344 return 1 350 return 1
345} 351}
346 352
347has_m64() { 353has_m64() {
348 # 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
362has_m32() { 368has_m32() {
363 # 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
364 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 370 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
365 # please dont replace this function with test_flag in some future 371 # please dont replace this function with test_flag in some future
366 # clean-up! 372 # clean-up!
373
374 [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0
375
367 local temp="$(emktemp)" 376 local temp="$(emktemp)"
368 echo "int main() { return(0); }" > ${temp}.c 377 echo "int main() { return(0); }" > ${temp}.c
369 MY_CC=$(tc-getCC) 378 MY_CC=$(tc-getCC)
370 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 379 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
371 local ret=$? 380 local ret=$?
414 for x in "$@" ; do 423 for x in "$@" ; do
415 LDFLAGS="${LDFLAGS// ${x} / }" 424 LDFLAGS="${LDFLAGS// ${x} / }"
416 done 425 done
417 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 426 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
418 export LDFLAGS 427 export LDFLAGS
419 return 0
420}
421
422etexec-flags() {
423 # if you're not using a hardened compiler you wont need this
424 # PIC/no-pic kludge in the first place.
425 has_hardened || return 0
426 use amd64 && return 0
427 use mips && return 0
428
429 if has_pie || has_pic; then
430 [ -z "`is-flag -fno-pic`" ] &&
431 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
432 [ -z "`is-flag -nopie`" ] &&
433 export CFLAGS="${CFLAGS} `test_flag -nopie`"
434 fi
435 return 0 428 return 0
436} 429}
437 430
438fstack-flags() { 431fstack-flags() {
439 if has_ssp; then 432 if has_ssp; then

Legend:
Removed from v.1.78  
changed lines
  Added in v.1.82

  ViewVC Help
Powered by ViewVC 1.1.20