public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Rebecca Cran" <quic_rcran@quicinc.com>
To: <devel@edk2.groups.io>, Andrew Fish <afish@apple.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	"Yuwei Chen" <yuwei.chen@intel.com>
Cc: Rebecca Cran <rebecca@quicinc.com>
Subject: [PATCH 2/3] BaseTools: Improve detection of users wanting to build using clang
Date: Thu, 16 Feb 2023 20:51:00 -0700	[thread overview]
Message-ID: <20230217035101.880854-3-rebecca@quicinc.com> (raw)
In-Reply-To: <20230217035101.880854-1-rebecca@quicinc.com>

In https://bugzilla.tianocore.org/show_bug.cgi?id=2842 clang support was
added by having users specify "make CXX=llvm" when building BaseTools.

Improve the detection of when a user wants to use the clang toolchain:
instead of checking if CXX=llvm (which in most cases doesn't make sense,
because the C++ compiler won't be run via an 'llvm' command), run
'$(CC) --version | grep clang' to see if the compiler's version string
contains 'clang', and if so configure the environment.

This provides flexibility to specify for example CC=clang-17
CXX=clang++-17 if multiple versions are installed.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
---
 BaseTools/Source/C/DevicePath/GNUmakefile          | 3 ++-
 BaseTools/Source/C/Makefiles/header.makefile       | 7 ++++---
 BaseTools/Source/C/VfrCompile/GNUmakefile          | 3 ++-
 BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile | 2 +-
 BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile   | 3 ++-
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile
index 3afc7fc0504e..f61b1b2f171d 100644
--- a/BaseTools/Source/C/DevicePath/GNUmakefile
+++ b/BaseTools/Source/C/DevicePath/GNUmakefile
@@ -14,8 +14,9 @@ OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o  DevicePathUtili
 include $(MAKEROOT)/Makefiles/app.makefile
 
 GCCVERSION = $(shell $(CC) -dumpversion | awk -F'.' '{print $$1}')
+CLANG := $(shell $(CC) --version | grep clang)
 ifneq ("$(GCCVERSION)", "5")
-ifneq ($(CXX), llvm)
+ifeq ($(CLANG),)
 ifneq ($(DARWIN),Darwin)
 # gcc 12 trips over device path handling
 CFLAGS += -Wno-error=stringop-overflow
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index 347918c7d4fa..bcc2791998b0 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -44,7 +44,8 @@ endif
 CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
 LINUX:=$(findstring Linux, $(shell uname -s))
 DARWIN:=$(findstring Darwin, $(shell uname -s))
-ifeq ($(CXX), llvm)
+CLANG:=$(shell $(CC) --version | grep clang)
+ifneq ($(CLANG),)
 CC ?= $(CLANG_BIN)clang
 CXX ?= $(CLANG_BIN)clang++
 AS ?= $(CLANG_BIN)clang
@@ -91,7 +92,7 @@ ifeq ($(DARWIN),Darwin)
 CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
 -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
 else
-ifeq ($(CXX), llvm)
+ifneq ($(CLANG),)
 CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
 -fno-delete-null-pointer-checks -Wall -Werror \
 -Wno-deprecated-declarations -Wno-self-assign \
@@ -103,7 +104,7 @@ CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
 -Wno-unused-result -nostdlib -g
 endif
 endif
-ifeq ($(CXX), llvm)
+ifneq ($(CLANG),)
 LDFLAGS =
 CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
 else
diff --git a/BaseTools/Source/C/VfrCompile/GNUmakefile b/BaseTools/Source/C/VfrCompile/GNUmakefile
index 9fbaaaba21d7..fdd19f55f77e 100644
--- a/BaseTools/Source/C/VfrCompile/GNUmakefile
+++ b/BaseTools/Source/C/VfrCompile/GNUmakefile
@@ -16,7 +16,8 @@ TOOL_INCLUDE = -I Pccts/h
 #OBJECTS = VfrSyntax.o VfrServices.o DLGLexer.o EfiVfrParser.o ATokenBuffer.o DLexerBase.o AParser.o
 OBJECTS = AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \
           VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.o
-ifeq ($(CXX), llvm)
+CLANG:=$(shell $(CC) --version | grep clang)
+ifneq ($(CLANG),)
 VFR_CPPFLAGS = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
 else
 VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
index 558d2f7b0111..42b603571fab 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
@@ -164,7 +164,7 @@ PCCTS_H=../h
 #
 #   UNIX  (default)
 #
-ifeq ($(CXX), llvm)
+ifneq ($(CLANG),)
 CC?=$(CLANG_BIN)clang
 else ifeq ($(origin CC),default)
 CC=gcc
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
index e214b35ab5e1..69dac6a59789 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
@@ -114,7 +114,8 @@ PCCTS_H=../h
 #
 #   UNIX
 #
-ifeq ($(CXX), llvm)
+CLANG:=$(shell $(CC) --version | grep clang)
+ifneq ($(CLANG),)
 CC?=$(CLANG_BIN)clang
 else ifeq ($(origin CC),default)
 CC=cc
-- 
2.30.2


  parent reply	other threads:[~2023-02-17  3:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17  3:50 [PATCH 0/3] BaseTools: allow users to override CC and CXX on the make command line Rebecca Cran
2023-02-17  3:50 ` [PATCH 1/3] BaseTools: Allow users to specify compiler to use with make CC= CXX= Rebecca Cran
2023-03-15 10:07   ` [edk2-devel] " Gerd Hoffmann
2023-03-17 10:43     ` Rebecca Cran
2023-03-20  9:35       ` Gerd Hoffmann
2023-03-20 13:13         ` Rebecca Cran
2023-02-17  3:51 ` Rebecca Cran [this message]
2023-03-15 10:11   ` [edk2-devel] [PATCH 2/3] BaseTools: Improve detection of users wanting to build using clang Gerd Hoffmann
2023-02-17  3:51 ` [PATCH 3/3] BaseTools: Build against C++14 when building with clang Rebecca Cran
2023-03-15 10:11   ` [edk2-devel] " Gerd Hoffmann
2023-03-09 15:47 ` [edk2-devel] [PATCH 0/3] BaseTools: allow users to override CC and CXX on the make command line Rebecca Cran
     [not found] ` <174ACADCDC6439C2.24021@groups.io>
2023-03-14 16:16   ` Rebecca Cran
2023-03-23  1:09     ` 回复: " gaoliming
     [not found]     ` <174EE719E87C3CB3.19937@groups.io>
2023-03-24  4:57       ` gaoliming
2023-03-24 21:39         ` Rebecca Cran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230217035101.880854-3-rebecca@quicinc.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox