| 1 | # Copyright 1999-2002 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2002 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 | # Author Bart Verwilst <verwilst@gentoo.org> |
3 | # Author Bart Verwilst <verwilst@gentoo.org> |
| 4 | # /space/gentoo/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass |
4 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.8 2002/10/13 01:01:58 azarah Exp $ |
|
|
5 | |
| 5 | ECLASS=flag-o-matic |
6 | ECLASS=flag-o-matic |
| 6 | INHERITED="$INHERITED $ECLASS" |
7 | INHERITED="$INHERITED $ECLASS" |
|
|
8 | |
| 7 | # |
9 | # |
| 8 | #### filter-flags <flag> #### |
10 | #### filter-flags <flag> #### |
| 9 | # Remove particular flags from C[XX]FLAGS |
11 | # Remove particular flags from C[XX]FLAGS |
| 10 | # |
12 | # |
| 11 | #### append-flags <flag> #### |
13 | #### append-flags <flag> #### |
| … | |
… | |
| 16 | # |
18 | # |
| 17 | #### is-flag <flag> #### |
19 | #### is-flag <flag> #### |
| 18 | # Returns "true" if flag is set in C[XX]FLAGS |
20 | # Returns "true" if flag is set in C[XX]FLAGS |
| 19 | # Matches only complete flag |
21 | # Matches only complete flag |
| 20 | # |
22 | # |
|
|
23 | #### strip-flags #### |
|
|
24 | # Strip C[XX]FLAGS of everything except known |
|
|
25 | # good options. |
|
|
26 | # |
| 21 | |
27 | |
| 22 | filter-flags () { |
28 | filter-flags () { |
| 23 | |
29 | |
| 24 | for x in $1; do |
30 | for x in $1 |
|
|
31 | do |
| 25 | CFLAGS="${CFLAGS/$x}" |
32 | export CFLAGS="${CFLAGS/${x}}" |
| 26 | CXXFLAGS="${CXXFLAGS/$x}" |
33 | export CXXFLAGS="${CXXFLAGS/${x}}" |
| 27 | done |
34 | done |
| 28 | |
35 | |
| 29 | } |
36 | } |
| 30 | |
37 | |
| 31 | append-flags () { |
38 | append-flags () { |
| 32 | |
39 | |
| 33 | |
|
|
| 34 | CFLAGS="$CFLAGS $1" |
40 | CFLAGS="${CFLAGS} $1" |
| 35 | CXXFLAGS="$CXXFLAGS $1" |
41 | CXXFLAGS="${CXXFLAGS} $1" |
| 36 | |
42 | |
| 37 | } |
43 | } |
| 38 | |
44 | |
| 39 | replace-flags () { |
45 | replace-flags () { |
| 40 | |
46 | |
| … | |
… | |
| 43 | |
49 | |
| 44 | } |
50 | } |
| 45 | |
51 | |
| 46 | is-flag() { |
52 | is-flag() { |
| 47 | |
53 | |
| 48 | for x in $CFLAGS $CXXFLAGS; do |
54 | for x in ${CFLAGS} ${CXXFLAGS} |
|
|
55 | do |
| 49 | if [ "$x" == "$1" ]; then |
56 | if [ "${x}" = "$1" ] |
|
|
57 | then |
| 50 | echo true |
58 | echo true |
| 51 | break |
59 | break |
| 52 | fi |
60 | fi |
| 53 | done |
61 | done |
| 54 | |
62 | |
| 55 | } |
63 | } |
|
|
64 | |
|
|
65 | strip-flags() { |
|
|
66 | |
|
|
67 | local NEW_CFLAGS="" |
|
|
68 | local NEW_CXXFLAGS="" |
|
|
69 | |
|
|
70 | local ALLOWED_FLAGS="-O -mcpu -march -pipe" |
|
|
71 | |
|
|
72 | set -f |
|
|
73 | |
|
|
74 | for x in ${CFLAGS} |
|
|
75 | do |
|
|
76 | for y in ${ALLOWED_FLAGS} |
|
|
77 | do |
|
|
78 | if [ "${x/${y}}" != "${x}" ] |
|
|
79 | then |
|
|
80 | if [ -z "${NEW_CFLAGS}" ] |
|
|
81 | then |
|
|
82 | NEW_CFLAGS="${x}" |
|
|
83 | else |
|
|
84 | NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
|
|
85 | fi |
|
|
86 | fi |
|
|
87 | done |
|
|
88 | done |
|
|
89 | |
|
|
90 | for x in ${CXXFLAGS} |
|
|
91 | do |
|
|
92 | for y in ${ALLOWED_FLAGS} |
|
|
93 | do |
|
|
94 | if [ "${x/${y}}" != "${x}" ] |
|
|
95 | then |
|
|
96 | if [ -z "${NEW_CXXFLAGS}" ] |
|
|
97 | then |
|
|
98 | NEW_CXXFLAGS="${x}" |
|
|
99 | else |
|
|
100 | NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
|
|
101 | fi |
|
|
102 | fi |
|
|
103 | done |
|
|
104 | done |
|
|
105 | |
|
|
106 | set +f |
|
|
107 | |
|
|
108 | export CFLAGS="${NEW_CFLAGS}" |
|
|
109 | export CXXFLAGS="${NEW_CXXFLAGS}" |
|
|
110 | } |
|
|
111 | |