| 1 | # Copyright 1999-2002 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.15 2003/04/06 23:35:41 method Exp $ |
|
|
4 | # |
| 3 | # Author Bart Verwilst <verwilst@gentoo.org> |
5 | # Author Bart Verwilst <verwilst@gentoo.org> |
| 4 | # /space/gentoo/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass |
6 | |
| 5 | ECLASS=flag-o-matic |
7 | ECLASS=flag-o-matic |
|
|
8 | INHERITED="$INHERITED $ECLASS" |
|
|
9 | |
|
|
10 | # |
|
|
11 | #### filter-flags <flag> #### |
|
|
12 | # Remove particular flags from C[XX]FLAGS |
|
|
13 | # |
|
|
14 | #### append-flags <flag> #### |
|
|
15 | # Add extra flags to your current C[XX]FLAGS |
|
|
16 | # |
|
|
17 | #### replace-flags <orig.flag> <new.flag> ### |
|
|
18 | # Replace a flag by another one |
|
|
19 | # |
|
|
20 | #### is-flag <flag> #### |
|
|
21 | # Returns "true" if flag is set in C[XX]FLAGS |
|
|
22 | # Matches only complete flag |
|
|
23 | # |
|
|
24 | #### strip-flags #### |
|
|
25 | # Strip C[XX]FLAGS of everything except known |
|
|
26 | # good options. |
|
|
27 | # |
|
|
28 | #### get-flag <flag> #### |
|
|
29 | # Find and echo the value for a particular flag |
|
|
30 | # |
|
|
31 | |
|
|
32 | ALLOWED_FLAGS="-O -mcpu -march -mtune -fstack-protector -pipe -g" |
|
|
33 | |
| 6 | |
34 | |
| 7 | filter-flags () { |
35 | filter-flags () { |
| 8 | |
36 | |
| 9 | for x in $1; do |
37 | for x in $1 |
|
|
38 | do |
| 10 | CFLAGS="${CFLAGS/$x}" |
39 | export CFLAGS="${CFLAGS/${x}}" |
| 11 | CXXFLAGS="${CXXFLAGS/$x}" |
40 | export CXXFLAGS="${CXXFLAGS/${x}}" |
| 12 | done |
41 | done |
| 13 | |
42 | |
| 14 | } |
43 | } |
| 15 | |
44 | |
| 16 | max-optim () { |
45 | append-flags () { |
| 17 | |
46 | |
| 18 | for x in $CFLAGS; do |
47 | CFLAGS="${CFLAGS} $1" |
| 19 | echo $x |
48 | CXXFLAGS="${CXXFLAGS} $1" |
|
|
49 | |
|
|
50 | } |
|
|
51 | |
|
|
52 | replace-flags () { |
|
|
53 | |
|
|
54 | CFLAGS="${CFLAGS/${1}/${2} }" |
|
|
55 | CXXFLAGS="${CXXFLAGS/${1}/${2} }" |
|
|
56 | |
|
|
57 | } |
|
|
58 | |
|
|
59 | is-flag() { |
|
|
60 | |
|
|
61 | for x in ${CFLAGS} ${CXXFLAGS} |
|
|
62 | do |
|
|
63 | if [ "${x}" = "$1" ] |
|
|
64 | then |
|
|
65 | echo true |
|
|
66 | break |
|
|
67 | fi |
| 20 | done |
68 | done |
| 21 | |
69 | |
| 22 | } |
70 | } |
|
|
71 | |
|
|
72 | strip-flags() { |
|
|
73 | |
|
|
74 | local NEW_CFLAGS="" |
|
|
75 | local NEW_CXXFLAGS="" |
|
|
76 | |
|
|
77 | set -f |
|
|
78 | |
|
|
79 | for x in ${CFLAGS} |
|
|
80 | do |
|
|
81 | for y in ${ALLOWED_FLAGS} |
|
|
82 | do |
|
|
83 | flag=${x%%=*} |
|
|
84 | if [ "${flag%%${y}}" = "" ] |
|
|
85 | then |
|
|
86 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
|
|
87 | break |
|
|
88 | fi |
|
|
89 | done |
|
|
90 | done |
|
|
91 | |
|
|
92 | for x in ${CXXFLAGS} |
|
|
93 | do |
|
|
94 | for y in ${ALLOWED_FLAGS} |
|
|
95 | do |
|
|
96 | flag=${x%%=*} |
|
|
97 | if [ "${flag%%${y}}" = "" ] |
|
|
98 | then |
|
|
99 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
|
|
100 | break |
|
|
101 | fi |
|
|
102 | done |
|
|
103 | done |
|
|
104 | |
|
|
105 | set +f |
|
|
106 | |
|
|
107 | export CFLAGS="${NEW_CFLAGS}" |
|
|
108 | export CXXFLAGS="${NEW_CXXFLAGS}" |
|
|
109 | } |
|
|
110 | |
|
|
111 | get-flag() { |
|
|
112 | local findflag="$1" |
|
|
113 | |
|
|
114 | for f in ${CFLAGS} ${CXXFLAGS} ; do |
|
|
115 | if [ "${f/${findflag}}" != "${f}" ] ; then |
|
|
116 | echo "${f/-${findflag}=}" |
|
|
117 | return |
|
|
118 | fi |
|
|
119 | done |
|
|
120 | } |