BaseTools: Allow users to build with clang using CC=clang CXX=clang++

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

The Makefile then sees that and sets CC=$(CLANG_BIN)clang and
CXX=$(CLANG_BIN)clang++. That requires that the executables 'clang' and
'clang++' exist and for example aren't named 'clang-17' and
'clang++-17'. Also, it's an unusual way of specifying the compiler,
since many users will expect to be able to override CC and CXX on the
make command line.

Rework the BaseTools Makefiles removing the 'BUILD_' prefix (BUILD_CC
and BUILD_CXX) and using the standard name 'LDFLAGS' instead of
'LFLAGS'. This allows clang to be used by running
'make -C BaseTools CC=clang CXX=clang++'.

Signed-off-by: Rebecca Cran <rebecca@quicinc.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Rebecca Cran 2023-02-16 09:34:32 -07:00 committed by mergify[bot]
parent 206168e83f
commit 728ff1da33
5 changed files with 22 additions and 18 deletions

View File

@ -14,8 +14,9 @@ OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o DevicePathUtili
include $(MAKEROOT)/Makefiles/app.makefile include $(MAKEROOT)/Makefiles/app.makefile
GCCVERSION = $(shell $(CC) -dumpversion | awk -F'.' '{print $$1}') GCCVERSION = $(shell $(CC) -dumpversion | awk -F'.' '{print $$1}')
CLANG := $(shell $(CC) --version | grep clang)
ifneq ("$(GCCVERSION)", "5") ifneq ("$(GCCVERSION)", "5")
ifneq ($(CXX), llvm) ifeq ($(CLANG),)
ifneq ($(DARWIN),Darwin) ifneq ($(DARWIN),Darwin)
# gcc 12 trips over device path handling # gcc 12 trips over device path handling
CFLAGS += -Wno-error=stringop-overflow CFLAGS += -Wno-error=stringop-overflow

View File

@ -44,18 +44,19 @@ endif
CYGWIN:=$(findstring CYGWIN, $(shell uname -s)) CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
LINUX:=$(findstring Linux, $(shell uname -s)) LINUX:=$(findstring Linux, $(shell uname -s))
DARWIN:=$(findstring Darwin, $(shell uname -s)) DARWIN:=$(findstring Darwin, $(shell uname -s))
ifeq ($(CXX), llvm) CLANG:=$(shell $(CC) --version | grep clang)
ifneq ($(CLANG),)
CC ?= $(CLANG_BIN)clang CC ?= $(CLANG_BIN)clang
CXX ?= $(CLANG_BIN)clang++ CXX ?= $(CLANG_BIN)clang++
AS ?= $(CLANG_BIN)clang AS ?= $(CLANG_BIN)clang
AR ?= $(CLANG_BIN)llvm-ar AR ?= $(CLANG_BIN)llvm-ar
LD ?= $(CLANG_BIN)llvm-ld LD ?= $(CLANG_BIN)llvm-ld
else else ifeq ($(origin CC),default)
CC ?= gcc CC = gcc
CXX ?= g++ CXX = g++
AS ?= gcc AS = gcc
AR ?= ar AR = ar
LD ?= ld LD = ld
endif endif
LINKER ?= $(CC) LINKER ?= $(CC)
ifeq ($(HOST_ARCH), IA32) ifeq ($(HOST_ARCH), IA32)
@ -91,7 +92,7 @@ ifeq ($(DARWIN),Darwin)
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \ CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
-Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
else else
ifeq ($(CXX), llvm) ifneq ($(CLANG),)
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \ CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-fno-delete-null-pointer-checks -Wall -Werror \ -fno-delete-null-pointer-checks -Wall -Werror \
-Wno-deprecated-declarations -Wno-self-assign \ -Wno-deprecated-declarations -Wno-self-assign \
@ -103,7 +104,7 @@ CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-Wno-unused-result -nostdlib -g -Wno-unused-result -nostdlib -g
endif endif
endif endif
ifeq ($(CXX), llvm) ifneq ($(CLANG),)
LDFLAGS = LDFLAGS =
CXXFLAGS = -Wno-deprecated-register -Wno-unused-result CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
else else

View File

@ -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 = 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 \ OBJECTS = AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \
VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.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 -std=c++14 -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS) VFR_CPPFLAGS = -Wno-deprecated-register -std=c++14 -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
else else
VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS) VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)

View File

@ -164,10 +164,10 @@ PCCTS_H=../h
# #
# UNIX (default) # UNIX (default)
# #
ifeq ($(CXX), llvm) ifneq ($(CLANG),)
CC?=$(CLANG_BIN)clang CC?=$(CLANG_BIN)clang
else else ifeq ($(origin CC),default)
CC?=gcc CC=gcc
endif endif
COPT=-O COPT=-O
ANTLR=${BIN_DIR}/antlr ANTLR=${BIN_DIR}/antlr

View File

@ -114,10 +114,11 @@ PCCTS_H=../h
# #
# UNIX # UNIX
# #
ifeq ($(CXX), llvm) CLANG:=$(shell $(CC) --version | grep clang)
BUILD_CC?=$(CLANG_BIN)clang ifneq ($(CLANG),)
else CC?=$(CLANG_BIN)clang
BUILD_CC?=cc else ifeq ($(origin CC),default)
CC=gcc
endif endif
COPT=-O COPT=-O
ANTLR=${BIN_DIR}/antlr ANTLR=${BIN_DIR}/antlr