summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@gentoo.org>2018-08-09 21:48:07 +0100
committerJames Le Cuirot <chewi@gentoo.org>2018-08-21 21:37:26 +0100
commitf3f183dd42463b42d1aac27debb04c75c616dae7 (patch)
tree4c10ee5cac21adb0b736bf1088cfe75ac9aa5669 /eclass/toolchain-funcs.eclass
parenttoolchain-funcs.eclass: New tc-getTARGET_CPP function (diff)
downloadgentoo-f3f183dd42463b42d1aac27debb04c75c616dae7.tar.gz
gentoo-f3f183dd42463b42d1aac27debb04c75c616dae7.tar.bz2
gentoo-f3f183dd42463b42d1aac27debb04c75c616dae7.zip
toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers
CTARGET is used, if defined, otherwise CHOST. CHOST was previously assumed but this should not affect existing usage of these helpers.
Diffstat (limited to 'eclass/toolchain-funcs.eclass')
-rw-r--r--eclass/toolchain-funcs.eclass53
1 files changed, 25 insertions, 28 deletions
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index fbd1a8d5e2bf..d9a37c91a8ef 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -196,6 +196,27 @@ tc-is-cross-compiler() {
[[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
}
+# @FUNCTION: tc-cpp-is-true
+# @USAGE: <condition> [cpp flags]
+# @RETURN: Shell true if the condition is true, shell false otherwise.
+# @DESCRIPTION:
+# Evaluate the given condition using the C preprocessor for CTARGET, if
+# defined, or CHOST. Additional arguments are passed through to the cpp
+# command. A typical condition would be in the form defined(__FOO__).
+tc-cpp-is-true() {
+ local CONDITION=${1}
+ shift
+
+ local RESULT=$($(tc-getTARGET_CPP) "${@}" -P - <<-EOF 2>/dev/null
+ #if ${CONDITION}
+ true
+ #endif
+ EOF
+ )
+
+ [[ ${RESULT} == true ]]
+}
+
# @FUNCTION: tc-is-softfloat
# @DESCRIPTION:
# See if this toolchain is a softfloat based one.
@@ -837,13 +858,7 @@ gcc-specs-stack-check() {
# Return truth if the current compiler generates position-independent code (PIC)
# which can be linked into executables.
tc-enables-pie() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__PIE__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp
@@ -855,13 +870,7 @@ tc-enables-pie() {
# -fstack-protector-strong
# -fstack-protector-all
tc-enables-ssp() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp-strong
@@ -872,13 +881,7 @@ tc-enables-ssp() {
# -fstack-protector-strong
# -fstack-protector-all
tc-enables-ssp-strong() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP_STRONG__) || defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp-all
@@ -888,13 +891,7 @@ tc-enables-ssp-strong() {
# on level corresponding to any of the following options:
# -fstack-protector-all
tc-enables-ssp-all() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}