/[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.41 Revision 1.54
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.41 2004/03/16 21:37:09 solar Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.54 2004/06/06 16:39:18 solar 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"
9IUSE="debug"
9 10
10# 11#
11#### filter-flags <flags> #### 12#### filter-flags <flags> ####
12# Remove particular flags from C[XX]FLAGS 13# Remove particular flags from C[XX]FLAGS
13# Matches only complete flags 14# Matches only complete flags
52#### filter-ldflags <flags> #### 53#### filter-ldflags <flags> ####
53# Remove particular flags from LDFLAGS 54# Remove particular flags from LDFLAGS
54# Matches only complete flags 55# Matches only complete flags
55# 56#
56#### etexec-flags #### 57#### etexec-flags ####
57# hooked function for hardened-gcc that appends 58# hooked function for hardened gcc that appends
58# -yet_exec {C,CXX,LD}FLAGS when hardened-gcc is installed 59# -fno-pic to {C,CXX,LD}FLAGS
59# and a package is filtering -fPIC,-fpic, -fPIE, -fpie 60# when a package is filtering -fpic, -fPIC, -fpie, -fPIE
60# 61#
61#### fstack-flags #### 62#### fstack-flags ####
62# hooked function for hardened-gcc that appends 63# hooked function for hardened gcc that appends
63# -yno_propolice to {C,CXX,LD}FLAGS when hardened-gcc is installed 64# -fno-stack-protector to {C,CXX,LD}FLAGS
64# and a package is filtering -fstack-protector, -fstack-protector-all 65# when a package is filtering -fstack-protector, -fstack-protector-all
66# notice: modern automatic specs files will also suppress -fstack-protector-all
67# when only -fno-stack-protector is given
65# 68#
66 69
67# C[XX]FLAGS that we allow in strip-flags 70# C[XX]FLAGS that we allow in strip-flags
68setup-allowed-flags() { 71setup-allowed-flags() {
72 if [ -z "${ALLOWED_FLAGS}" ] ; then
69 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -pipe -g" 73 export ALLOWED_FLAGS="-O -O1 -O2 -mcpu -march -mtune -fstack-protector -fno-unit-at-a-time -pipe -g"
70 case "${ARCH}" in 74 case "${ARCH}" in
71 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;; 75 mips) ALLOWED_FLAGS="${ALLOWED_FLAGS} -mips1 -mips2 -mips3 -mips4 -mabi" ;;
72 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 76 amd64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC -m64" ;;
77 x86) ALLOWED_FLAGS="${ALLOWED_FLAGS} -m32" ;;
73 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 78 alpha) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
74 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;; 79 ia64) ALLOWED_FLAGS="${ALLOWED_FLAGS} -fPIC" ;;
75 esac 80 esac
81 fi
76 82
77 # C[XX]FLAGS that we are think is ok, but needs testing 83 # C[XX]FLAGS that we are think is ok, but needs testing
78 # NOTE: currently -Os have issues with gcc3 and K6* arch's 84 # NOTE: currently -Os have issues with gcc3 and K6* arch's
79 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays" 85 export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks -fprefetch-loop-arrays"
80 return 0 86 return 0
102 return 0 108 return 0
103} 109}
104 110
105filter-lfs-flags() { 111filter-lfs-flags() {
106 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE 112 filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
113}
114
115append-lfs-flags() {
116 append-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
107} 117}
108 118
109append-flags() { 119append-flags() {
110 export CFLAGS="${CFLAGS} $@" 120 export CFLAGS="${CFLAGS} $@"
111 export CXXFLAGS="${CXXFLAGS} $@" 121 export CXXFLAGS="${CXXFLAGS} $@"
175 185
176 local NEW_CFLAGS="" 186 local NEW_CFLAGS=""
177 local NEW_CXXFLAGS="" 187 local NEW_CXXFLAGS=""
178 188
179 # Allow unstable C[XX]FLAGS if we are using unstable profile ... 189 # Allow unstable C[XX]FLAGS if we are using unstable profile ...
180 if [ `has ~${ARCH} ${ACCEPT_KEYWORDS}` ] ; then 190 if has ~${ARCH} ${ACCEPT_KEYWORDS} ; then
181 [ `use debug` ] && einfo "Enabling the use of some unstable flags" 191 use debug && einfo "Enabling the use of some unstable flags"
182 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}" 192 ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}"
183 fi 193 fi
184 194
185 set -f 195 set -f
186 196
218 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2" 228 NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2"
219 fi 229 fi
220 230
221 set +f 231 set +f
222 232
223 [ `use debug` ] \ 233 use debug \
224 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \ 234 && einfo "CFLAGS=\"${NEW_CFLAGS}\"" \
225 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\"" 235 && einfo "CXXFLAGS=\"${NEW_CXXFLAGS}\""
226 236
227 export CFLAGS="${NEW_CFLAGS}" 237 export CFLAGS="${NEW_CFLAGS}"
228 export CXXFLAGS="${NEW_CXXFLAGS}" 238 export CXXFLAGS="${NEW_CXXFLAGS}"
229 return 0 239 return 0
230} 240}
231 241
232test_flag() { 242test_flag() {
233 if gcc -S -xc "$@" -o /dev/null /dev/null >/dev/null 2>&1; then 243 if [ -z "`gcc -S -xc "$@" -o /dev/null /dev/null 2>&1`" ]; then
234 echo "$@" 244 echo "$@"
235 return 0 245 return 0
236 fi 246 fi
237 return 1 247 return 1
238} 248}
263 fi 273 fi
264 done 274 done
265 return 1 275 return 1
266} 276}
267 277
278has_hardened() {
279 local cc=${CC:-gcc}
280 [[ $(${cc%% *} --version 2>&1) == *Hardened* ]]
281 return $?
282}
283
284has_pic() {
285 [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0
286 [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0
287 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
288 return 1
289}
290
291has_pie() {
292 [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0
293 [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0
294 [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0
295 return 1
296}
297
298has_ssp() {
299 [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0
300 [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0
301 return 1
302}
303
268replace-sparc64-flags() { 304replace-sparc64-flags() {
269 local SPARC64_CPUS="ultrasparc v9" 305 local SPARC64_CPUS="ultrasparc v9"
270 306
271 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] 307 if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]
272 then 308 then
310 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" 346 LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}"
311 return 0 347 return 0
312} 348}
313 349
314etexec-flags() { 350etexec-flags() {
315 has_version sys-devel/hardened-gcc 351 # if your not using a hardened compiler you wont need this
352 # PIC/no-pic kludge in the first place.
353 has_hardened || return
354
355 has_pie || has_pic
316 if [ $? == 0 ] ; then 356 if [ $? == 0 ] ; then
317 if [ "`is-flag -yet_exec`" != "true" ]; then 357 [ -z "`is-flag -fno-pic`" ] &&
318 debug-print ">>> appending flags -yet_exec" 358 export CFLAGS="${CFLAGS} `test_flag -fno-pic`"
319 append-flags -yet_exec 359
320 append-ldflags -yet_exec 360 [ -z "`is-flag -nopie`" ] &&
321 fi 361 export CFLAGS="${CFLAGS} `test_flag -nopie`"
322 fi 362 fi
323} 363}
324 364
325fstack-flags() { 365fstack-flags() {
326 has_version sys-devel/hardened-gcc 366 has_ssp
327 if [ $? == 0 ] ; then 367 if [ $? == 0 ] ; then
328 if [ "`is-flag -yno_propolice`" != "true" ]; then 368 [ -z "`is-flag -fno-stack-protector`" ] &&
329 debug-print ">>> appending flags -yno_propolice" 369 export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`"
330 append-flags -yno_propolice
331 append-ldflags -yno_propolice
332 fi 370 fi
333 fi
334} 371}

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.54

  ViewVC Help
Powered by ViewVC 1.1.20