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 <rebe...@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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#100297): https://edk2.groups.io/g/devel/message/100297 Mute This Topic: https://groups.io/mt/97022153/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-