/[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.35 Revision 1.36
1# Copyright 1999-2003 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.35 2004/01/20 10:37:19 solar Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.36 2004/02/21 07:07:56 vapier Exp $
4# 4#
5# Author Bart Verwilst <verwilst@gentoo.org> 5# Author Bart Verwilst <verwilst@gentoo.org>
6 6
7ECLASS=flag-o-matic 7ECLASS=flag-o-matic
8INHERITED="$INHERITED $ECLASS" 8INHERITED="$INHERITED $ECLASS"
55# -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed 55# -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed
56# and a package is filtering -fstack-protector, -fstack-protector-all 56# and a package is filtering -fstack-protector, -fstack-protector-all
57# 57#
58 58
59# C[XX]FLAGS that we allow in strip-flags 59# C[XX]FLAGS that we allow in strip-flags
60setup-allowed-flags() {
60ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" 61 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
61case "${ARCH}" in 62 case "${ARCH}" in
62 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 63 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
63 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 64 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
64 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 65 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
65 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 66 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
66esac 67 esac
67 68
68# C[XX]FLAGS that we are think is ok, but needs testing 69 # C[XX]FLAGS that we are think is ok, but needs testing
69# NOTE: currently -Os have issues with gcc3 and K6* arch's 70 # NOTE: currently -Os have issues with gcc3 and K6* arch's
70UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 71 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
71 72 return 0
72filter-mfpmath() {
73 for a in $CFLAGS; do
74 if [ "${a:0:8}" == "-mfpmath" ]; then
75 orig_mfpmath=$a
76 fi
77 done
78
79 mfpmath="$( echo $orig_mfpmath | awk -F '=' '{print $2}' | tr "," " " )"
80 for b in $@; do
81 mfpmath="${mfpmath/$b}"
82 done
83
84 if [ -z "${mfpmath/ }" ]; then
85 filter-flags "$orig_mfpmath"
86 else
87 new_mfpmath="-mfpmath=$( echo $mfpmath | sed -e "s/ /,/g" -e "s/,,/,/g" )"
88 replace-flags "$orig_mfpmath" "$new_mfpmath"
89 fi
90} 73}
91 74
92filter-flags() { 75filter-flags() {
93 # we do two loops to avoid the first and last char from being chomped.
94 for x in $@ ; do 76 for x in "$@" ; do
95 case "${x}" in 77 case "${x}" in
96 -fPIC|-fpic|-fPIE|-fpie) etexec-flags;; 78 -fPIC|-fpic|-fPIE|-fpie) etexec-flags;;
97 -fstack-protector|-fstack-protector-all) fstack-flags;; 79 -fstack-protector|-fstack-protector-all) fstack-flags;;
98 *) ;; 80 *) ;;
99 esac 81 esac
100 done 82 done
83
101 # we do this fancy spacing stuff so as to not filter 84 # we do this fancy spacing stuff so as to not filter
102 # out part of a flag ... we want flag atoms ! :D 85 # out part of a flag ... we want flag atoms ! :D
103 CFLAGS=" ${CFLAGS} " 86 CFLAGS=" ${CFLAGS} "
104 CXXFLAGS=" ${CXXFLAGS} " 87 CXXFLAGS=" ${CXXFLAGS} "
105 for x in $@ ; do 88 for x in "$@" ; do
106 CFLAGS="${CFLAGS/ ${x} / }" 89 CFLAGS="${CFLAGS/ ${x} / }"
107 CXXFLAGS="${CXXFLAGS/ ${x} / }" 90 CXXFLAGS="${CXXFLAGS/ ${x} / }"
108 done 91 done
109 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" 92 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
110 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" 93 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
94 return 0
111} 95}
112 96
113append-flags() { 97append-flags() {
114 CFLAGS="${CFLAGS} $@" 98 export CFLAGS="${CFLAGS} $@"
115 CXXFLAGS="${CXXFLAGS} $@" 99 export CXXFLAGS="${CXXFLAGS} $@"
116 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags 100 [ "`is-flag -fno-stack-protector`" -o "`is-flag -fno-stack-protector-all`" ] && fstack-flags
117 return 0 101 return 0
118} 102}
119 103
120replace-flags() { 104replace-flags() {
105 # we do this fancy spacing stuff so as to not filter
106 # out part of a flag ... we want flag atoms ! :D
107 CFLAGS=" ${CFLAGS} "
108 CXXFLAGS=" ${CXXFLAGS} "
121 CFLAGS="${CFLAGS/${1}/${2} }" 109 CFLAGS="${CFLAGS/ ${1} / ${2} }"
122 CXXFLAGS="${CXXFLAGS/${1}/${2} }" 110 CXXFLAGS="${CXXFLAGS/ ${1} / ${2} }"
111 CFLAGS="${CFLAGS:1:${#CFLAGS}-2}"
112 CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}"
123 return 0 113 return 0
124} 114}
125 115
126is-flag() { 116is-flag() {
127 for x in ${CFLAGS} ${CXXFLAGS} ; do 117 for x in ${CFLAGS} ${CXXFLAGS} ; do
131 fi 121 fi
132 done 122 done
133 return 1 123 return 1
134} 124}
135 125
126filter-mfpmath() {
127 # save the original -mfpmath flag
128 local orig_mfpmath="`get-flag -mfpmath`"
129 # get the value of the current -mfpmath flag
130 local new_math=" `get-flag mfpmath | tr , ' '` "
131 # figure out which math values are to be removed
132 local prune_math=""
133 for prune_math in "$@" ; do
134 new_math="${new_math/ ${prune_math} / }"
135 done
136 new_math="`echo ${new_math:1:${#new_math}-2} | tr ' ' ,`"
137
138 if [ -z "${new_math}" ] ; then
139 # if we're removing all user specified math values are
140 # slated for removal, then we just filter the flag
141 filter-flags ${orig_mfpmath}
142 else
143 # if we only want to filter some of the user specified
144 # math values, then we replace the current flag
145 replace-flags ${orig_mfpmath} -mfpmath=${new_math}
146 fi
147 return 0
148}
149
136strip-flags() { 150strip-flags() {
151 setup-allowed-flags
152
137 local NEW_CFLAGS="" 153 local NEW_CFLAGS=""
138 local NEW_CXXFLAGS="" 154 local NEW_CXXFLAGS=""
139 155
140 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 156 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
141 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then 157 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then
185 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ 201 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
186 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" 202 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
187 203
188 export CFLAGS="${NEW_CFLAGS}" 204 export CFLAGS="${NEW_CFLAGS}"
189 export CXXFLAGS="${NEW_CXXFLAGS}" 205 export CXXFLAGS="${NEW_CXXFLAGS}"
206 return 0
190} 207}
191 208
192test_flag () { 209test_flag() {
193 if gcc -S -xc $1 -o /dev/null /dev/null >/dev/null 2>&1; then 210 if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then
194 echo "$1" 211 echo "$@"
212 return 0
195 fi 213 fi
214 return 1
196} 215}
197 216
198strip-unsupported-flags() { 217strip-unsupported-flags() {
199 for x in ${CFLAGS} 218 for x in ${CFLAGS} ; do
200 do
201 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`" 219 NEW_CFLAGS=${NEW_CFLAGS}" ""`test_flag ${x}`"
202 done 220 done
203
204 for x in ${CXXFLAGS} 221 for x in ${CXXFLAGS} ; do
205 do
206 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`" 222 NEW_CXXFLAGS=${NEW_CXXFLAGS}" ""`test_flag ${x}`"
207 done 223 done
208 224
209 CFLAGS="${NEW_CFLAGS}" 225 export CFLAGS="${NEW_CFLAGS}"
210 CXXFLAGS="${NEW_CXXFLAGS}" 226 export CXXFLAGS="${NEW_CXXFLAGS}"
211} 227}
212 228
213get-flag() { 229get-flag() {
230 # this code looks a little flaky but seems to work for
231 # everything we want ...
232 # for example, if CFLAGS="-march=i686":
233 # `get-flags -march` == "-march=i686"
234 # `get-flags march` == "i686"
214 local findflag="$1" 235 local findflag="$1"
215 for f in ${CFLAGS} ${CXXFLAGS} ; do 236 for f in ${CFLAGS} ${CXXFLAGS} ; do
216 if [ "${f/${findflag}}" != "${f}" ] ; then 237 if [ "${f/${findflag}}" != "${f}" ] ; then
217 echo "${f/-${findflag}=}" 238 echo "${f/-${findflag}=}"
218 return 0 239 return 0
254append-ldflags() { 275append-ldflags() {
255 LDFLAGS="${LDFLAGS} $@" 276 LDFLAGS="${LDFLAGS} $@"
256 return 0 277 return 0
257} 278}
258 279
259etexec-flags() { 280etexec-flags() {
260 has_version sys-devel/hardened-gcc 281 has_version sys-devel/hardened-gcc
261 if [ $? == 0 ]; then 282 if [ $? == 0 ] ; then
262 if [ "`is-flag -yet_exec`" != "true" ]; then 283 if [ "`is-flag -yet_exec`" != "true" ]; then
263 debug-print ">>> appending flags -yet_exec" 284 debug-print ">>> appending flags -yet_exec"
264 append-flags -yet_exec 285 append-flags -yet_exec
265 append-ldflags -yet_exec 286 append-ldflags -yet_exec
266 fi 287 fi
267 fi 288 fi
268} 289}
269 290
270fstack-flags() { 291fstack-flags() {
271 has_version sys-devel/hardened-gcc 292 has_version sys-devel/hardened-gcc
272 if [ $? == 0 ]; then 293 if [ $? == 0 ] ; then
273 if [ "`is-flag -yno_propolice`" != "true" ]; then 294 if [ "`is-flag -yno_propolice`" != "true" ]; then
274 debug-print ">>> appending flags -yno_propolice" 295 debug-print ">>> appending flags -yno_propolice"
275 append-flags -yno_propolice 296 append-flags -yno_propolice
276 append-ldflags -yno_propolice 297 append-ldflags -yno_propolice
277 fi 298 fi

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

  ViewVC Help
Powered by ViewVC 1.1.20