| 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.37 2004/02/21 07:19:29 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.42 2004/04/06 03:45:00 tseng Exp $ |
| 4 | # |
4 | # |
| 5 | # Author Bart Verwilst <verwilst@gentoo.org> |
5 | # Author Bart Verwilst <verwilst@gentoo.org> |
| 6 | |
6 | |
| 7 | ECLASS=flag-o-matic |
7 | ECLASS=flag-o-matic |
| 8 | INHERITED="$INHERITED $ECLASS" |
8 | INHERITED="$INHERITED $ECLASS" |
| … | |
… | |
| 46 | # If the user has -mfpmath=sse,386, running `filter-mfpmath sse` |
46 | # If the user has -mfpmath=sse,386, running `filter-mfpmath sse` |
| 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 | # |
|
|
52 | #### filter-ldflags <flags> #### |
|
|
53 | # Remove particular flags from LDFLAGS |
|
|
54 | # Matches only complete flags |
| 51 | # |
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 |
| … | |
… | |
| 77 | } |
81 | } |
| 78 | |
82 | |
| 79 | filter-flags() { |
83 | filter-flags() { |
| 80 | for x in "$@" ; do |
84 | for x in "$@" ; do |
| 81 | case "${x}" in |
85 | case "${x}" in |
| 82 | -fPIC|-fpic|-fPIE|-fpie) etexec-flags;; |
86 | -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; |
| 83 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
87 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
| 84 | *) ;; |
88 | *) ;; |
| 85 | esac |
89 | esac |
| 86 | done |
90 | done |
| 87 | |
91 | |
| … | |
… | |
| 94 | CXXFLAGS="${CXXFLAGS// ${x} / }" |
98 | CXXFLAGS="${CXXFLAGS// ${x} / }" |
| 95 | done |
99 | done |
| 96 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
100 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
| 97 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
101 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
| 98 | return 0 |
102 | return 0 |
|
|
103 | } |
|
|
104 | |
|
|
105 | filter-lfs-flags() { |
|
|
106 | filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
| 99 | } |
107 | } |
| 100 | |
108 | |
| 101 | append-flags() { |
109 | append-flags() { |
| 102 | export CFLAGS="${CFLAGS} $@" |
110 | export CFLAGS="${CFLAGS} $@" |
| 103 | export CXXFLAGS="${CXXFLAGS} $@" |
111 | export CXXFLAGS="${CXXFLAGS} $@" |
| … | |
… | |
| 121 | local newcpu="$1" ; shift |
129 | local newcpu="$1" ; shift |
| 122 | local oldcpu="" |
130 | local oldcpu="" |
| 123 | for oldcpu in "$@" ; do |
131 | for oldcpu in "$@" ; do |
| 124 | replace-flags -march=${oldcpu} -march=${newcpu} |
132 | replace-flags -march=${oldcpu} -march=${newcpu} |
| 125 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
133 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
|
|
134 | replace-flags -mtune=${oldcpu} -mtune=${newcpu} |
| 126 | done |
135 | done |
| 127 | return 0 |
136 | return 0 |
| 128 | } |
137 | } |
| 129 | |
138 | |
| 130 | is-flag() { |
139 | is-flag() { |
| … | |
… | |
| 254 | fi |
263 | fi |
| 255 | done |
264 | done |
| 256 | return 1 |
265 | return 1 |
| 257 | } |
266 | } |
| 258 | |
267 | |
|
|
268 | has_pic() { |
|
|
269 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
|
|
270 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
|
|
271 | [ has_version sys-devel/hardened-gcc ] && return 0 |
|
|
272 | [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 |
|
|
273 | return 1 |
|
|
274 | } |
|
|
275 | |
|
|
276 | has_pie() { |
|
|
277 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
|
|
278 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
|
|
279 | [ has_version sys-devel/hardened-gcc ] && return 0 |
|
|
280 | [ ! -z "`${CC/ .*/} --version| grep pie`" ] && return 0 |
|
|
281 | return 1 |
|
|
282 | } |
|
|
283 | |
|
|
284 | has_ssp() { |
|
|
285 | [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 |
|
|
286 | [ has_version sys-devel/hardened-gcc ] && return 0 |
|
|
287 | [ ! -z "`${CC/ .*/} --version| grep ssp`" ] && return 0 |
|
|
288 | return 1 |
|
|
289 | } |
|
|
290 | |
| 259 | replace-sparc64-flags() { |
291 | replace-sparc64-flags() { |
| 260 | local SPARC64_CPUS="ultrasparc v9" |
292 | local SPARC64_CPUS="ultrasparc v9" |
| 261 | |
293 | |
| 262 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
294 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
| 263 | then |
295 | then |
| … | |
… | |
| 289 | append-ldflags() { |
321 | append-ldflags() { |
| 290 | LDFLAGS="${LDFLAGS} $@" |
322 | LDFLAGS="${LDFLAGS} $@" |
| 291 | return 0 |
323 | return 0 |
| 292 | } |
324 | } |
| 293 | |
325 | |
|
|
326 | filter-ldflags() { |
|
|
327 | # we do this fancy spacing stuff so as to not filter |
|
|
328 | # out part of a flag ... we want flag atoms ! :D |
|
|
329 | LDFLAGS=" ${LDFLAGS} " |
|
|
330 | for x in "$@" ; do |
|
|
331 | LDFLAGS="${LDFLAGS// ${x} / }" |
|
|
332 | done |
|
|
333 | LDFLAGS="${LDFLAGS:1:${#LDFLAGS}-2}" |
|
|
334 | return 0 |
|
|
335 | } |
|
|
336 | |
| 294 | etexec-flags() { |
337 | etexec-flags() { |
| 295 | has_version sys-devel/hardened-gcc |
338 | has_pie || has_pic |
| 296 | if [ $? == 0 ] ; then |
339 | if [ $? == 0 ] ; then |
|
|
340 | # strip -fPIC regardless if you've gotten this far |
|
|
341 | strip-flags -fPIC -fpic -fPIE -fpie -pie |
| 297 | if [ "`is-flag -yet_exec`" != "true" ]; then |
342 | if [ "`is-flag -yet_exec`" != "true" ]; then |
|
|
343 | # If our compile support -yet_exec, append it now |
|
|
344 | [ -z "`gcc -yet_exec -S -o /dev/null -xc /dev/null 2>&1`" ] \ |
| 298 | debug-print ">>> appending flags -yet_exec" |
345 | && ( debug-print ">>> appending flags -yet_exec" ; \ |
| 299 | append-flags -yet_exec |
346 | append-flags -yet_exec ; append-ldflags -yet_exec ) |
| 300 | append-ldflags -yet_exec |
|
|
| 301 | fi |
347 | fi |
| 302 | fi |
348 | fi |
| 303 | } |
349 | } |
| 304 | |
350 | |
| 305 | fstack-flags() { |
351 | fstack-flags() { |
| 306 | has_version sys-devel/hardened-gcc |
352 | has_ssp |
| 307 | if [ $? == 0 ] ; then |
353 | if [ $? == 0 ] ; then |
|
|
354 | # strip -fstack-protector regardless if you've gotten this far |
|
|
355 | strip-flags -fstack-protector -fstack-protector-all |
| 308 | if [ "`is-flag -yno_propolice`" != "true" ]; then |
356 | if [ "`is-flag -yno_propolice`" != "true" ]; then |
|
|
357 | # If our compile support -yno_propolice, append it now |
|
|
358 | [ -z "`gcc -yno_propolice -S -o /dev/null -xc /dev/null 2>&1`" ] \ |
| 309 | debug-print ">>> appending flags -yno_propolice" |
359 | && ( debug-print ">>> appending flags -yno_propolice" ; \ |
| 310 | append-flags -yno_propolice |
360 | append-flags -yno_propolice ; append-ldflags -yno_propolice ) |
| 311 | append-ldflags -yno_propolice |
|
|
| 312 | fi |
361 | fi |
| 313 | fi |
362 | fi |
| 314 | } |
363 | } |