| 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.18 2003/06/17 14:38:32 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.24 2003/07/22 12:48:11 aliz 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" |
| … | |
… | |
| 35 | # |
35 | # |
| 36 | |
36 | |
| 37 | |
37 | |
| 38 | # C[XX]FLAGS that we allow in strip-flags |
38 | # C[XX]FLAGS that we allow in strip-flags |
| 39 | ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
39 | ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" |
|
|
40 | case "${ARCH}" in |
|
|
41 | mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; |
|
|
42 | amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; |
|
|
43 | esac |
| 40 | |
44 | |
| 41 | # C[XX]FLAGS that we are think is ok, but needs testing |
45 | # C[XX]FLAGS that we are think is ok, but needs testing |
| 42 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
46 | # NOTE: currently -Os have issues with gcc3 and K6* arch's |
| 43 | UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
47 | UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" |
|
|
48 | |
|
|
49 | filter-mfpmath() { |
|
|
50 | for a in $CFLAGS; do |
|
|
51 | if [ "${a:0:8}" == "-mfpmath" ]; then |
|
|
52 | orig_mfpmath=$a |
|
|
53 | fi |
|
|
54 | done |
|
|
55 | |
|
|
56 | mfpmath="$( echo $orig_mfpmath | awk -F '=' '{print $2}' | tr "," " " )" |
|
|
57 | for b in $@; do |
|
|
58 | mfpmath="${mfpmath/$b}" |
|
|
59 | done |
|
|
60 | |
|
|
61 | if [ -z "${mfpmath/ }" ]; then |
|
|
62 | filter-flags "$orig_mfpmath" |
|
|
63 | else |
|
|
64 | new_mfpmath="-mfpmath=$( echo $mfpmath | sed -e "s/ /,/g" -e "s/,,/,/g" )" |
|
|
65 | replace-flags "$orig_mfpmath" "$new_mfpmath" |
|
|
66 | fi |
|
|
67 | } |
| 44 | |
68 | |
| 45 | filter-flags() { |
69 | filter-flags() { |
| 46 | # we do this fancy spacing stuff so as to not filter |
70 | # we do this fancy spacing stuff so as to not filter |
| 47 | # out part of a flag ... we want flag atoms ! :D |
71 | # out part of a flag ... we want flag atoms ! :D |
| 48 | export CFLAGS=" ${CFLAGS} " |
72 | export CFLAGS=" ${CFLAGS} " |
| … | |
… | |
| 54 | export CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
78 | export CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
| 55 | export CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
79 | export CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
| 56 | } |
80 | } |
| 57 | |
81 | |
| 58 | append-flags() { |
82 | append-flags() { |
| 59 | CFLAGS="${CFLAGS} $1" |
83 | CFLAGS="${CFLAGS} $@" |
| 60 | CXXFLAGS="${CXXFLAGS} $1" |
84 | CXXFLAGS="${CXXFLAGS} $@" |
| 61 | } |
85 | } |
| 62 | |
86 | |
| 63 | replace-flags() { |
87 | replace-flags() { |
| 64 | CFLAGS="${CFLAGS/${1}/${2} }" |
88 | CFLAGS="${CFLAGS/${1}/${2} }" |
| 65 | CXXFLAGS="${CXXFLAGS/${1}/${2} }" |
89 | CXXFLAGS="${CXXFLAGS/${1}/${2} }" |
| … | |
… | |
| 78 | strip-flags() { |
102 | strip-flags() { |
| 79 | local NEW_CFLAGS="" |
103 | local NEW_CFLAGS="" |
| 80 | local NEW_CXXFLAGS="" |
104 | local NEW_CXXFLAGS="" |
| 81 | |
105 | |
| 82 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
106 | # Allow unstable C[XX]FLAGS if we are using unstable profile ... |
| 83 | if [ "${ACCEPT_KEYWORDS/~/}" != "${ACCEPT_KEYWORDS}" -a \ |
107 | if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then |
| 84 | "${ACCEPT_KEYWORDS/-~/}" = "${ACCEPT_KEYWORDS}" ] |
|
|
| 85 | then |
|
|
| 86 | if use debug &> /dev/null |
|
|
| 87 | then |
|
|
| 88 | einfo "Enabling the use of some unstable flags" |
108 | [ `use debug` ] && einfo "Enabling the use of some unstable flags" |
| 89 | fi |
|
|
| 90 | |
|
|
| 91 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
109 | ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" |
| 92 | fi |
110 | fi |
| 93 | |
111 | |
| 94 | set -f |
112 | set -f |
| 95 | |
113 | |
| … | |
… | |
| 119 | done |
137 | done |
| 120 | done |
138 | done |
| 121 | |
139 | |
| 122 | set +f |
140 | set +f |
| 123 | |
141 | |
| 124 | use debug &>/dev/null && einfo "CFLAGS=\"${NEW_CFLAGS}\"" |
142 | [ `use debug` ] \ |
|
|
143 | && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ |
| 125 | use debug &>/dev/null && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" |
144 | && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" |
| 126 | |
145 | |
| 127 | export CFLAGS="${NEW_CFLAGS}" |
146 | export CFLAGS="${NEW_CFLAGS}" |
| 128 | export CXXFLAGS="${NEW_CXXFLAGS}" |
147 | export CXXFLAGS="${NEW_CXXFLAGS}" |
| 129 | } |
148 | } |
| 130 | |
149 | |
| 131 | get-flag() { |
150 | get-flag() { |