/[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.49
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.49 2004/05/11 13:02:05 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"
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
98 return 0 104 return 0
99} 105}
100 106
101filter-lfs-flags() { 107filter-lfs-flags() {
102 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 108 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
109}
110
111append-lfs-flags() {
112 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
103} 113}
104 114
105append-flags() { 115append-flags() {
106 export CFLAGS="${CFLAGS} $@" 116 export CFLAGS="${CFLAGS} $@"
107 export CXXFLAGS="${CXXFLAGS} $@" 117 export CXXFLAGS="${CXXFLAGS} $@"
171 181
172 local NEW_CFLAGS="" 182 local NEW_CFLAGS=""
173 local NEW_CXXFLAGS="" 183 local NEW_CXXFLAGS=""
174 184
175 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 185 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
176 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then 186 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then
177 [ `use debug` ] && einfo "Enabling the use of some unstable flags" 187 use debug && einfo "Enabling the use of some unstable flags"
178 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 188 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
179 fi 189 fi
180 190
181 set -f 191 set -f
182 192
214 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 224 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
215 fi 225 fi
216 226
217 set +f 227 set +f
218 228
219 [ `use debug` ] \ 229 use debug \
220 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ 230 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
221 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" 231 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
222 232
223 export CFLAGS="${NEW_CFLAGS}" 233 export CFLAGS="${NEW_CFLAGS}"
224 export CXXFLAGS="${NEW_CXXFLAGS}" 234 export CXXFLAGS="${NEW_CXXFLAGS}"
225 return 0 235 return 0
226} 236}
227 237
228test_flag() { 238test_flag() {
229 if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then 239 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then
230 echo "$@" 240 echo "$@"
231 return 0 241 return 0
232 fi 242 fi
233 return 1 243 return 1
234} 244}
259 fi 269 fi
260 done 270 done
261 return 1 271 return 1
262} 272}
263 273
274has_pic() {
275 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
276 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
277 has_version sys-devel/hardened-gcc && return 0
278 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
279 return 1
280}
281
282has_pie() {
283 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
284 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
285 has_version sys-devel/hardened-gcc && return 0
286 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
287 return 1
288}
289
290has_ssp() {
291 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
292 has_version sys-devel/hardened-gcc && return 0
293 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0
294 return 1
295}
296
264replace-sparc64-flags() { 297replace-sparc64-flags() {
265 local SPARC64_CPUS="ultrasparc v9" 298 local SPARC64_CPUS="ultrasparc v9"
266 299
267 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] 300 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
268 then 301 then
294append-ldflags() { 327append-ldflags() {
295 LDFLAGS="${LDFLAGS} $@" 328 LDFLAGS="${LDFLAGS} $@"
296 return 0 329 return 0
297} 330}
298 331
332filter-ldflags() {
333 # we do this fancy spacing stuff so as to not filter
334 # out part of a flag ... we want flag atoms ! :D
335 LDFLAGS=" ${LDFLAGS} "
336 for x in "$@" ; do
337 LDFLAGS="${LDFLAGS// ${x} / }"
338 done
339 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
340 return 0
341}
342
299etexec-flags() { 343etexec-flags() {
300 has_version sys-devel/hardened-gcc 344 has_pie || has_pic
301 if [ $? == 0 ] ; then 345 if [ $? == 0 ] ; then
302 if [ "`is-flag -yet_exec`" != "true" ]; then 346 [ -z "`is-flag -yet_exec`" ] &&
303 debug-print ">>> appending flags -yet_exec" 347 export CFLAGS="${CFLAGS} `test_flag -yet_exec`"
304 append-flags -yet_exec 348 [ -z "`is-flag -nopie`" ] &&
305 append-ldflags -yet_exec 349 export CFLAGS="${CFLAGS} `test_flag -nopie`"
306 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
313 if [ "`is-flag -yno_propolice`" != "true" ]; then 356 [ -z "`is-flag -yno_propolice`" ] &&
314 debug-print ">>> appending flags -yno_propolice" 357 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
315 append-flags -yno_propolice
316 append-ldflags -yno_propolice
317 fi 358 fi
318 fi
319} 359}

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

  ViewVC Help
Powered by ViewVC 1.1.20