| 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.46 2004/04/10 17:15:37 swtaylor 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" |
| … | |
… | |
| 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 |
| 64 | setup-allowed-flags() { |
68 | setup-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 |
| 77 | } |
83 | } |
| 78 | |
84 | |
| 79 | filter-flags() { |
85 | filter-flags() { |
| 80 | for x in "$@" ; do |
86 | for x in "$@" ; do |
| 81 | case "${x}" in |
87 | case "${x}" in |
| 82 | -fPIC|-fpic|-fPIE|-fpie) etexec-flags;; |
88 | -fPIC|-fpic|-fPIE|-fpie|-pie) etexec-flags;; |
| 83 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
89 | -fstack-protector|-fstack-protector-all) fstack-flags;; |
| 84 | *) ;; |
90 | *) ;; |
| 85 | esac |
91 | esac |
| 86 | done |
92 | done |
| 87 | |
93 | |
| … | |
… | |
| 94 | CXXFLAGS="${CXXFLAGS// ${x} / }" |
100 | CXXFLAGS="${CXXFLAGS// ${x} / }" |
| 95 | done |
101 | done |
| 96 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
102 | CFLAGS="${CFLAGS:1:${#CFLAGS}-2}" |
| 97 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
103 | CXXFLAGS="${CXXFLAGS:1:${#CXXFLAGS}-2}" |
| 98 | return 0 |
104 | return 0 |
|
|
105 | } |
|
|
106 | |
|
|
107 | filter-lfs-flags() { |
|
|
108 | filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE |
| 99 | } |
109 | } |
| 100 | |
110 | |
| 101 | append-flags() { |
111 | append-flags() { |
| 102 | export CFLAGS="${CFLAGS} $@" |
112 | export CFLAGS="${CFLAGS} $@" |
| 103 | export CXXFLAGS="${CXXFLAGS} $@" |
113 | export CXXFLAGS="${CXXFLAGS} $@" |
| … | |
… | |
| 121 | local newcpu="$1" ; shift |
131 | local newcpu="$1" ; shift |
| 122 | local oldcpu="" |
132 | local oldcpu="" |
| 123 | for oldcpu in "$@" ; do |
133 | for oldcpu in "$@" ; do |
| 124 | replace-flags -march=${oldcpu} -march=${newcpu} |
134 | replace-flags -march=${oldcpu} -march=${newcpu} |
| 125 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
135 | replace-flags -mcpu=${oldcpu} -mcpu=${newcpu} |
|
|
136 | replace-flags -mtune=${oldcpu} -mtune=${newcpu} |
| 126 | done |
137 | done |
| 127 | return 0 |
138 | return 0 |
| 128 | } |
139 | } |
| 129 | |
140 | |
| 130 | is-flag() { |
141 | is-flag() { |
| … | |
… | |
| 254 | fi |
265 | fi |
| 255 | done |
266 | done |
| 256 | return 1 |
267 | return 1 |
| 257 | } |
268 | } |
| 258 | |
269 | |
|
|
270 | has_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 | |
|
|
278 | has_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 | |
|
|
286 | has_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 | |
| 259 | replace-sparc64-flags() { |
293 | replace-sparc64-flags() { |
| 260 | local SPARC64_CPUS="ultrasparc v9" |
294 | local SPARC64_CPUS="ultrasparc v9" |
| 261 | |
295 | |
| 262 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
296 | if [ "${CFLAGS/mtune}" != "${CFLAGS}" ] |
| 263 | then |
297 | then |
| … | |
… | |
| 289 | append-ldflags() { |
323 | append-ldflags() { |
| 290 | LDFLAGS="${LDFLAGS} $@" |
324 | LDFLAGS="${LDFLAGS} $@" |
| 291 | return 0 |
325 | return 0 |
| 292 | } |
326 | } |
| 293 | |
327 | |
|
|
328 | filter-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 | |
| 294 | etexec-flags() { |
339 | etexec-flags() { |
| 295 | has_version sys-devel/hardened-gcc |
340 | has_pie || has_pic |
| 296 | if [ $? == 0 ] ; then |
341 | if [ $? == 0 ] ; then |
| 297 | if [ "`is-flag -yet_exec`" != "true" ]; then |
342 | if [ "`is-flag -yet_exec`" != "true" ]; then |
| 298 | debug-print ">>> appending flags -yet_exec" |
343 | debug-print ">>> appending flags -yet_exec" |
| 299 | append-flags -yet_exec |
344 | export CFLAGS="${CFLAGS} `test_flag -yet_exec`" |
| 300 | append-ldflags -yet_exec |
|
|
| 301 | fi |
345 | fi |
| 302 | fi |
346 | fi |
| 303 | } |
347 | } |
| 304 | |
348 | |
| 305 | fstack-flags() { |
349 | fstack-flags() { |
| 306 | has_version sys-devel/hardened-gcc |
350 | has_ssp |
| 307 | if [ $? == 0 ] ; then |
351 | if [ $? == 0 ] ; then |
| 308 | if [ "`is-flag -yno_propolice`" != "true" ]; then |
352 | if [ "`is-flag -yno_propolice`" != "true" ]; then |
| 309 | debug-print ">>> appending flags -yno_propolice" |
353 | debug-print ">>> appending flags -fno-stack-protector" |
| 310 | append-flags -yno_propolice |
354 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
| 311 | append-ldflags -yno_propolice |
|
|
| 312 | fi |
355 | fi |
| 313 | fi |
356 | fi |
| 314 | } |
357 | } |