/[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.28 - (hide annotations) (download)
Sun Oct 26 00:40:52 2003 UTC (10 years, 8 months ago) by vapier
Branch: MAIN
Changes since 1.27: +7 -5 lines
fix return values

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.28 # $Header: /home/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.27 2003/09/24 05:51:32 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 danarmak 1.7 #### is-flag <flag> ####
22     # Returns "true" if flag is set in C[XX]FLAGS
23 vapier 1.18 # Matches only complete a flag
24 danarmak 1.7 #
25 azarah 1.8 #### strip-flags ####
26     # Strip C[XX]FLAGS of everything except known
27     # good options.
28     #
29 vapier 1.10 #### get-flag <flag> ####
30     # Find and echo the value for a particular flag
31     #
32 joker 1.16 #### replace-sparc64-flags ####
33     # Sets mcpu to v8 and uses the original value
34     # as mtune if none specified.
35     #
36 vapier 1.26 #### filter-mfpmath <math types> ####
37     # Remove specified math types from the fpmath specification
38     # If the user has -mfpmath=sse,386, running `filter-mfpmath sse`
39     # will leave the user with -mfpmath=386
40 solar 1.27 #
41     #### append-ldflags ####
42     # Add extra flags to your current LDFLAGS
43     #
44     #### etexec-flags ####
45     # hooked function for hardened-gcc that appends
46     # -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed
47     # and a package is filtering -fPIC
48     #
49     #### fstack-flags ####
50     # hooked function for hardened-gcc that appends
51     # -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed
52     # and a package is filtering -fstack-protector
53     #
54 verwilst 1.3
55 azarah 1.17 # C[XX]FLAGS that we allow in strip-flags
56 vapier 1.22 ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
57     case "${ARCH}" in
58     mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
59 tester 1.23 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
60 agriffis 1.25 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
61 vapier 1.22 esac
62 verwilst 1.13
63 azarah 1.17 # C[XX]FLAGS that we are think is ok, but needs testing
64     # NOTE: currently -Os have issues with gcc3 and K6* arch's
65     UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
66 aliz 1.24
67     filter-mfpmath() {
68     for a in $CFLAGS; do
69     if [ "${a:0:8}" == "-mfpmath" ]; then
70     orig_mfpmath=$a
71     fi
72     done
73    
74     mfpmath="$( echo $orig_mfpmath | awk -F '=' '{print $2}' | tr "," " " )"
75     for b in $@; do
76     mfpmath="${mfpmath/$b}"
77     done
78    
79     if [ -z "${mfpmath/ }" ]; then
80     filter-flags "$orig_mfpmath"
81     else
82     new_mfpmath="-mfpmath=$( echo $mfpmath | sed -e "s/ /,/g" -e "s/,,/,/g" )"
83     replace-flags "$orig_mfpmath" "$new_mfpmath"
84     fi
85     }
86 verwilst 1.13
87 vapier 1.18 filter-flags() {
88 solar 1.27 # we do two loops to avoid the first and last char from being chomped.
89     for x in $@ ; do
90     case "${x}" in
91     -fPIC) etexec-flags;;
92     -fstack-protector) fstack-flags;;
93     *) ;;
94     esac
95     done
96 vapier 1.18 # we do this fancy spacing stuff so as to not filter
97     # out part of a flag ... we want flag atoms ! :D
98 agriffis 1.25 CFLAGS=" ${CFLAGS} "
99     CXXFLAGS=" ${CXXFLAGS} "
100 vapier 1.18 for x in $@ ; do
101 agriffis 1.25 CFLAGS="${CFLAGS/ ${x} / }"
102     CXXFLAGS="${CXXFLAGS/ ${x} / }"
103 verwilst 1.1 done
104 agriffis 1.25 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
105     CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
106 verwilst 1.2 }
107    
108 vapier 1.18 append-flags() {
109 vapier 1.19 CFLAGS="${CFLAGS} $@"
110     CXXFLAGS="${CXXFLAGS} $@"
111 solar 1.27 for x in $@; do
112 vapier 1.28 [ "${x}" = "-fno-stack-protector" ] && fstack-flags
113 solar 1.27 done
114 vapier 1.28 return 0
115 verwilst 1.1 }
116    
117 vapier 1.18 replace-flags() {
118 seemant 1.9 CFLAGS="${CFLAGS/${1}/${2} }"
119     CXXFLAGS="${CXXFLAGS/${1}/${2} }"
120 vapier 1.28 return 0
121 danarmak 1.7 }
122    
123     is-flag() {
124 vapier 1.18 for x in ${CFLAGS} ${CXXFLAGS} ; do
125     if [ "${x}" == "$1" ] ; then
126 azarah 1.8 echo true
127 vapier 1.18 return 0
128     fi
129 danarmak 1.7 done
130 vapier 1.18 return 1
131 verwilst 1.1 }
132 azarah 1.8
133     strip-flags() {
134     local NEW_CFLAGS=""
135     local NEW_CXXFLAGS=""
136    
137 azarah 1.17 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
138 vapier 1.20 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then
139     [ `use debug` ] && einfo "Enabling the use of some unstable flags"
140 azarah 1.17 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
141     fi
142    
143 azarah 1.8 set -f
144    
145     for x in ${CFLAGS}
146     do
147     for y in ${ALLOWED_FLAGS}
148     do
149 lostlogic 1.14 flag=${x%%=*}
150     if [ "${flag%%${y}}" = "" ]
151 azarah 1.8 then
152 lostlogic 1.14 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
153     break
154 azarah 1.8 fi
155     done
156     done
157    
158     for x in ${CXXFLAGS}
159     do
160     for y in ${ALLOWED_FLAGS}
161     do
162 lostlogic 1.14 flag=${x%%=*}
163     if [ "${flag%%${y}}" = "" ]
164 azarah 1.8 then
165 lostlogic 1.14 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
166     break
167 azarah 1.8 fi
168     done
169     done
170    
171     set +f
172    
173 vapier 1.20 [ `use debug` ] \
174     && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
175     && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
176    
177 azarah 1.8 export CFLAGS="${NEW_CFLAGS}"
178     export CXXFLAGS="${NEW_CXXFLAGS}"
179     }
180    
181 vapier 1.10 get-flag() {
182     local findflag="$1"
183     for f in ${CFLAGS} ${CXXFLAGS} ; do
184     if [ "${f/${findflag}}" != "${f}" ] ; then
185     echo "${f/-${findflag}=}"
186 vapier 1.28 return 0
187 vapier 1.10 fi
188     done
189 vapier 1.28 return 1
190 joker 1.16 }
191    
192 vapier 1.18 replace-sparc64-flags() {
193 joker 1.16 local SPARC64_CPUS="ultrasparc v9"
194    
195     if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
196     then
197     for x in ${SPARC64_CPUS}
198     do
199     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}"
200     done
201     else
202     for x in ${SPARC64_CPUS}
203     do
204     CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
205     done
206     fi
207    
208     if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]
209     then
210     for x in ${SPARC64_CPUS}
211     do
212     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}"
213     done
214     else
215     for x in ${SPARC64_CPUS}
216     do
217     CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}"
218     done
219     fi
220 solar 1.27 }
221    
222     append-ldflags() {
223     LDFLAGS="${LDFLAGS} $@"
224 vapier 1.28 return 0
225 solar 1.27 }
226    
227     etexec-flags() {
228     has_version 'sys-devel/hardened-gcc' && {
229     debug-print ">>> appending flags -yet_exec"
230     append-flags -yet_exec
231     append-ldflags -yet_exec
232     }
233     }
234    
235     fstack-flags() {
236     has_version 'sys-devel/hardened-gcc' && {
237     debug-print ">>> appending flags -yno_propolice"
238     append-flags -yno_propolice
239     append-ldflags -yno_propolice
240     }
241 vapier 1.10 }

  ViewVC Help
Powered by ViewVC 1.1.20