/[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.40 Revision 1.45
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.40 2004/03/12 11:21:15 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.45 2004/04/09 22:21:35 tseng 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"
47# will leave the user with -mfpmath=386 47# will leave the user with -mfpmath=386
48# 48#
49#### append-ldflags #### 49#### append-ldflags ####
50# Add extra flags to your current LDFLAGS 50# Add extra flags to your current LDFLAGS
51# 51#
52#### filter-ldflags <flags> ####
53# Remove particular flags from LDFLAGS
54# Matches only complete flags
55#
52#### etexec-flags #### 56#### etexec-flags ####
53# hooked function for hardened-gcc that appends 57# hooked function for hardened-gcc that appends
54# -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed 58# -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed
55# and a package is filtering -fPIC,-fpic, -fPIE, -fpie 59# and a package is filtering -fPIC,-fpic, -fPIE, -fpie
56# 60#
60# and a package is filtering -fstack-protector, -fstack-protector-all 64# and a package is filtering -fstack-protector, -fstack-protector-all
61# 65#
62 66
63# C[XX]FLAGS that we allow in strip-flags 67# C[XX]FLAGS that we allow in strip-flags
64setup-allowed-flags() { 68setup-allowed-flags() {
69 if [ -z "${ALLOWED_FLAGS}" ] ; then
65 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" 70 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g"
66 case "${ARCH}" in 71 case "${ARCH}" in
67 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 72 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
68 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 73 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
69 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 74 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
70 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 75 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
71 esac 76 esac
77 fi
72 78
73 # C[XX]FLAGS that we are think is ok, but needs testing 79 # C[XX]FLAGS that we are think is ok, but needs testing
74 # NOTE: currently -Os have issues with gcc3 and K6* arch's 80 # NOTE: currently -Os have issues with gcc3 and K6* arch's
75 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 81 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
76 return 0 82 return 0
259 fi 265 fi
260 done 266 done
261 return 1 267 return 1
262} 268}
263 269
270has_pic() {
271 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
272 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
273 has_version sys-devel/hardened-gcc && return 0
274 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
275 return 1
276}
277
278has_pie() {
279 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
280 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
281 has_version sys-devel/hardened-gcc && return 0
282 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
283 return 1
284}
285
286has_ssp() {
287 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
288 has_version sys-devel/hardened-gcc && return 0
289 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0
290 return 1
291}
292
264replace-sparc64-flags() { 293replace-sparc64-flags() {
265 local SPARC64_CPUS="ultrasparc v9" 294 local SPARC64_CPUS="ultrasparc v9"
266 295
267 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] 296 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
268 then 297 then
294append-ldflags() { 323append-ldflags() {
295 LDFLAGS="${LDFLAGS} $@" 324 LDFLAGS="${LDFLAGS} $@"
296 return 0 325 return 0
297} 326}
298 327
328filter-ldflags() {
329 # we do this fancy spacing stuff so as to not filter
330 # out part of a flag ... we want flag atoms ! :D
331 LDFLAGS=" ${LDFLAGS} "
332 for x in "$@" ; do
333 LDFLAGS="${LDFLAGS// ${x} / }"
334 done
335 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
336 return 0
337}
338
299etexec-flags() { 339etexec-flags() {
300 has_version sys-devel/hardened-gcc 340 has_pie || has_pic
301 if [ $? == 0 ] ; then 341 if [ $? == 0 ] ; then
342 # strip -fPIC regardless if you've gotten this far
343 strip-flags -fPIC -fpic -fPIE -fpie -pie
302 if [ "`is-flag -yet_exec`" != "true" ]; then 344 if [ "`is-flag -yet_exec`" != "true" ]; then
345 # If our compile support -yet_exec, append it now
346 [ -z "`gcc -yet_exec -S -o /dev/null -xc /dev/null 2>&1`" ] \
303 debug-print ">>> appending flags -yet_exec" 347 && ( debug-print ">>> appending flags -yet_exec" ; \
304 append-flags -yet_exec 348 append-flags -yet_exec ; append-ldflags -yet_exec )
305 append-ldflags -yet_exec
306 fi 349 fi
307 fi 350 fi
308} 351}
309 352
310fstack-flags() { 353fstack-flags() {
311 has_version sys-devel/hardened-gcc 354 has_ssp
312 if [ $? == 0 ] ; then 355 if [ $? == 0 ] ; then
356 # strip -fstack-protector regardless if you've gotten this far
357 strip-flags -fstack-protector -fstack-protector-all
313 if [ "`is-flag -yno_propolice`" != "true" ]; then 358 if [ "`is-flag -yno_propolice`" != "true" ]; then
359 # If our compile support -yno_propolice, append it now
360 [ -z "`gcc -yno_propolice -S -o /dev/null -xc /dev/null 2>&1`" ] \
314 debug-print ">>> appending flags -yno_propolice" 361 && ( debug-print ">>> appending flags -yno_propolice" ; \
315 append-flags -yno_propolice 362 append-flags -yno_propolice ; append-ldflags -yno_propolice )
316 append-ldflags -yno_propolice
317 fi 363 fi
318 fi 364 fi
319} 365}

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20