From patchwork Tue Dec 17 10:58:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11297257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D029921 for ; Tue, 17 Dec 2019 11:00:30 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 394C52082E for ; Tue, 17 Dec 2019 11:00:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="CCKduMpS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 394C52082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihAZI-00086m-Uc; Tue, 17 Dec 2019 10:59:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihAZH-00086h-GS for xen-devel@lists.xenproject.org; Tue, 17 Dec 2019 10:59:07 +0000 X-Inumbo-ID: 3e27e0aa-20bc-11ea-8e9d-12813bfff9fa Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3e27e0aa-20bc-11ea-8e9d-12813bfff9fa; Tue, 17 Dec 2019 10:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576580346; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yUm/2bZSlveXpXlz+YiY8oG5Y26wdJFehLf0nNerXIM=; b=CCKduMpSqnqJRnPflYabUhkOosUIF0lFNVjPkBYk3f3vhRGZcQjtSl59 OO5xlz5nt1hR70v4sFsooFBcyDKu3w2qMLjLfHbUZkIH0pq8Ittn1TBAK XAoofOqSek0zkiHOZaLTrNqPGjobSaix86C3dRQfN2uyC8QiITqu0EBuf E=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: oF2jceJrBjJkGPJ7+vZZFlXAnzG3QQjsTvQWv11jcTR9dqgZ1eLEODbSpBoa9EECcojdUfJ52g PbkQSpslDfL7XyFlb6JkI8F12abgiY/8ucGR+LwxSkEm4vb7/WTIQ1mJ+wap7CU2GR7Pacyytg bv9nvAESokfzNAivfBXjwQ8kHdbvNtP0Y21mTagsU5WUkDzO7Fb/bHI4H4yL5CiAV6IBxXnu3Z 6gbhVLTbn306DXemrKXMjqB+pCp4Ir+en4qZg00I4zQrcE66mXaBtBBEM/s9nroAPOyILlGDPT Egw= X-SBRS: 2.7 X-MesageID: 10211654 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,325,1571716800"; d="scan'208";a="10211654" From: Anthony PERARD To: Date: Tue, 17 Dec 2019 10:58:57 +0000 Message-ID: <20191217105901.68158-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191217105901.68158-1-anthony.perard@citrix.com> References: <20191217105901.68158-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH v2 2/6] xen: Have Kconfig check $(CC)'s version X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Jan Beulich , Anthony PERARD Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This import several files from Linux v5.3 - scripts/Kconfig.include - scripts/clang-version.sh - scripts/gcc-version.sh and several config values from from Linux's init/Kconfig file. Files are copied into scripts/ directory because that's were the files are found in Linux tree, and also because we are going to import more of Kbuild from Linux which is located in scripts/. CONFIG_GCC_VERSION and CONFIG_CC_IS_CLANG are going to be use in follow-up patches. Signed-off-by: Anthony PERARD Acked-by: Andrew Cooper --- Notes: v2: - move the export CC* earlier in xen/Makefile, and add CXX to the list. xen/Kconfig | 17 ++++++++++++++++ xen/Makefile | 2 ++ xen/scripts/Kconfig.include | 39 ++++++++++++++++++++++++++++++++++++ xen/scripts/clang-version.sh | 19 ++++++++++++++++++ xen/scripts/gcc-version.sh | 20 ++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 xen/scripts/Kconfig.include create mode 100755 xen/scripts/clang-version.sh create mode 100755 xen/scripts/gcc-version.sh diff --git a/xen/Kconfig b/xen/Kconfig index 01067326b4e7..9f6512d65b08 100644 --- a/xen/Kconfig +++ b/xen/Kconfig @@ -4,9 +4,26 @@ # mainmenu "Xen/$(SRCARCH) $(XEN_FULLVERSION) Configuration" +source "scripts/Kconfig.include" + config BROKEN bool +config CC_IS_GCC + def_bool $(success,$(CC) --version | head -n 1 | grep -q gcc) + +config GCC_VERSION + int + default $(shell,$(BASEDIR)/scripts/gcc-version.sh $(CC)) if CC_IS_GCC + default 0 + +config CC_IS_CLANG + def_bool $(success,$(CC) --version | head -n 1 | grep -q clang) + +config CLANG_VERSION + int + default $(shell,$(BASEDIR)/scripts/clang-version.sh $(CC)) + source "arch/$(SRCARCH)/Kconfig" config DEFCONFIG_LIST diff --git a/xen/Makefile b/xen/Makefile index efbe9605e52b..c326fee5880e 100644 --- a/xen/Makefile +++ b/xen/Makefile @@ -18,6 +18,8 @@ export XEN_CONFIG_EXPERT ?= n PYTHON_INTERPRETER := $(word 1,$(shell which python3 python python2 2>/dev/null) python) export PYTHON ?= $(PYTHON_INTERPRETER) +export CC CXX LD + export BASEDIR := $(CURDIR) export XEN_ROOT := $(BASEDIR)/.. diff --git a/xen/scripts/Kconfig.include b/xen/scripts/Kconfig.include new file mode 100644 index 000000000000..8221095ca34b --- /dev/null +++ b/xen/scripts/Kconfig.include @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Kconfig helper macros + +# Convenient variables +comma := , +quote := " +squote := ' +empty := +space := $(empty) $(empty) +dollar := $ +right_paren := ) +left_paren := ( + +# $(if-success,,,) +# Return if exits with 0, otherwise. +if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") + +# $(success,) +# Return y if exits with 0, n otherwise +success = $(if-success,$(1),y,n) + +# $(failure,) +# Return n if exits with 0, y otherwise +failure = $(if-success,$(1),n,y) + +# $(cc-option,) +# Return y if the compiler supports , n otherwise +cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -E -x c /dev/null -o /dev/null) + +# $(ld-option,) +# Return y if the linker supports , n otherwise +ld-option = $(success,$(LD) -v $(1)) + +# check if $(CC) and $(LD) exist +$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found) +$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found) + +# gcc version including patch level +gcc-version := $(shell,$(BASEDIR)/scripts/gcc-version.sh $(CC)) diff --git a/xen/scripts/clang-version.sh b/xen/scripts/clang-version.sh new file mode 100755 index 000000000000..6fabf0695761 --- /dev/null +++ b/xen/scripts/clang-version.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# clang-version clang-command +# +# Print the compiler version of `clang-command' in a 5 or 6-digit form +# such as `50001' for clang-5.0.1 etc. + +compiler="$*" + +if ! ( $compiler --version | grep -q clang) ; then + echo 0 + 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) +PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL diff --git a/xen/scripts/gcc-version.sh b/xen/scripts/gcc-version.sh new file mode 100755 index 000000000000..ae353432539b --- /dev/null +++ b/xen/scripts/gcc-version.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# gcc-version gcc-command +# +# Print the gcc version of `gcc-command' in a 5 or 6-digit form +# such as `29503' for gcc-2.95.3, `30301' for gcc-3.3.1, etc. + +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." >&2 + printf "Usage:\n\t$0 \n" >&2 + exit 1 +fi + +MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1) +MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1) +PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1) +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL