/[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.48 - (hide annotations) (download)
Thu May 6 02:36:37 2004 UTC (10 years, 5 months ago) by vapier
Branch: MAIN
Changes since 1.47: +5 -1 lines
append-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.48 # $Header: /home/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.47 2004/04/12 02:33:29 swtaylor 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 solar 1.41 #### filter-ldflags <flags> ####
53     # Remove particular flags from LDFLAGS
54     # Matches only complete flags
55     #
56 solar 1.27 #### etexec-flags ####
57     # hooked function for hardened-gcc that appends
58     # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed
59 solar 1.32 # and a package is filtering -fPIC,-fpic, -fPIE, -fpie
60 solar 1.27 #
61     #### fstack-flags ####
62     # hooked function for hardened-gcc that appends
63     # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed
64 solar 1.32 # and a package is filtering -fstack-protector, -fstack-protector-all
65 solar 1.27 #
66 verwilst 1.3
67 azarah 1.17 # C[XX]FLAGS that we allow in strip-flags
68 vapier 1.36 setup-allowed-flags() {
69 vapier 1.44 if [ -z "${ALLOWED_FLAGS}" ] ; then
70     export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
71     case "${ARCH}" in
72     mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
73     amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
74     alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
75     ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
76     esac
77     fi
78 vapier 1.36
79     # C[XX]FLAGS that we are think is ok, but needs testing
80     # NOTE: currently -Os have issues with gcc3 and K6* arch's
81     export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
82     return 0
83 aliz 1.24 }
84 verwilst 1.13
85 vapier 1.18 filter-flags() {
86 vapier 1.36 for x in "$@" ; do
87 solar 1.27 case "${x}" in
88 solar 1.39 -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;;
89 solar 1.32 -fstack-protector|-fstack-protector-all) fstack-flags;;
90 solar 1.27 *) ;;
91     esac
92     done
93 vapier 1.36
94 vapier 1.18 # we do this fancy spacing stuff so as to not filter
95     # out part of a flag ... we want flag atoms ! :D
96 agriffis 1.25 CFLAGS=" ${CFLAGS} "
97     CXXFLAGS=" ${CXXFLAGS} "
98 vapier 1.36 for x in "$@" ; do
99 vapier 1.37 CFLAGS="${CFLAGS// ${x} / }"
100     CXXFLAGS="${CXXFLAGS// ${x} / }"
101 verwilst 1.1 done
102 agriffis 1.25 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
103     CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
104 vapier 1.36 return 0
105 verwilst 1.2 }
106    
107 vapier 1.40 filter-lfs-flags() {
108     filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
109     }
110    
111 vapier 1.48 append-lfs-flags() {
112     append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
113     }
114    
115 vapier 1.18 append-flags() {
116 vapier 1.36 export CFLAGS="${CFLAGS} $@"
117     export CXXFLAGS="${CXXFLAGS} $@"
118 vapier 1.33 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags
119 vapier 1.28 return 0
120 verwilst 1.1 }
121    
122 vapier 1.18 replace-flags() {
123 vapier 1.36 # we do this fancy spacing stuff so as to not filter
124     # out part of a flag ... we want flag atoms ! :D
125     CFLAGS=" ${CFLAGS} "
126     CXXFLAGS=" ${CXXFLAGS} "
127 vapier 1.37 CFLAGS="${CFLAGS// ${1} / ${2} }"
128     CXXFLAGS="${CXXFLAGS// ${1} / ${2} }"
129 vapier 1.36 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
130     CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
131 vapier 1.28 return 0
132 danarmak 1.7 }
133    
134 vapier 1.37 replace-cpu-flags() {
135     local newcpu="$1" ; shift
136     local oldcpu=""
137     for oldcpu in "$@" ; do
138     replace-flags -march=${oldcpu} -march=${newcpu}
139     replace-flags -mcpu=${oldcpu} -mcpu=${newcpu}
140 vapier 1.38 replace-flags -mtune=${oldcpu} -mtune=${newcpu}
141 vapier 1.37 done
142     return 0
143     }
144    
145 danarmak 1.7 is-flag() {
146 vapier 1.18 for x in ${CFLAGS} ${CXXFLAGS} ; do
147     if [ "${x}" == "$1" ] ; then
148 azarah 1.8 echo true
149 vapier 1.18 return 0
150     fi
151 danarmak 1.7 done
152 vapier 1.18 return 1
153 verwilst 1.1 }
154 azarah 1.8
155 vapier 1.36 filter-mfpmath() {
156     # save the original -mfpmath flag
157     local orig_mfpmath="`get-flag -mfpmath`"
158     # get the value of the current -mfpmath flag
159     local new_math=" `get-flag mfpmath | tr , ' '` "
160     # figure out which math values are to be removed
161     local prune_math=""
162     for prune_math in "$@" ; do
163     new_math="${new_math/ ${prune_math} / }"
164     done
165     new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`"
166    
167     if [ -z "${new_math}" ] ; then
168     # if we're removing all user specified math values are
169     # slated for removal, then we just filter the flag
170     filter-flags ${orig_mfpmath}
171     else
172     # if we only want to filter some of the user specified
173     # math values, then we replace the current flag
174     replace-flags ${orig_mfpmath} -mfpmath=${new_math}
175     fi
176     return 0
177     }
178    
179 azarah 1.8 strip-flags() {
180 vapier 1.36 setup-allowed-flags
181    
182 azarah 1.8 local NEW_CFLAGS=""
183     local NEW_CXXFLAGS=""
184    
185 azarah 1.17 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
186 vapier 1.20 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then
187     [ `use debug` ] && einfo "Enabling the use of some unstable flags"
188 azarah 1.17 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
189     fi
190    
191 azarah 1.8 set -f
192    
193     for x in ${CFLAGS}
194     do
195     for y in ${ALLOWED_FLAGS}
196     do
197 lostlogic 1.14 flag=${x%%=*}
198     if [ "${flag%%${y}}" = "" ]
199 azarah 1.8 then
200 lostlogic 1.14 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
201     break
202 azarah 1.8 fi
203     done
204     done
205    
206     for x in ${CXXFLAGS}
207     do
208     for y in ${ALLOWED_FLAGS}
209     do
210 lostlogic 1.14 flag=${x%%=*}
211     if [ "${flag%%${y}}" = "" ]
212 azarah 1.8 then
213 lostlogic 1.14 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
214     break
215 azarah 1.8 fi
216     done
217     done
218 azarah 1.30
219     # In case we filtered out all optimization flags fallback to -O2
220     if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
221     NEW_CFLAGS="${NEW_CFLAGS} -O2"
222     fi
223     if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
224     NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
225     fi
226 azarah 1.8
227     set +f
228    
229 vapier 1.20 [ `use debug` ] \
230     && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
231     && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
232    
233 azarah 1.8 export CFLAGS="${NEW_CFLAGS}"
234     export CXXFLAGS="${NEW_CXXFLAGS}"
235 vapier 1.36 return 0
236 puggy 1.29 }
237    
238 vapier 1.36 test_flag() {
239 swtaylor 1.47 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then
240 vapier 1.36 echo "$@"
241     return 0
242 puggy 1.29 fi
243 vapier 1.36 return 1
244 puggy 1.29 }
245    
246     strip-unsupported-flags() {
247 vapier 1.36 for x in ${CFLAGS} ; do
248 puggy 1.29 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`"
249     done
250 vapier 1.36 for x in ${CXXFLAGS} ; do
251 puggy 1.29 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`"
252     done
253    
254 vapier 1.36 export CFLAGS="${NEW_CFLAGS}"
255     export CXXFLAGS="${NEW_CXXFLAGS}"
256 azarah 1.8 }
257    
258 vapier 1.10 get-flag() {
259 vapier 1.36 # this code looks a little flaky but seems to work for
260     # everything we want ...
261     # for example, if CFLAGS="-march=i686":
262     # `get-flags -march` == "-march=i686"
263     # `get-flags march` == "i686"
264 vapier 1.10 local findflag="$1"
265     for f in ${CFLAGS} ${CXXFLAGS} ; do
266     if [ "${f/${findflag}}" != "${f}" ] ; then
267     echo "${f/-${findflag}=}"
268 vapier 1.28 return 0
269 vapier 1.10 fi
270     done
271 vapier 1.28 return 1
272 joker 1.16 }
273    
274 tseng 1.42 has_pic() {
275     [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
276     [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
277 tseng 1.45 has_version sys-devel/hardened-gcc && return 0
278 tseng 1.42 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
279     return 1
280     }
281    
282     has_pie() {
283 tseng 1.43 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
284     [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
285 tseng 1.45 has_version sys-devel/hardened-gcc && return 0
286 tseng 1.42 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
287     return 1
288     }
289    
290     has_ssp() {
291     [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
292 tseng 1.45 has_version sys-devel/hardened-gcc && return 0
293 tseng 1.42 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0
294     return 1
295     }
296    
297 vapier 1.18 replace-sparc64-flags() {
298 joker 1.16 local SPARC64_CPUS="ultrasparc v9"
299    
300     if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
301     then
302     for x in ${SPARC64_CPUS}
303     do
304     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
305     done
306     else
307     for x in ${SPARC64_CPUS}
308     do
309     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
310     done
311     fi
312    
313     if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]
314     then
315     for x in ${SPARC64_CPUS}
316     do
317     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
318     done
319     else
320     for x in ${SPARC64_CPUS}
321     do
322     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
323     done
324     fi
325 solar 1.27 }
326    
327     append-ldflags() {
328     LDFLAGS="${LDFLAGS} $@"
329 vapier 1.28 return 0
330 solar 1.27 }
331    
332 solar 1.41 filter-ldflags() {
333     # we do this fancy spacing stuff so as to not filter
334     # out part of a flag ... we want flag atoms ! :D
335     LDFLAGS=" ${LDFLAGS} "
336     for x in "$@" ; do
337     LDFLAGS="${LDFLAGS// ${x} / }"
338     done
339     LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
340     return 0
341     }
342    
343 vapier 1.36 etexec-flags() {
344 tseng 1.42 has_pie || has_pic
345 vapier 1.36 if [ $? == 0 ] ; then
346 swtaylor 1.47 [ -z "`is-flag -yet_exec`" ] &&
347 swtaylor 1.46 export CFLAGS="${CFLAGS} `test_flag -yet_exec`"
348 swtaylor 1.47 [ -z "`is-flag -nopie`" ] &&
349     export CFLAGS="${CFLAGS} `test_flag -nopie`"
350 solar 1.35 fi
351 solar 1.27 }
352    
353     fstack-flags() {
354 tseng 1.42 has_ssp
355 vapier 1.36 if [ $? == 0 ] ; then
356 swtaylor 1.47 [ -z "`is-flag -yno_propolice`" ] &&
357 swtaylor 1.46 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
358 solar 1.35 fi
359 vapier 1.10 }

  ViewVC Help
Powered by ViewVC 1.1.20