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