| 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.81 2005/01/29 03:09:45 solar 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 | |
| 7 | ECLASS=flag-o-matic |
7 | ECLASS=flag-o-matic |
| 8 | INHERITED="$INHERITED $ECLASS" |
8 | INHERITED="$INHERITED $ECLASS" |
| … | |
… | |
| 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 |
| … | |
… | |
| 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 |
| … | |
… | |
| 138 | append-lfs-flags() { |
135 | append-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 | |
| 142 | append-flags() { |
139 | append-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 |
| … | |
… | |
| 428 | LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" |
426 | LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" |
| 429 | export LDFLAGS |
427 | export LDFLAGS |
| 430 | return 0 |
428 | return 0 |
| 431 | } |
429 | } |
| 432 | |
430 | |
| 433 | etexec-flags() { |
|
|
| 434 | # if you're not using a hardened compiler you wont need this |
|
|
| 435 | # PIC/no-pic kludge in the first place. |
|
|
| 436 | has_hardened || return 0 |
|
|
| 437 | use amd64 && return 0 |
|
|
| 438 | use mips && return 0 |
|
|
| 439 | |
|
|
| 440 | if has_pie || has_pic; then |
|
|
| 441 | [ -z "`is-flag -fno-pic`" ] && |
|
|
| 442 | export CFLAGS="${CFLAGS} `test_flag -fno-pic`" |
|
|
| 443 | [ -z "`is-flag -nopie`" ] && |
|
|
| 444 | export CFLAGS="${CFLAGS} `test_flag -nopie`" |
|
|
| 445 | fi |
|
|
| 446 | return 0 |
|
|
| 447 | } |
|
|
| 448 | |
|
|
| 449 | fstack-flags() { |
431 | fstack-flags() { |
| 450 | if has_ssp; then |
432 | if has_ssp; then |
| 451 | [ -z "`is-flag -fno-stack-protector`" ] && |
433 | [ -z "`is-flag -fno-stack-protector`" ] && |
| 452 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
434 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
| 453 | fi |
435 | fi |