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: 10060365 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 8E58760231 for ; Wed, 15 Nov 2017 21:38:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D8B02A2DA for ; Wed, 15 Nov 2017 21:38:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 725652A31D; Wed, 15 Nov 2017 21:38:36 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 0F3F22A2DA for ; Wed, 15 Nov 2017 21:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759568AbdKOVi1 (ORCPT ); Wed, 15 Nov 2017 16:38:27 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:41768 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758988AbdKOVeq (ORCPT ); Wed, 15 Nov 2017 16:34:46 -0500 Received: by mail-io0-f195.google.com with SMTP id g73so3073622ioj.8 for ; Wed, 15 Nov 2017 13:34:46 -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=pmsVdJyLjgcVz0dv6vlwQY6piDvUzObZicQN9dR04Dw57+0my6qTPShRPu8V0qSr1o yETf5+vUGIrjPOVbEmxVitKNxKyGH43Tc0x1x6M1yhjKIACU3VIAAiklDGQFL+/CHD5K Wih2h09GiVr96thXNes/6QgzIRU3p368QwLuJRA4SDehS+uUB0UdUugAOjcc1qZw9ROs oLCaV2TteAbn8C5bpQAJOWXKyuUec5DlWIFuzuArPBEBxPwRe8eUeo2dhOE8MRyYkMFT 4UiA6zz2Oizf7FBgsdrv6O3R+Aoa3up15ftBN8mC208KB/UbGNAwgK3EB9hbVHdr7fiv lFtA== X-Gm-Message-State: AJaThX7SGUYgMsZT2nHeZT0My101ZIGOr/lGkAfD24yl+OI+CxbCBZWC 02G6G3oukjsbkTZgdGsNkc9fmQ== 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 Cc: Sami Tolvanen 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> 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 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