From patchwork Wed Nov 15 21:34:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10060323 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 F312560231 for ; Wed, 15 Nov 2017 21:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFEF92A118 for ; Wed, 15 Nov 2017 21:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D46142A312; Wed, 15 Nov 2017 21:36:19 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=ham 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 590062A118 for ; Wed, 15 Nov 2017 21:36:19 +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=9++q2r4/JUN/1AEWXxU1EajLD+cBSeqSvtNSlhD3XP0=; b=WoBmOrdTVm+LqvusQHw0/Vdext if4t6tRbe05HBkdU5UN8EzUXpJSvZF2MbCYoMpAInCXJWfTID/oQ8CajayZvjliId+7nLbBJ85qYo 9yDkVWUhuKhkOdPqg+RUQjJ+CEjc5uB6MYS1VPoH6DTXdNtAaxWw3SjGQoNViRP5ZXO2KrmubQ0/W p9D0vR9AMbzQmhnlqgWbl2RzypBnvyuHDnIbbhFq2nOiDSIrzFgrk1zUyqimvPFBvx1IxX0qnNHhi I94y+n+3TvZ11YcKm9jEmiF4RC1XugFFcJU18R8zlFKrzmdrBHTWCHZH9PN7i1hVLdUZ4sb5NUgNi CBGxC4Sg==; 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 1eF5M2-0001ve-KE; Wed, 15 Nov 2017 21:36:18 +0000 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eF5Ks-00088Q-9i for linux-arm-kernel@lists.infradead.org; Wed, 15 Nov 2017 21:35:11 +0000 Received: by mail-io0-x243.google.com with SMTP id v21so3096776ioi.4 for ; Wed, 15 Nov 2017 13:34:45 -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=/8d+p6CdShK26W+iVK0rVICui4hJ74hdEW/HYNlEcIM=; b=miV0v8PvpRIos2tiabGZfIUb0q2I7LHwJFSHE5a9nfvFtVC+TC0YWkPWRD+NqQNnE7 +/YKz0MKp2U2YoOC1GPf9HcJ4r1wSbH4xNoskv7FZ/P6jLBc1J6923p4a7aScd1JwdbH Ia2HYR96yiH5OPkpqzZWO07Mdm4Scsk91IfOwH39cI+Ezyz/zl+OMwdQZJaYikQtiNtO 3yPCYtEk3o/koZytD/G+hMk94f9jttuH3IEZoiqE/JXlARN3EnxFGdkxikFJKcB4wqOZ bozy1R/Xopm7XBFBWBJ2k4LEDBMr+BE0sf87a46LDYLcNPd0BZi2y0DGJTgaikvMSWfm sF0g== 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=/8d+p6CdShK26W+iVK0rVICui4hJ74hdEW/HYNlEcIM=; b=iMSz71kvxqxDQdxpY1ZtN1XrwBNY74HZxDgrk+vAkyIzcu1WSz/VfAIcV04Skt7Lmg LKEP6QxVclkGofoIQRDlZhqBHvRNw1LVviQA8a/e2OzqtS5kKCDErPc/pXBFKEicEHfv tD8IpneXcUfvi3T2qSJYqc8Ri0nccUKFFS/idhyyDfK2VKkkELZIZ4I4a79VMJq+6dDA slL0V5e3x4yhZXwDa/kcwfu9+VNL89DTj62mg8yajfPfr6EYTpUHAnZlyPuR092hPiAh s+MhFFr5Ewat+zTEesUsge9HCu2dfSZkiWSLNYFbwaFR8v3pZtWIe5BaA4tiN9+u28Re lftw== X-Gm-Message-State: AJaThX4kj4ecuH1EMHSSxpR/pgya3m8JXoGhjBcLjZeV8H+/x+KzZmKj PE0uXTLpdE2HhEjTN8bTjUf20A== X-Google-Smtp-Source: AGs4zMYxpz3xwb2mtyE4/1vtJ/RYxbhPbf/Bo9YNucD9jMJ7k/6DNhDwP/HNDxE3G24h1jTe1qSaRA== X-Received: by 10.107.18.38 with SMTP id a38mr4253068ioj.58.1510781684887; Wed, 15 Nov 2017 13:34:44 -0800 (PST) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id 68sm9735197iov.2.2017.11.15.13.34.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 13:34:44 -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 Subject: [PATCH v2 03/18] kbuild: move gcc-version.sh to cc-version.sh and add clang support Date: Wed, 15 Nov 2017 13:34:13 -0800 Message-Id: <20171115213428.22559-4-samitolvanen@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: <20171115213428.22559-1-samitolvanen@google.com> References: <20171115213428.22559-1-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171115_133506_549069_4C76A44C X-CRM114-Status: GOOD ( 11.53 ) 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 Signed-off-by: Sami Tolvanen --- scripts/Kbuild.include | 4 ++-- scripts/cc-version.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ scripts/gcc-version.sh | 33 --------------------------------- 3 files changed, 47 insertions(+), 35 deletions(-) create mode 100755 scripts/cc-version.sh delete mode 100755 scripts/gcc-version.sh diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 584d6cecd7c0..de41ab74121e 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -143,11 +143,11 @@ cc-disable-warning = $(call try-run,\ cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) # cc-version -cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) +cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/cc-version.sh $(CC)) # cc-fullversion cc-fullversion = $(shell $(CONFIG_SHELL) \ - $(srctree)/scripts/gcc-version.sh -p $(CC)) + $(srctree)/scripts/cc-version.sh -p $(CC)) # cc-ifversion # Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) diff --git a/scripts/cc-version.sh b/scripts/cc-version.sh new file mode 100755 index 000000000000..6d085a8a07e8 --- /dev/null +++ b/scripts/cc-version.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# cc-version [-p] cc-command +# +# Prints the compiler version of `command' in a canonical 4-digit form +# such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc. +# +# With the -p option, prints the patchlevel as well, for example `029503' for +# gcc-2.95.3, `030301' for gcc-3.3.1, etc. +# + +if [ "$1" = "-p" ] ; then + with_patchlevel=1; + shift; +fi + +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." + printf "Usage:\n\t$0 \n" + exit 1 +fi + +clang=$(echo __clang__ | $compiler -E -x c - | tail -n1) + +if [ "$clang" == "1" ]; then + major_macro="__clang_major__" + minor_macro="__clang_minor__" + patchlevel_macro="__clang_patchlevel__" +else + major_macro="__GNUC__" + minor_macro="__GNUC_MINOR__" + patchlevel_macro="__GNUC_PATCHLEVEL__" +fi + +MAJOR=$(echo $major_macro | $compiler -E -x c - | tail -n 1) +MINOR=$(echo $minor_macro | $compiler -E -x c - | tail -n 1) +if [ "x$with_patchlevel" != "x" ] ; then + PATCHLEVEL=$(echo $patchlevel_macro | $compiler -E -x c - | tail -n 1) + printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL +else + printf "%02d%02d\\n" $MAJOR $MINOR +fi diff --git a/scripts/gcc-version.sh b/scripts/gcc-version.sh deleted file mode 100755 index 11bb909845e7..000000000000 --- a/scripts/gcc-version.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# -# gcc-version [-p] gcc-command -# -# Prints the gcc version of `gcc-command' in a canonical 4-digit form -# such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc. -# -# With the -p option, prints the patchlevel as well, for example `029503' for -# gcc-2.95.3, `030301' for gcc-3.3.1, etc. -# - -if [ "$1" = "-p" ] ; then - with_patchlevel=1; - shift; -fi - -compiler="$*" - -if [ ${#compiler} -eq 0 ]; then - echo "Error: No compiler specified." - printf "Usage:\n\t$0 \n" - exit 1 -fi - -MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1) -MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1) -if [ "x$with_patchlevel" != "x" ] ; then - PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1) - printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL -else - printf "%02d%02d\\n" $MAJOR $MINOR -fi