1 |
# Copyright 1999-2002 Gentoo Technologies, Inc. |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Author Bart Verwilst <verwilst@gentoo.org> |
4 |
# $Header: $ |
5 |
|
6 |
ECLASS=flag-o-matic |
7 |
INHERITED="$INHERITED $ECLASS" |
8 |
|
9 |
# |
10 |
#### filter-flags <flag> #### |
11 |
# Remove particular flags from C[XX]FLAGS |
12 |
# |
13 |
#### append-flags <flag> #### |
14 |
# Add extra flags to your current C[XX]FLAGS |
15 |
# |
16 |
#### replace-flags <orig.flag> <new.flag> ### |
17 |
# Replace a flag by another one |
18 |
# |
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 |
|
28 |
filter-flags () { |
29 |
|
30 |
for x in $1 |
31 |
do |
32 |
export CFLAGS="${CFLAGS/${x}}" |
33 |
export CXXFLAGS="${CXXFLAGS/${x}}" |
34 |
done |
35 |
|
36 |
} |
37 |
|
38 |
append-flags () { |
39 |
|
40 |
CFLAGS="${CFLAGS} $1" |
41 |
CXXFLAGS="${CXXFLAGS} $1" |
42 |
|
43 |
} |
44 |
|
45 |
replace-flags () { |
46 |
|
47 |
CFLAGS="${CFLAGS/${1}/${2}}" |
48 |
CXXFLAGS="${CXXFLAGS/${1}/${2}}" |
49 |
|
50 |
} |
51 |
|
52 |
is-flag() { |
53 |
|
54 |
for x in ${CFLAGS} ${CXXFLAGS} |
55 |
do |
56 |
if [ "${x}" = "$1" ] |
57 |
then |
58 |
echo true |
59 |
break |
60 |
fi |
61 |
done |
62 |
|
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 |
|