Gentoo Archives: gentoo-dev

From: James Le Cuirot <chewi@g.o>
To: gentoo-dev@l.g.o
Cc: James Le Cuirot <chewi@g.o>
Subject: [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
Date: Tue, 14 Aug 2018 20:34:29
Message-Id: 20180814203304.27305-3-chewi@gentoo.org
In Reply to: [gentoo-dev] [arm17] [PATCH 0/3] toolchain-funcs.eclass: tc-is-softfloat for ARM and associated functions by James Le Cuirot
1 CTARGET is used, if defined, otherwise CHOST. CHOST was previously
2 assumed but this should not affect existing usage of these helpers.
3 ---
4 eclass/toolchain-funcs.eclass | 53 +++++++++++++++++------------------
5 1 file changed, 25 insertions(+), 28 deletions(-)
6
7 diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
8 index fbd1a8d5e2bf..d9a37c91a8ef 100644
9 --- a/eclass/toolchain-funcs.eclass
10 +++ b/eclass/toolchain-funcs.eclass
11 @@ -196,6 +196,27 @@ tc-is-cross-compiler() {
12 [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
13 }
14
15 +# @FUNCTION: tc-cpp-is-true
16 +# @USAGE: <condition> [cpp flags]
17 +# @RETURN: Shell true if the condition is true, shell false otherwise.
18 +# @DESCRIPTION:
19 +# Evaluate the given condition using the C preprocessor for CTARGET, if
20 +# defined, or CHOST. Additional arguments are passed through to the cpp
21 +# command. A typical condition would be in the form defined(__FOO__).
22 +tc-cpp-is-true() {
23 + local CONDITION=${1}
24 + shift
25 +
26 + local RESULT=$($(tc-getTARGET_CPP) "${@}" -P - <<-EOF 2>/dev/null
27 + #if ${CONDITION}
28 + true
29 + #endif
30 + EOF
31 + )
32 +
33 + [[ ${RESULT} == true ]]
34 +}
35 +
36 # @FUNCTION: tc-is-softfloat
37 # @DESCRIPTION:
38 # See if this toolchain is a softfloat based one.
39 @@ -837,13 +858,7 @@ gcc-specs-stack-check() {
40 # Return truth if the current compiler generates position-independent code (PIC)
41 # which can be linked into executables.
42 tc-enables-pie() {
43 - local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
44 - #if defined(__PIE__)
45 - true
46 - #endif
47 - EOF
48 - )"
49 - [[ ${ret} == true ]]
50 + tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
51 }
52
53 # @FUNCTION: tc-enables-ssp
54 @@ -855,13 +870,7 @@ tc-enables-pie() {
55 # -fstack-protector-strong
56 # -fstack-protector-all
57 tc-enables-ssp() {
58 - local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
59 - #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)
60 - true
61 - #endif
62 - EOF
63 - )"
64 - [[ ${ret} == true ]]
65 + tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
66 }
67
68 # @FUNCTION: tc-enables-ssp-strong
69 @@ -872,13 +881,7 @@ tc-enables-ssp() {
70 # -fstack-protector-strong
71 # -fstack-protector-all
72 tc-enables-ssp-strong() {
73 - local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
74 - #if defined(__SSP_STRONG__) || defined(__SSP_ALL__)
75 - true
76 - #endif
77 - EOF
78 - )"
79 - [[ ${ret} == true ]]
80 + tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
81 }
82
83 # @FUNCTION: tc-enables-ssp-all
84 @@ -888,13 +891,7 @@ tc-enables-ssp-strong() {
85 # on level corresponding to any of the following options:
86 # -fstack-protector-all
87 tc-enables-ssp-all() {
88 - local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
89 - #if defined(__SSP_ALL__)
90 - true
91 - #endif
92 - EOF
93 - )"
94 - [[ ${ret} == true ]]
95 + tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
96 }
97
98
99 --
100 2.17.0