/[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.79 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.79 2004/12/25 18:45:56 chriswhite 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
101 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 96 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
102 return 0 97 return 0
103} 98}
104 99
105filter-flags() { 100filter-flags() {
106 local x f fset 101 local x f fset
107 declare -a new_CFLAGS new_CXXFLAGS 102 declare -a new_CFLAGS new_CXXFLAGS
108 103
109 for x in "$@" ; do 104 for x in "$@" ; do
110 case "${x}" in 105 case "${x}" in
111 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; 106 -fPIC|-fpic|-fPIE|-fpie|-pie)
107 append-flags `test_flag -fno-pie`;;
112 -fstack-protector|-fstack-protector-all) fstack-flags;; 108 -fstack-protector|-fstack-protector-all)
109 fstack-flags;;
113 esac 110 esac
114 done 111 done
115 112
116 for fset in CFLAGS CXXFLAGS; do 113 for fset in CFLAGS CXXFLAGS; do
117 # Looping over the flags instead of using a global 114 # Looping over the flags instead of using a global
138append-lfs-flags() { 135append-lfs-flags() {
139 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
140} 137}
141 138
142append-flags() { 139append-flags() {
140 [[ -z $* ]] && return 0
143 export CFLAGS="${CFLAGS} $*" 141 export CFLAGS="${CFLAGS} $*"
144 export CXXFLAGS="${CXXFLAGS} $*" 142 export CXXFLAGS="${CXXFLAGS} $*"
145 [ -n "`is-flag -fno-stack-protector`" -o \ 143 [ -n "`is-flag -fno-stack-protector`" -o \
146 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags 144 -n "`is-flag -fno-stack-protector-all`" ] && fstack-flags
147 return 0 145 return 0
148} 146}
149 147
150replace-flags() { 148replace-flags() {
151 local f fset 149 local f fset
152 declare -a new_CFLAGS new_CXXFLAGS 150 declare -a new_CFLAGS new_CXXFLAGS
153 151
154 for fset in CFLAGS CXXFLAGS; do 152 for fset in CFLAGS CXXFLAGS; do
155 # Looping over the flags instead of using a global 153 # Looping over the flags instead of using a global
156 # substitution ensures that we're working with flag atoms. 154 # substitution ensures that we're working with flag atoms.
323 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ 321 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \
324 return 0 322 return 0
325 return 1 323 return 1
326} 324}
327 325
326# indicate whether PIC is set
328has_pic() { 327has_pic() {
329 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 328 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
330 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 329 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
330 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0
331 test_version_info pie && return 0 331 test_version_info pie && return 0
332 return 1 332 return 1
333} 333}
334 334
335# indicate whether PIE is set
335has_pie() { 336has_pie() {
336 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 337 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
337 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 338 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
338 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
339 return 1 342 return 1
340} 343}
341 344
345# indicate whether code for SSP is being generated
342has_ssp() { 346has_ssp() {
347 # note; this matches both -fstack-protector and -fstack-protector-all
343 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 348 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
344 test_version_info ssp && return 0 349 [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0
345 return 1 350 return 1
346} 351}
347 352
348has_m64() { 353has_m64() {
349 # 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
363has_m32() { 368has_m32() {
364 # 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
365 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 370 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
366 # please dont replace this function with test_flag in some future 371 # please dont replace this function with test_flag in some future
367 # clean-up! 372 # clean-up!
373
374 [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0
375
368 local temp="$(emktemp)" 376 local temp="$(emktemp)"
369 echo "int main() { return(0); }" > ${temp}.c 377 echo "int main() { return(0); }" > ${temp}.c
370 MY_CC=$(tc-getCC) 378 MY_CC=$(tc-getCC)
371 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1 379 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
372 local ret=$? 380 local ret=$?
376} 384}
377 385
378replace-sparc64-flags() { 386replace-sparc64-flags() {
379 local SPARC64_CPUS="ultrasparc v9" 387 local SPARC64_CPUS="ultrasparc v9"
380 388
381 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then 389 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
382 for x in ${SPARC64_CPUS}; do 390 for x in ${SPARC64_CPUS}; do
383 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}" 391 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
384 done 392 done
385 else 393 else
386 for x in ${SPARC64_CPUS}; do 394 for x in ${SPARC64_CPUS}; do
387 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}" 395 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
388 done 396 done
389 fi 397 fi
390 398
391 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then 399 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
392 for x in ${SPARC64_CPUS}; do 400 for x in ${SPARC64_CPUS}; do
393 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}" 401 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
394 done 402 done
395 else 403 else
396 for x in ${SPARC64_CPUS}; do 404 for x in ${SPARC64_CPUS}; do
418 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 426 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
419 export LDFLAGS 427 export LDFLAGS
420 return 0 428 return 0
421} 429}
422 430
423etexec-flags() {
424 # if you're not using a hardened compiler you wont need this
425 # PIC/no-pic kludge in the first place.
426 has_hardened || return 0
427 use amd64 && return 0
428 use mips && return 0
429
430 if has_pie || has_pic; then
431 [ -z "`is-flag -fno-pic`" ] &&
432 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
433 [ -z "`is-flag -nopie`" ] &&
434 export CFLAGS="${CFLAGS} `test_flag -nopie`"
435 fi
436 return 0
437}
438
439fstack-flags() { 431fstack-flags() {
440 if has_ssp; then 432 if has_ssp; then
441 [ -z "`is-flag -fno-stack-protector`" ] && 433 [ -z "`is-flag -fno-stack-protector`" ] &&
442 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 434 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
443 fi 435 fi
444 return 0 436 return 0
445} 437}
446 438

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

  ViewVC Help
Powered by ViewVC 1.1.20