/[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.47
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.47 2004/04/12 02:33:29 swtaylor 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
224 export CXXFLAGS="${NEW_CXXFLAGS}" 230 export CXXFLAGS="${NEW_CXXFLAGS}"
225 return 0 231 return 0
226} 232}
227 233
228test_flag() { 234test_flag() {
229 if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then 235 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then
230 echo "$@" 236 echo "$@"
231 return 0 237 return 0
232 fi 238 fi
233 return 1 239 return 1
234} 240}
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
302 if [ "`is-flag -yet_exec`" != "true" ]; then 342 [ -z "`is-flag -yet_exec`" ] &&
303 debug-print ">>> appending flags -yet_exec" 343 export CFLAGS="${CFLAGS} `test_flag -yet_exec`"
304 append-flags -yet_exec 344 [ -z "`is-flag -nopie`" ] &&
305 append-ldflags -yet_exec 345 export CFLAGS="${CFLAGS} `test_flag -nopie`"
306 fi
307 fi 346 fi
308} 347}
309 348
310fstack-flags() { 349fstack-flags() {
311 has_version sys-devel/hardened-gcc 350 has_ssp
312 if [ $? == 0 ] ; then 351 if [ $? == 0 ] ; then
313 if [ "`is-flag -yno_propolice`" != "true" ]; then 352 [ -z "`is-flag -yno_propolice`" ] &&
314 debug-print ">>> appending flags -yno_propolice" 353 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
315 append-flags -yno_propolice
316 append-ldflags -yno_propolice
317 fi 354 fi
318 fi
319} 355}

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

  ViewVC Help
Powered by ViewVC 1.1.20