From patchwork Thu Nov 30 23:38:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10085769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F529602BC for ; Thu, 30 Nov 2017 23:39:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E7742A2DC for ; Thu, 30 Nov 2017 23:39:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 236D12A420; Thu, 30 Nov 2017 23:39:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C78272A2DC for ; Thu, 30 Nov 2017 23:39:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbdK3Xiw (ORCPT ); Thu, 30 Nov 2017 18:38:52 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:37864 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbdK3Xii (ORCPT ); Thu, 30 Nov 2017 18:38:38 -0500 Received: by mail-io0-f194.google.com with SMTP id d16so9415808iob.4 for ; Thu, 30 Nov 2017 15:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EI5MX/swbu5YzzNugPIp6dJyAMGLq0ALGwJnFl1a3Oo=; b=gQc9k4dcLd/bOPgQQ/sCAmdvq4OeAKfSmmjQzWAzB2NvQSIoSPg7OKsP1n/sMKXjQK Tk4dnr+UhLcD1m9C6Mqr0GRQEID2kJr48PJvz4HzICBefC6zjwojfmyclxJw5CNW84pk 1Mp2yo4lVAkh9Grl6SSg7vfeiX7tL7g5VXNQOA4w//h7CGaiB13CPmJzWJUnxkq9TMXe uD6aOyOnuVPVb2HPDFjp8a6mlHDBzB9I7rp0biXfTanNt30pzfLg1FA6Z05LfUey8bb3 YBfLlBs5vua/Na18h9naY+ItxqHceVFpHHqDHGzlKMmVcWZQ7HO5YTr2nhncKc0lwSdk C1VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EI5MX/swbu5YzzNugPIp6dJyAMGLq0ALGwJnFl1a3Oo=; b=seLjPoNCPXGnn6cdaZAxMwmNV8nZLfV/JQPqJ9mPigyb0UnKCYT02+w4AiFzGzWu0Z Di+Kuw0UZtDKW3Evbx8ILxkMLPCuaUaOFDUfeAGAywH5wJM/LT0H1IDTZZ0CRqKBCRd+ JbAWy94Ga+jOLjv1Gi8H7hZCvhZrxZti/LaPKG3ga1plv2eML/SHn+KSxevU+N0xM8g1 /7Xy5Bvzf45rmJEpgPEtwJTt0SL338x9xr2obvOvYJZszSzezXACvvA4WGPEQ9Sq4wDA 8ibg8V0nt6MXyfIDFurc7KkdWfU3RGetvuVoi4p+v5s5EY9BzqYtGXPFiNR7nX1y/6S3 7E8Q== X-Gm-Message-State: AJaThX7e67ETxPpEIFIwi47L8DKer6aDYuigDkh5CRXETRVVR+AG2pZ/ wQ+sVuMw7S8s/Cw7eg/sFfKy5Q== X-Google-Smtp-Source: AGs4zMbYcbZOBudm0rG/nNU4Tha3KTeYDAT2ym8xOIcPvMSTxb4pJdui/YM6ffZrSEkF0GNXC/dh+A== X-Received: by 10.107.24.135 with SMTP id 129mr9849998ioy.79.1512085117415; Thu, 30 Nov 2017 15:38:37 -0800 (PST) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id y21sm2494714ioi.14.2017.11.30.15.38.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 15:38:36 -0800 (PST) From: Sami Tolvanen To: Alex Matveev , Andi Kleen , Ard Biesheuvel , Greg Hackmann , Kees Cook , linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Masahiro Yamada , Maxim Kuvyrkov , Michal Marek , Nick Desaulniers , Yury Norov , Matthias Kaehlcke , Nicholas Piggin Cc: Sami Tolvanen Subject: [PATCH v2 2/2] kbuild: add __cc-ifversion and compiler-specific variants Date: Thu, 30 Nov 2017 15:38:27 -0800 Message-Id: <20171130233827.130069-3-samitolvanen@google.com> X-Mailer: git-send-email 2.15.0.531.g2ccb3012c9-goog In-Reply-To: <20171130233827.130069-1-samitolvanen@google.com> References: <20171129000011.55235-1-samitolvanen@google.com> <20171130233827.130069-1-samitolvanen@google.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change adds macros for testing both compiler name and version. Current cc-version, cc-ifversion etc. macros that test gcc version are left unchanged to prevent compatibility issues with existing tests. Signed-off-by: Sami Tolvanen --- scripts/Kbuild.include | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 065324a8046f..eb2cf2780f6e 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -215,6 +215,37 @@ cc-disable-warning = $(call try-run-cached,\ # Expands to either gcc or clang cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) +# __cc-version +# Returns compiler version +__cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/$(cc-name)-version.sh $(CC)) + +# __cc-fullversion +# Returns full compiler version +__cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \ + $(srctree)/scripts/$(cc-name)-version.sh -p $(CC)) + +# __cc-ifversion +# Matches compiler name and version +# Usage: EXTRA_CFLAGS += $(call cc-if-name-version, gcc, -lt, 0402, -O1) +__cc-ifversion = $(shell [ $(cc-name) = $(1) ] && [ $(__cc-version) $(2) $(3) ] && echo $(4) || echo $(5)) + +# __cc-if-fullversion +# Matches compiler name and full version +# Usage: EXTRA_CFLAGS += $(call cc-if-name-fullversion, gcc, -lt, 040502, -O1) +__cc-if-fullversion = $(shell [ $(cc-name) = $(1) ] && [ $(__cc-fullversion) $(2) $(3) ] && echo $(4) || echo $(5)) + +# gcc-ifversion +gcc-ifversion = $(call __cc-ifversion, gcc, $(1), $(2), $(3), $(4)) + +# gcc-if-fullversion +gcc-if-fullversion = (call __cc-if-fullversion, gcc, $(1), $(2), $(3), $(4)) + +# clang-ifversion +clang-ifversion = $(call __cc-ifversion, clang, $(1), $(2), $(3), $(4)) + +# clang-if-fullversion +clang-if-fullversion = (call __cc-if-fullversion, clang, $(1), $(2), $(3), $(4)) + # cc-version cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) @@ -222,13 +253,9 @@ cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version. cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \ $(srctree)/scripts/gcc-version.sh -p $(CC)) -# cc-ifversion -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) -cc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) - -# cc-if-fullversion -# Usage: EXTRA_CFLAGS += $(call cc-if-fullversion, -lt, 040502, -O1) -cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo $(4)) +# backward compatibility +cc-ifversion = $(gcc-ifversion) +cc-if-fullversion = $(gcc-if-fullversion) # cc-ldoption # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)