| 1 |
# Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 |
# Distributed under the terms of the GNU General Public License v2 |
| 3 |
# $Header: /home/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.12 2003/02/16 04:26:21 vapier Exp $ |
| 4 |
# |
| 5 |
# Author Bart Verwilst <verwilst@gentoo.org> |
| 6 |
|
| 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 -pipe -g" |
| 33 |
|
| 34 |
|
| 35 |
filter-flags () { |
| 36 |
|
| 37 |
for x in $1 |
| 38 |
do |
| 39 |
export CFLAGS="${CFLAGS/${x}}" |
| 40 |
export CXXFLAGS="${CXXFLAGS/${x}}" |
| 41 |
done |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
append-flags () { |
| 46 |
|
| 47 |
CFLAGS="${CFLAGS} $1" |
| 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 |
| 68 |
done |
| 69 |
|
| 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 |
if [ "${x/${y}}" != "${x}" ] |
| 84 |
then |
| 85 |
if [ -z "${NEW_CFLAGS}" ] |
| 86 |
then |
| 87 |
NEW_CFLAGS="${x}" |
| 88 |
else |
| 89 |
NEW_CFLAGS="${NEW_CFLAGS} ${x}" |
| 90 |
fi |
| 91 |
fi |
| 92 |
done |
| 93 |
done |
| 94 |
|
| 95 |
for x in ${CXXFLAGS} |
| 96 |
do |
| 97 |
for y in ${ALLOWED_FLAGS} |
| 98 |
do |
| 99 |
if [ "${x/${y}}" != "${x}" ] |
| 100 |
then |
| 101 |
if [ -z "${NEW_CXXFLAGS}" ] |
| 102 |
then |
| 103 |
NEW_CXXFLAGS="${x}" |
| 104 |
else |
| 105 |
NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" |
| 106 |
fi |
| 107 |
fi |
| 108 |
done |
| 109 |
done |
| 110 |
|
| 111 |
set +f |
| 112 |
|
| 113 |
export CFLAGS="${NEW_CFLAGS}" |
| 114 |
export CXXFLAGS="${NEW_CXXFLAGS}" |
| 115 |
} |
| 116 |
|
| 117 |
get-flag() { |
| 118 |
local findflag="$1" |
| 119 |
|
| 120 |
for f in ${CFLAGS} ${CXXFLAGS} ; do |
| 121 |
if [ "${f/${findflag}}" != "${f}" ] ; then |
| 122 |
echo "${f/-${findflag}=}" |
| 123 |
return |
| 124 |
fi |
| 125 |
done |
| 126 |
} |