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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.40 - (hide annotations) (download)
Fri Mar 12 11:21:15 2004 UTC (10 years, 1 month ago) by vapier
Branch: MAIN
Changes since 1.39: +5 -1 lines
add filter-lfs-flags

1 vapier 1.12 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 verwilst 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.40 # $Header: /home/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.39 2004/03/12 05:14:45 solar Exp $
4 vapier 1.12 #
5 verwilst 1.1 # Author Bart Verwilst <verwilst@gentoo.org>
6 azarah 1.8
7 verwilst 1.1 ECLASS=flag-o-matic
8 danarmak 1.6 INHERITED="$INHERITED $ECLASS"
9 azarah 1.8
10 verwilst 1.2 #
11 vapier 1.18 #### filter-flags <flags> ####
12 verwilst 1.3 # Remove particular flags from C[XX]FLAGS
13 vapier 1.18 # Matches only complete flags
14 verwilst 1.2 #
15 vapier 1.18 #### append-flags <flags> ####
16 verwilst 1.3 # Add extra flags to your current C[XX]FLAGS
17     #
18 verwilst 1.4 #### replace-flags <orig.flag> <new.flag> ###
19 verwilst 1.3 # Replace a flag by another one
20     #
21 vapier 1.37 #### replace-cpu-flags <new.cpu> <old.cpus> ###
22     # Replace march/mcpu flags that specify <old.cpus>
23     # with flags that specify <new.cpu>
24     #
25 danarmak 1.7 #### is-flag <flag> ####
26     # Returns "true" if flag is set in C[XX]FLAGS
27 vapier 1.18 # Matches only complete a flag
28 danarmak 1.7 #
29 azarah 1.8 #### strip-flags ####
30     # Strip C[XX]FLAGS of everything except known
31     # good options.
32     #
33 puggy 1.29 #### strip-unsupported-flags ####
34     # Strip C[XX]FLAGS of any flags not supported by
35     # installed version of gcc
36     #
37 vapier 1.10 #### get-flag <flag> ####
38     # Find and echo the value for a particular flag
39     #
40 joker 1.16 #### replace-sparc64-flags ####
41     # Sets mcpu to v8 and uses the original value
42     # as mtune if none specified.
43     #
44 vapier 1.26 #### filter-mfpmath <math types> ####
45     # Remove specified math types from the fpmath specification
46     # If the user has -mfpmath=sse,386, running `filter-mfpmath sse`
47     # will leave the user with -mfpmath=386
48 solar 1.27 #
49     #### append-ldflags ####
50     # Add extra flags to your current LDFLAGS
51     #
52     #### etexec-flags ####
53     # hooked function for hardened-gcc that appends
54     # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed
55 solar 1.32 # and a package is filtering -fPIC,-fpic, -fPIE, -fpie
56 solar 1.27 #
57     #### fstack-flags ####
58     # hooked function for hardened-gcc that appends
59     # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed
60 solar 1.32 # and a package is filtering -fstack-protector, -fstack-protector-all
61 solar 1.27 #
62 verwilst 1.3
63 azarah 1.17 # C[XX]FLAGS that we allow in strip-flags
64 vapier 1.36 setup-allowed-flags() {
65     export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
66     case "${ARCH}" in
67     mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
68     amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
69     alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
70     ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
71     esac
72    
73     # C[XX]FLAGS that we are think is ok, but needs testing
74     # NOTE: currently -Os have issues with gcc3 and K6* arch's
75     export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
76     return 0
77 aliz 1.24 }
78 verwilst 1.13
79 vapier 1.18 filter-flags() {
80 vapier 1.36 for x in "$@" ; do
81 solar 1.27 case "${x}" in
82 solar 1.39 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
83 solar 1.32 -fstack-protector|-fstack-protector-all) fstack-flags;;
84 solar 1.27 *) ;;
85     esac
86     done
87 vapier 1.36
88 vapier 1.18 # we do this fancy spacing stuff so as to not filter
89     # out part of a flag ... we want flag atoms ! :D
90 agriffis 1.25 CFLAGS=" ${CFLAGS} "
91     CXXFLAGS=" ${CXXFLAGS} "
92 vapier 1.36 for x in "$@" ; do
93 vapier 1.37 CFLAGS="${CFLAGS// ${x} / }"
94     CXXFLAGS="${CXXFLAGS// ${x} / }"
95 verwilst 1.1 done
96 agriffis 1.25 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
97     CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
98 vapier 1.36 return 0
99 verwilst 1.2 }
100    
101 vapier 1.40 filter-lfs-flags() {
102     filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
103     }
104    
105 vapier 1.18 append-flags() {
106 vapier 1.36 export CFLAGS="${CFLAGS} $@"
107     export CXXFLAGS="${CXXFLAGS} $@"
108 vapier 1.33 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags
109 vapier 1.28 return 0
110 verwilst 1.1 }
111    
112 vapier 1.18 replace-flags() {
113 vapier 1.36 # we do this fancy spacing stuff so as to not filter
114     # out part of a flag ... we want flag atoms ! :D
115     CFLAGS=" ${CFLAGS} "
116     CXXFLAGS=" ${CXXFLAGS} "
117 vapier 1.37 CFLAGS="${CFLAGS// ${1} / ${2} }"
118     CXXFLAGS="${CXXFLAGS// ${1} / ${2} }"
119 vapier 1.36 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
120     CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
121 vapier 1.28 return 0
122 danarmak 1.7 }
123    
124 vapier 1.37 replace-cpu-flags() {
125     local newcpu="$1" ; shift
126     local oldcpu=""
127     for oldcpu in "$@" ; do
128     replace-flags -march=${oldcpu} -march=${newcpu}
129     replace-flags -mcpu=${oldcpu} -mcpu=${newcpu}
130 vapier 1.38 replace-flags -mtune=${oldcpu} -mtune=${newcpu}
131 vapier 1.37 done
132     return 0
133     }
134    
135 danarmak 1.7 is-flag() {
136 vapier 1.18 for x in ${CFLAGS} ${CXXFLAGS} ; do
137     if [ "${x}" == "$1" ] ; then
138 azarah 1.8 echo true
139 vapier 1.18 return 0
140     fi
141 danarmak 1.7 done
142 vapier 1.18 return 1
143 verwilst 1.1 }
144 azarah 1.8
145 vapier 1.36 filter-mfpmath() {
146     # save the original -mfpmath flag
147     local orig_mfpmath="`get-flag -mfpmath`"
148     # get the value of the current -mfpmath flag
149     local new_math=" `get-flag mfpmath | tr , ' '` "
150     # figure out which math values are to be removed
151     local prune_math=""
152     for prune_math in "$@" ; do
153     new_math="${new_math/ ${prune_math} / }"
154     done
155     new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`"
156    
157     if [ -z "${new_math}" ] ; then
158     # if we're removing all user specified math values are
159     # slated for removal, then we just filter the flag
160     filter-flags ${orig_mfpmath}
161     else
162     # if we only want to filter some of the user specified
163     # math values, then we replace the current flag
164     replace-flags ${orig_mfpmath} -mfpmath=${new_math}
165     fi
166     return 0
167     }
168    
169 azarah 1.8 strip-flags() {
170 vapier 1.36 setup-allowed-flags
171    
172 azarah 1.8 local NEW_CFLAGS=""
173     local NEW_CXXFLAGS=""
174    
175 azarah 1.17 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
176 vapier 1.20 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then
177     [ `use debug` ] && einfo "Enabling the use of some unstable flags"
178 azarah 1.17 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
179     fi
180    
181 azarah 1.8 set -f
182    
183     for x in ${CFLAGS}
184     do
185     for y in ${ALLOWED_FLAGS}
186     do
187 lostlogic 1.14 flag=${x%%=*}
188     if [ "${flag%%${y}}" = "" ]
189 azarah 1.8 then
190 lostlogic 1.14 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
191     break
192 azarah 1.8 fi
193     done
194     done
195    
196     for x in ${CXXFLAGS}
197     do
198     for y in ${ALLOWED_FLAGS}
199     do
200 lostlogic 1.14 flag=${x%%=*}
201     if [ "${flag%%${y}}" = "" ]
202 azarah 1.8 then
203 lostlogic 1.14 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
204     break
205 azarah 1.8 fi
206     done
207     done
208 azarah 1.30
209     # In case we filtered out all optimization flags fallback to -O2
210     if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
211     NEW_CFLAGS="${NEW_CFLAGS} -O2"
212     fi
213     if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
214     NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
215     fi
216 azarah 1.8
217     set +f
218    
219 vapier 1.20 [ `use debug` ] \
220     && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
221     && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
222    
223 azarah 1.8 export CFLAGS="${NEW_CFLAGS}"
224     export CXXFLAGS="${NEW_CXXFLAGS}"
225 vapier 1.36 return 0
226 puggy 1.29 }
227    
228 vapier 1.36 test_flag() {
229     if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then
230     echo "$@"
231     return 0
232 puggy 1.29 fi
233 vapier 1.36 return 1
234 puggy 1.29 }
235    
236     strip-unsupported-flags() {
237 vapier 1.36 for x in ${CFLAGS} ; do
238 puggy 1.29 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`"
239     done
240 vapier 1.36 for x in ${CXXFLAGS} ; do
241 puggy 1.29 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`"
242     done
243    
244 vapier 1.36 export CFLAGS="${NEW_CFLAGS}"
245     export CXXFLAGS="${NEW_CXXFLAGS}"
246 azarah 1.8 }
247    
248 vapier 1.10 get-flag() {
249 vapier 1.36 # this code looks a little flaky but seems to work for
250     # everything we want ...
251     # for example, if CFLAGS="-march=i686":
252     # `get-flags -march` == "-march=i686"
253     # `get-flags march` == "i686"
254 vapier 1.10 local findflag="$1"
255     for f in ${CFLAGS} ${CXXFLAGS} ; do
256     if [ "${f/${findflag}}" != "${f}" ] ; then
257     echo "${f/-${findflag}=}"
258 vapier 1.28 return 0
259 vapier 1.10 fi
260     done
261 vapier 1.28 return 1
262 joker 1.16 }
263    
264 vapier 1.18 replace-sparc64-flags() {
265 joker 1.16 local SPARC64_CPUS="ultrasparc v9"
266    
267     if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
268     then
269     for x in ${SPARC64_CPUS}
270     do
271     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
272     done
273     else
274     for x in ${SPARC64_CPUS}
275     do
276     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
277     done
278     fi
279    
280     if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]
281     then
282     for x in ${SPARC64_CPUS}
283     do
284     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
285     done
286     else
287     for x in ${SPARC64_CPUS}
288     do
289     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
290     done
291     fi
292 solar 1.27 }
293    
294     append-ldflags() {
295     LDFLAGS="${LDFLAGS} $@"
296 vapier 1.28 return 0
297 solar 1.27 }
298    
299 vapier 1.36 etexec-flags() {
300 solar 1.35 has_version sys-devel/hardened-gcc
301 vapier 1.36 if [ $? == 0 ] ; then
302 solar 1.35 if [ "`is-flag -yet_exec`" != "true" ]; then
303 vapier 1.36 debug-print ">>> appending flags -yet_exec"
304 solar 1.34 append-flags -yet_exec
305     append-ldflags -yet_exec
306     fi
307 solar 1.35 fi
308 solar 1.27 }
309    
310     fstack-flags() {
311 solar 1.35 has_version sys-devel/hardened-gcc
312 vapier 1.36 if [ $? == 0 ] ; then
313 solar 1.35 if [ "`is-flag -yno_propolice`" != "true" ]; then
314 solar 1.34 debug-print ">>> appending flags -yno_propolice"
315     append-flags -yno_propolice
316     append-ldflags -yno_propolice
317     fi
318 solar 1.35 fi
319 vapier 1.10 }

  ViewVC Help
Powered by ViewVC 1.1.20