| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 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.31 2003/12/10 21:13:25 agriffis Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.32 2003/12/21 06:50:15 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" |
| … | |
… | |
| 46 | # Add extra flags to your current LDFLAGS |
46 | # Add extra flags to your current LDFLAGS |
| 47 | # |
47 | # |
| 48 | #### etexec-flags #### |
48 | #### etexec-flags #### |
| 49 | # hooked function for hardened-gcc that appends |
49 | # hooked function for hardened-gcc that appends |
| 50 | # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed |
50 | # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed |
| 51 | # and a package is filtering -fPIC |
51 | # and a package is filtering -fPIC,-fpic, -fPIE, -fpie |
| 52 | # |
52 | # |
| 53 | #### fstack-flags #### |
53 | #### fstack-flags #### |
| 54 | # hooked function for hardened-gcc that appends |
54 | # hooked function for hardened-gcc that appends |
| 55 | # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed |
55 | # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed |
| 56 | # and a package is filtering -fstack-protector |
56 | # and a package is filtering -fstack-protector, -fstack-protector-all |
| 57 | # |
57 | # |
| 58 | |
58 | |
| 59 | # C[XX]FLAGS that we allow in strip-flags |
59 | # C[XX]FLAGS that we allow in strip-flags |
| 60 | ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
60 | ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
| 61 | case "${ARCH}" in |
61 | case "${ARCH}" in |
| … | |
… | |
| 91 | |
91 | |
| 92 | filter-flags() { |
92 | filter-flags() { |
| 93 | # we do two loops to avoid the first and last char from being chomped. |
93 | # we do two loops to avoid the first and last char from being chomped. |
| 94 | for x in $@ ; do |
94 | for x in $@ ; do |
| 95 | case "${x}" in |
95 | case "${x}" in |
| 96 | -fPIC) etexec-flags;; |
96 | -fPIC|-fpic|-fPIE|-fpie) etexec-flags;; |
| 97 | -fstack-protector) fstack-flags;; |
97 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
| 98 | *) ;; |
98 | *) ;; |
| 99 | esac |
99 | esac |
| 100 | done |
100 | done |
| 101 | # we do this fancy spacing stuff so as to not filter |
101 | # we do this fancy spacing stuff so as to not filter |
| 102 | # out part of a flag ... we want flag atoms ! :D |
102 | # out part of a flag ... we want flag atoms ! :D |
| … | |
… | |
| 112 | |
112 | |
| 113 | append-flags() { |
113 | append-flags() { |
| 114 | CFLAGS="${CFLAGS} $@" |
114 | CFLAGS="${CFLAGS} $@" |
| 115 | CXXFLAGS="${CXXFLAGS} $@" |
115 | CXXFLAGS="${CXXFLAGS} $@" |
| 116 | for x in $@; do |
116 | for x in $@; do |
| 117 | [ "${x}" = "-fno-stack-protector" ] && fstack-flags |
117 | [ "${x}" = "-fno-stack-protector" -o "${x}" = "-fno-stack-protector-all" ] && fstack-flags |
| 118 | done |
118 | done |
| 119 | return 0 |
119 | return 0 |
| 120 | } |
120 | } |
| 121 | |
121 | |
| 122 | replace-flags() { |
122 | replace-flags() { |