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: 10085791 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 D3D82602BC for ; Thu, 30 Nov 2017 23:40:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C556B2A161 for ; Thu, 30 Nov 2017 23:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9C1D2A1A9; Thu, 30 Nov 2017 23:40:08 +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=-2.5 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, URIBL_BLACK autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F2B22A161 for ; Thu, 30 Nov 2017 23:40:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=uP9m4DWx94BTCB/pvLcLKlrt3mVq06EtgjvN0ND4p/g=; b=Is2pYvhAFXWKhl3JBZ4T14j2Jm ZJ6bQlbMrSQtvah43gkZwCvrplsb7WR3M3+yWReFLZFiCIGCifSw8LKzPc0h0gWYlQtu4LjEtntsg QPpSWT1XsPJ7jIp/xxmpSO7DzlO/LCK1h7yiVtf8h1upJ73J2WaKsUqNTF50RooxWlRSt8yricMS+ 8yHlvpXlScAwwBkKseaei0WBkpLOx2Ctr3uba1dqO6T0PV+gO+1wyvqnNIPqk6Jfcy8G9/RBLGLvu MdJTnWHe04IPIDq+hUdQWiNeh//coDwJTkSZ9BzjJdI5r54/X8YMqOxnjorhbde+IXB5JjEbDaoyO mrt0tOyg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eKYR4-0001gS-6p; Thu, 30 Nov 2017 23:40:06 +0000 Received: from mail-io0-x242.google.com ([2607:f8b0:4001:c06::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eKYQ0-0000at-JP for linux-arm-kernel@lists.infradead.org; Thu, 30 Nov 2017 23:39:05 +0000 Received: by mail-io0-x242.google.com with SMTP id 81so9425224iof.3 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=OIgRAlpf6fnbmy6sFHxgO9/IWfV/vSlrPDHZRZquLreYj0U5p1YBc8aL9g77NBruaU 5+JMdShGp9BD/HFjCcjmgxLUFTDD/MKwvKrIC2Iz3fbRuwsrORl48ho4sKFRLAxjVpc+ dCWjvdn1xr9KlbTb4zKvIWiCkH5yRZrvovW56uPPnbl3VyG4SnOmn/GzDem9O9eNNc5B HLwQw+veAldAXffnmrr85F0YNcOqdKSYdx7BsCowDWm4VbiKgYKX0r/GG3HoAFiCWBmj ElLZjBst/Siia2A9sOgkUVagxkzdkU0Ef7tl5/+6ngQ8UBB0NUA60iByx76ak9w8nGw1 1QnA== X-Gm-Message-State: AJaThX4tRJNLpkHXpdXxJb4RQr3XsPnYFqe2rbGwD5etcKSQD0lmqHXi pofv7xf+UkbPNAofyX5sQUzzwQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171130_153901_171458_48121D3E X-CRM114-Status: UNSURE ( 9.30 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sami Tolvanen MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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)