From patchwork Wed Nov 29 00:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10081237 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 DD86360311 for ; Wed, 29 Nov 2017 00:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCE412979C for ; Wed, 29 Nov 2017 00:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0741297A2; Wed, 29 Nov 2017 00:01:07 +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=ham 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 70A602979C for ; Wed, 29 Nov 2017 00:01:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753262AbdK2AA0 (ORCPT ); Tue, 28 Nov 2017 19:00:26 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:39094 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753039AbdK2AAY (ORCPT ); Tue, 28 Nov 2017 19:00:24 -0500 Received: by mail-io0-f195.google.com with SMTP id h12so1826610iof.6 for ; Tue, 28 Nov 2017 16:00:24 -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=bZzvoLAfnVAaXjPqAoPFIq1X+vSOJpUjR17wwEnMtkI=; b=iNZWsBjPQtvNjcyuQnor+wMPbwyCTSXsUj97l0bZKJGi9Phy36wOVE7HqQv4NUXCc5 SYyzzA0K+LABqaOX+GD+Rtg8G7YgKfk27UmRl4hc9j2404lFQJQFNlMOinAr4f3dR0P+ UlpHXirg2P5jdtdla3iECtILRH7bWy9A0p72215buGeZa3JMIbsGxF+HGGihP/5j6G3+ huuPSzmsEitjFrPrLtF+U09exQbQBGm69VXgzfWpcbIiXBXDn82UKuUXLfvDSATEcCKS KzmouJcnGD1K/oCBbgbo5wIqZFSfOEARN/YzSB7NdcY264PXqstM/LiAtpEtojfUGLTv 7weA== 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=bZzvoLAfnVAaXjPqAoPFIq1X+vSOJpUjR17wwEnMtkI=; b=CRy6bFSDTrltDyK//WfLQjhOhB0sHFHSKlU3ZoRqv7+SBzPp1ZGN2RckxrfjnJa8XH I6MzW9Ksl/0D8G2NZQ6ew4Va5ffD1FO/oIjmrB5Uy1sjrnE3ROjzPcR557t2bojLYxNv d3XGhdaX9ZjOMxCsySppfyPOR3mu39hlOPh6KwwijbRp6lJhhwMby5OPtgqNHJOUBVCG LEfh0fkpIewfPJJFX9DGuuxHi1IhdBQQagrEoVMd55SWXZrKSMQJNS36u/v0hGGlLyBw 4nl4zUm4zbHZFFRU7fZtgzKANIK3cPeWLpFFwR5f0SbAU3rrjwS4cq7hTCFPQG/S+6M/ tQqg== X-Gm-Message-State: AJaThX7l10hra6FgGrY1gtXZMfPimkoh8J1PLvjq5ws6PFyivxUY46uf zTXRg4Nl8W00uMQtR/DA3LoZvg== X-Google-Smtp-Source: AGs4zMZ/0yG0WXPyMkW38k9G9XokoCjX1dbhr3xjqgqRtsaYFUOozoYONcz5xXHl7+Nz1mUo8zqe5Q== X-Received: by 10.107.135.97 with SMTP id j94mr1166881iod.213.1511913622383; Tue, 28 Nov 2017 16:00:22 -0800 (PST) Received: from samitolvanen.mtv.corp.google.com ([100.98.112.14]) by smtp.gmail.com with ESMTPSA id w68sm204836iow.18.2017.11.28.16.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Nov 2017 16:00:21 -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 1/3] kbuild: add clang-version.sh Date: Tue, 28 Nov 2017 16:00:09 -0800 Message-Id: <20171129000011.55235-2-samitolvanen@google.com> X-Mailer: git-send-email 2.15.0.417.g466bffb3ac-goog In-Reply-To: <20171129000011.55235-1-samitolvanen@google.com> References: <20171129000011.55235-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 Based on gcc-version.sh, clang-version.sh prints out the correct version of clang. Signed-off-by: Sami Tolvanen Tested-by: Nick Desaulniers --- scripts/clang-version.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 scripts/clang-version.sh diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh new file mode 100755 index 000000000000..5f14ddc54032 --- /dev/null +++ b/scripts/clang-version.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# clang-version [-p] clang-command +# +# Prints the compiler version of `command' in a canonical 4-digit form +# such as `0500' for clang-5.0 etc. +# +# With the -p option, prints the patchlevel as well, for example `050001' for +# clang-5.0.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 __clang_major__ | $compiler -E -x c - | tail -n 1) +MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) +if [ "x$with_patchlevel" != "x" ] ; then + PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) + printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL +else + printf "%02d%02d\\n" $MAJOR $MINOR +fi