From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BC463138334 for ; Tue, 14 Aug 2018 20:34:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 91851E0943; Tue, 14 Aug 2018 20:33:43 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 42F01E092F for ; Tue, 14 Aug 2018 20:33:43 +0000 (UTC) Received: from symphony.aura-online.co.uk (154.189.187.81.in-addr.arpa [81.187.189.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: chewi) by smtp.gentoo.org (Postfix) with ESMTPSA id 656D0335CD1; Tue, 14 Aug 2018 20:33:41 +0000 (UTC) From: James Le Cuirot To: gentoo-dev@lists.gentoo.org Cc: James Le Cuirot Subject: [gentoo-dev] [arm17] [PATCH 2/3] toolchain-funcs.eclass: tc-cpp-is-true function to simplify helpers Date: Tue, 14 Aug 2018 21:33:03 +0100 Message-Id: <20180814203304.27305-3-chewi@gentoo.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180814203304.27305-1-chewi@gentoo.org> References: <20180814203304.27305-1-chewi@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 6cd4790a-69fe-4233-8d2b-0d21392e8ea5 X-Archives-Hash: d8fb89b5a25708231522dbfb2e529828 CTARGET is used, if defined, otherwise CHOST. CHOST was previously assumed but this should not affect existing usage of these helpers. --- eclass/toolchain-funcs.eclass | 53 +++++++++++++++++------------------ 1 file 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: [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} } -- 2.17.0