/[gentoo-x86]/eclass/flag-o-matic.eclass
Gentoo

Diff of /eclass/flag-o-matic.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.17
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.17 2003/04/27 20:57:46 azarah 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
5ECLASS=flag-o-matic 7ECLASS=flag-o-matic
8INHERITED="$INHERITED $ECLASS"
6 9
7# 10#
8#### filter-flags <flag> #### 11#### filter-flags <flag> ####
9# Remove particular flags from C[XX]FLAGS 12# Remove particular flags from C[XX]FLAGS
10# 13#
11#### append-flags <flag> #### 14#### append-flags <flag> ####
12# Add extra flags to your current C[XX]FLAGS 15# Add extra flags to your current C[XX]FLAGS
13# 16#
14#### change-flags <orig.flag> <new.flag> ### 17#### replace-flags <orig.flag> <new.flag> ###
15# Replace a flag by another one 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#### replace-sparc64-flags ####
32# Sets mcpu to v8 and uses the original value
33# as mtune if none specified.
16# 34#
17 35
18 36
37# C[XX]FLAGS that we allow in strip-flags
38ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
39
40# C[XX]FLAGS that we are think is ok, but needs testing
41# NOTE: currently -Os have issues with gcc3 and K6* arch's
42UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
43
19filter-flags () { 44filter-flags () {
20 45
21 for x in $1; do 46 for x in $1
47 do
22 CFLAGS="${CFLAGS/$x}" 48 export CFLAGS="${CFLAGS/${x}}"
23 CXXFLAGS="${CXXFLAGS/$x}" 49 export CXXFLAGS="${CXXFLAGS/${x}}"
24 done 50 done
25 51
26} 52}
27 53
28append-flags () { 54append-flags () {
29 55
30
31 CFLAGS="$CFLAGS $1" 56 CFLAGS="${CFLAGS} $1"
32 CXXFLAGS="$CXXFLAGS $1" 57 CXXFLAGS="${CXXFLAGS} $1"
33 58
34} 59}
35 60
36change-flags () { 61replace-flags () {
37 62
38 CFLAGS="${CFLAGS/${1}/${2}" 63 CFLAGS="${CFLAGS/${1}/${2} }"
39 CXXFLAGS="${CXXFLAGS/${1}/${2}" 64 CXXFLAGS="${CXXFLAGS/${1}/${2} }"
40 65
41} 66}
67
68is-flag() {
69
70 for x in ${CFLAGS} ${CXXFLAGS}
71 do
72 if [ "${x}" = "$1" ]
73 then
74 echo true
75 break
76 fi
77 done
78
79}
80
81strip-flags() {
82
83 local NEW_CFLAGS=""
84 local NEW_CXXFLAGS=""
85
86 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
87 if [ "${ACCEPT_KEYWORDS/~/}" != "${ACCEPT_KEYWORDS}" -a \
88 "${ACCEPT_KEYWORDS/-~/}" = "${ACCEPT_KEYWORDS}" ]
89 then
90 if use debug &> /dev/null
91 then
92 einfo "Enabling the use of some unstable flags"
93 fi
94
95 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
96 fi
97
98 set -f
99
100 for x in ${CFLAGS}
101 do
102 for y in ${ALLOWED_FLAGS}
103 do
104 flag=${x%%=*}
105 if [ "${flag%%${y}}" = "" ]
106 then
107 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
108 break
109 fi
110 done
111 done
112
113 for x in ${CXXFLAGS}
114 do
115 for y in ${ALLOWED_FLAGS}
116 do
117 flag=${x%%=*}
118 if [ "${flag%%${y}}" = "" ]
119 then
120 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
121 break
122 fi
123 done
124 done
125
126 set +f
127
128 use debug &>/dev/null && einfo "CFLAGS=\"${NEW_CFLAGS}\""
129 use debug &>/dev/null && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
130
131 export CFLAGS="${NEW_CFLAGS}"
132 export CXXFLAGS="${NEW_CXXFLAGS}"
133}
134
135get-flag() {
136 local findflag="$1"
137
138 for f in ${CFLAGS} ${CXXFLAGS} ; do
139 if [ "${f/${findflag}}" != "${f}" ] ; then
140 echo "${f/-${findflag}=}"
141 return
142 fi
143 done
144}
145
146replace-sparc64-flags () {
147
148 local SPARC64_CPUS="ultrasparc v9"
149
150 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
151 then
152 for x in ${SPARC64_CPUS}
153 do
154 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
155 done
156 else
157 for x in ${SPARC64_CPUS}
158 do
159 CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
160 done
161 fi
162
163 if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]
164 then
165 for x in ${SPARC64_CPUS}
166 do
167 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
168 done
169 else
170 for x in ${SPARC64_CPUS}
171 do
172 CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
173 done
174 fi
175
176}

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.20