/[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.64 Revision 1.79
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 Gentoo Foundation
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.64 2004/07/22 15:29:10 agriffis Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.79 2004/12/25 18:45:56 chriswhite 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"
9 9
10# Please leave ${IUSE} in this until portage .51 is stable, otherwise
11# IUSE gets clobbered.
12IUSE="${IUSE} debug" 10IUSE="debug"
11
12# need access to emktemp()
13inherit eutils toolchain-funcs
13 14
14# 15#
15#### filter-flags <flags> #### 16#### filter-flags <flags> ####
16# Remove particular flags from C[XX]FLAGS 17# Remove particular flags from C[XX]FLAGS
17# Matches only complete flags 18# Matches only complete flags
20# Add extra flags to your current C[XX]FLAGS 21# Add extra flags to your current C[XX]FLAGS
21# 22#
22#### replace-flags <orig.flag> <new.flag> ### 23#### replace-flags <orig.flag> <new.flag> ###
23# Replace a flag by another one 24# Replace a flag by another one
24# 25#
25#### replace-cpu-flags <new.cpu> <old.cpus> ### 26#### replace-cpu-flags <old.cpus> <new.cpu> ###
26# Replace march/mcpu flags that specify <old.cpus> 27# Replace march/mcpu flags that specify <old.cpus>
27# with flags that specify <new.cpu> 28# with flags that specify <new.cpu>
28# 29#
29#### is-flag <flag> #### 30#### is-flag <flag> ####
30# Returns "true" if flag is set in C[XX]FLAGS 31# Returns "true" if flag is set in C[XX]FLAGS
71# 72#
72 73
73# C[XX]FLAGS that we allow in strip-flags 74# C[XX]FLAGS that we allow in strip-flags
74setup-allowed-flags() { 75setup-allowed-flags() {
75 if [ -z "${ALLOWED_FLAGS}" ] ; then 76 if [ -z "${ALLOWED_FLAGS}" ] ; then
76 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-unit-at-a-time -pipe -g" 77 export ALLOWED_FLAGS="-pipe"
78 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune"
79 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fno-stack-protector"
80 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-pie -fno-unit-at-a-time"
81 export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g0 -g1 -g2 -g3 -ggdb -ggdb0 -ggdb1 -ggdb2 -ggdb3"
77 case "${ARCH}" in 82 case "${ARCH}" in
78 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 83 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -EL -EB -mabi" ;;
79 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;; 84 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
80 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;; 85 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
81 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 86 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
82 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 87 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
88 sparc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32 -m64" ;;
89 ppc) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mabi" ;;
83 esac 90 esac
84 fi 91 fi
92 # allow a bunch of flags that negate features / control ABI
93 ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all"
94 case "${ARCH}" in
95 x86|amd64|ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow" ;;
96 esac
97 ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs -msoft-float -mflat -mno-faster-structs -mfaster-structs -mlittle-endian -mbig-endian -mlive-g0 -mcmodel -mno-stack-bias -mstack-bias"
85 98
86 # C[XX]FLAGS that we are think is ok, but needs testing 99 # C[XX]FLAGS that we are think is ok, but needs testing
87 # NOTE: currently -Os have issues with gcc3 and K6* arch's 100 # NOTE: currently -Os have issues with gcc3 and K6* arch's
88 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 101 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
89 return 0 102 return 0
153 166
154 return 0 167 return 0
155} 168}
156 169
157replace-cpu-flags() { 170replace-cpu-flags() {
158 local oldcpu newcpu="$1" ; shift 171 local newcpu="$#" ; newcpu="${!newcpu}"
159 for oldcpu in "$@" ; do 172 while [ $# -gt 1 ] ; do
160 # quote to make sure that no globbing is done (particularly on 173 # quote to make sure that no globbing is done (particularly on
161 # ${oldcpu} prior to calling replace-flags 174 # ${oldcpu} prior to calling replace-flags
162 replace-flags "-march=${oldcpu}" "-march=${newcpu}" 175 replace-flags "-march=${1}" "-march=${newcpu}"
163 replace-flags "-mcpu=${oldcpu}" "-mcpu=${newcpu}" 176 replace-flags "-mcpu=${1}" "-mcpu=${newcpu}"
164 replace-flags "-mtune=${oldcpu}" "-mtune=${newcpu}" 177 replace-flags "-mtune=${1}" "-mtune=${newcpu}"
178 shift
165 done 179 done
166 return 0 180 return 0
167} 181}
168 182
169is-flag() { 183is-flag() {
170 local x 184 local x
171 185
172 for x in ${CFLAGS} ${CXXFLAGS} ; do 186 for x in ${CFLAGS} ${CXXFLAGS} ; do
187 # Note this should work with globs like -mcpu=ultrasparc*
173 if [ "${x}" == "$1" ] ; then 188 if [[ ${x} == ${1} ]]; then
174 echo true 189 echo true
175 return 0 190 return 0
176 fi 191 fi
177 done 192 done
178 return 1 193 return 1
221 set -f # disable pathname expansion 236 set -f # disable pathname expansion
222 237
223 for x in ${CFLAGS}; do 238 for x in ${CFLAGS}; do
224 for y in ${ALLOWED_FLAGS}; do 239 for y in ${ALLOWED_FLAGS}; do
225 flag=${x%%=*} 240 flag=${x%%=*}
226 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then 241 if [ "${flag%%${y}}" = "" ] ; then
227 NEW_CFLAGS="${NEW_CFLAGS} ${x}" 242 NEW_CFLAGS="${NEW_CFLAGS} ${x}"
228 break 243 break
229 fi 244 fi
230 done 245 done
231 done 246 done
232 247
233 for x in ${CXXFLAGS}; do 248 for x in ${CXXFLAGS}; do
234 for y in ${ALLOWED_FLAGS}; do 249 for y in ${ALLOWED_FLAGS}; do
235 flag=${x%%=*} 250 flag=${x%%=*}
236 if [ "${flag%%${y}}" = "" ] || [ "${flag:0:5}" = "-fno-" ] || [ "${flag:0:5}" = "-mno-" ] ; then 251 if [ "${flag%%${y}}" = "" ] ; then
237 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}" 252 NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}"
238 break 253 break
239 fi 254 fi
240 done 255 done
241 done 256 done
254 export CXXFLAGS="${NEW_CXXFLAGS}" 269 export CXXFLAGS="${NEW_CXXFLAGS}"
255 return 0 270 return 0
256} 271}
257 272
258test_flag() { 273test_flag() {
259 local cc=${CC:-gcc} ; cc=${cc%% *} 274 if $(tc-getCC) -S -xc "$@" -o "$(emktemp)" /dev/null &>/dev/null; then
260 if ${cc} -S -xc "$@" -o /dev/null /dev/null &>/dev/null; then
261 printf "%s\n" "$*" 275 printf "%s\n" "$*"
262 return 0 276 return 0
263 fi 277 fi
264 return 1 278 return 1
265} 279}
266 280
267test_version_info() { 281test_version_info() {
268 local cc=${CC:-gcc} ; cc=${cc%% *}
269 if [[ $(${cc} --version 2>&1) == *$1* ]]; then 282 if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
270 return 0 283 return 0
271 else 284 else
272 return 1 285 return 1
273 fi 286 fi
274} 287}
303 done 316 done
304 return 1 317 return 1
305} 318}
306 319
307has_hardened() { 320has_hardened() {
308 test_version_info Hardened 321 test_version_info Hardened && return 0
322 # the specs file wont exist unless gcc has GCC_SPECS support
323 [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \
324 return 0
309 return $? 325 return 1
310} 326}
311 327
312has_pic() { 328has_pic() {
313 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 329 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
314 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 330 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
332has_m64() { 348has_m64() {
333 # this doesnt test if the flag is accepted, it tests if the flag 349 # this doesnt test if the flag is accepted, it tests if the flag
334 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 350 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
335 # please dont replace this function with test_flag in some future 351 # please dont replace this function with test_flag in some future
336 # clean-up! 352 # clean-up!
337 temp=`mktemp` 353 local temp="$(emktemp)"
338 echo "int main() { return(0); }" > ${temp}.c 354 echo "int main() { return(0); }" > ${temp}.c
339 ${CC/ .*/} -m64 -o /dev/null ${temp}.c > /dev/null 2>&1 355 MY_CC=$(tc-getCC)
340 ret=$? 356 ${MY_CC/ .*/} -m64 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
357 local ret=$?
341 rm -f ${temp}.c 358 rm -f ${temp}.c
342 [ "$ret" != "1" ] && return 0 359 [ "$ret" != "1" ] && return 0
343 return 1 360 return 1
344} 361}
345 362
346has_m32() { 363has_m32() {
347 # this doesnt test if the flag is accepted, it tests if the flag 364 # this doesnt test if the flag is accepted, it tests if the flag
348 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64! 365 # actually -WORKS-. non-multilib gcc will take both -m32 and -m64!
349 # please dont replace this function with test_flag in some future 366 # please dont replace this function with test_flag in some future
350 # clean-up! 367 # clean-up!
351 temp=`mktemp` 368 local temp="$(emktemp)"
352 echo "int main() { return(0); }" > ${temp}.c 369 echo "int main() { return(0); }" > ${temp}.c
353 ${CC/ .*/} -m32 -o /dev/null ${temp}.c > /dev/null 2>&1 370 MY_CC=$(tc-getCC)
354 ret=$? 371 ${MY_CC/ .*/} -m32 -o "$(emktemp)" ${temp}.c > /dev/null 2>&1
372 local ret=$?
355 rm -f ${temp}.c 373 rm -f ${temp}.c
356 [ "$ret" != "1" ] && return 0 374 [ "$ret" != "1" ] && return 0
357 return 1 375 return 1
358} 376}
359 377
404 422
405etexec-flags() { 423etexec-flags() {
406 # if you're not using a hardened compiler you wont need this 424 # if you're not using a hardened compiler you wont need this
407 # PIC/no-pic kludge in the first place. 425 # PIC/no-pic kludge in the first place.
408 has_hardened || return 0 426 has_hardened || return 0
427 use amd64 && return 0
428 use mips && return 0
409 429
410 if has_pie || has_pic; then 430 if has_pie || has_pic; then
411 [ -z "`is-flag -fno-pic`" ] && 431 [ -z "`is-flag -fno-pic`" ] &&
412 export CFLAGS="${CFLAGS} `test_flag -fno-pic`" 432 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
413 [ -z "`is-flag -nopie`" ] && 433 [ -z "`is-flag -nopie`" ] &&
421 [ -z "`is-flag -fno-stack-protector`" ] && 441 [ -z "`is-flag -fno-stack-protector`" ] &&
422 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" 442 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
423 fi 443 fi
424 return 0 444 return 0
425} 445}
446
447# This is thanks to great work from Paul de Vrieze <gentoo-user@devrieze.net>,
448# bug #9016. Also thanks to Jukka Salmi <salmi@gmx.net> (bug #13907) for more
449# fixes.
450#
451# Export CFLAGS and CXXFLAGS that are compadible with gcc-2.95.3
452gcc2-flags() {
453 CFLAGS=${CFLAGS//pentium-mmx/i586}
454 CFLAGS=${CFLAGS//pentium[234]/i686}
455 CFLAGS=${CFLAGS//k6-[23]/k6}
456 CFLAGS=${CFLAGS//athlon-tbird/i686}
457 CFLAGS=${CFLAGS//athlon-4/i686}
458 CFLAGS=${CFLAGS//athlon-[xm]p/i686}
459 CFLAGS=${CFLAGS//athlon/i686}
460
461 CXXFLAGS=${CXXFLAGS//pentium-mmx/i586}
462 CXXFLAGS=${CXXFLAGS//pentium[234]/i686}
463 CXXFLAGS=${CXXFLAGS//k6-[23]/k6}
464 CXXFLAGS=${CXXFLAGS//athlon-tbird/i686}
465 CXXFLAGS=${CXXFLAGS//athlon-4/i686}
466 CXXFLAGS=${CXXFLAGS//athlon-[xm]p/i686}
467 CXXFLAGS=${CXXFLAGS//athlon/i686}
468
469 if [ "$ARCH" = alpha ]; then
470 CHOST=${CHOST/#alphaev6[78]/alphaev6}
471 CFLAGS=${CFLAGS//ev6[78]/ev6}
472 CXXFLAGS=${CXXFLAGS//ev6[78]/ev6}
473 fi
474
475 export CFLAGS CXXFLAGS
476}

Legend:
Removed from v.1.64  
changed lines
  Added in v.1.79

  ViewVC Help
Powered by ViewVC 1.1.20