BaseTools: Allow users to specify compiler to use with make CC= CXX=

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 08:40:46 -07:00 committed by mergify[bot]
parent cdd79996c2
commit 206168e83f
9 changed files with 59 additions and 59 deletions

View File

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

View File

@ -24,4 +24,4 @@ OBJECTS = \
include $(MAKEROOT)/Makefiles/app.makefile
BUILD_CFLAGS += -D_7ZIP_ST
CFLAGS += -D_7ZIP_ST

View File

@ -15,7 +15,7 @@ APPLICATION = $(MAKEROOT)/bin/$(APPNAME)
all: $(MAKEROOT)/bin $(APPLICATION)
$(APPLICATION): $(OBJECTS)
$(LINKER) -o $(APPLICATION) $(BUILD_LFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
$(LINKER) -o $(APPLICATION) $(LDFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
$(OBJECTS): $(MAKEROOT)/Include/Common/BuildVersion.h

View File

@ -15,13 +15,13 @@ install: $(MAKEROOT)/libs-$(HOST_ARCH) $(LIBRARY)
cp $(LIBRARY) $(MAKEROOT)/libs-$(HOST_ARCH)
$(LIBRARY): $(OBJECTS)
$(BUILD_AR) crs $@ $^
$(AR) crs $@ $^
%.o : %.c
$(BUILD_CC) -c $(BUILD_CPPFLAGS) $(BUILD_CFLAGS) $< -o $@
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
%.o : %.cpp
$(BUILD_CXX) -c $(BUILD_CPPFLAGS) $(BUILD_CXXFLAGS) $< -o $@
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
.PHONY: clean
clean:

View File

@ -45,19 +45,19 @@ CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
LINUX:=$(findstring Linux, $(shell uname -s))
DARWIN:=$(findstring Darwin, $(shell uname -s))
ifeq ($(CXX), llvm)
BUILD_CC ?= $(CLANG_BIN)clang
BUILD_CXX ?= $(CLANG_BIN)clang++
BUILD_AS ?= $(CLANG_BIN)clang
BUILD_AR ?= $(CLANG_BIN)llvm-ar
BUILD_LD ?= $(CLANG_BIN)llvm-ld
CC ?= $(CLANG_BIN)clang
CXX ?= $(CLANG_BIN)clang++
AS ?= $(CLANG_BIN)clang
AR ?= $(CLANG_BIN)llvm-ar
LD ?= $(CLANG_BIN)llvm-ld
else
BUILD_CC ?= gcc
BUILD_CXX ?= g++
BUILD_AS ?= gcc
BUILD_AR ?= ar
BUILD_LD ?= ld
CC ?= gcc
CXX ?= g++
AS ?= gcc
AR ?= ar
LD ?= ld
endif
LINKER ?= $(BUILD_CC)
LINKER ?= $(CC)
ifeq ($(HOST_ARCH), IA32)
ARCH_INCLUDE = -I $(MAKEROOT)/Include/Ia32/
@ -81,34 +81,34 @@ $(error Bad HOST_ARCH)
endif
INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKEROOT)/Include/ -I $(MAKEROOT)/Include/IndustryStandard -I $(MAKEROOT)/Common/ -I .. -I . $(ARCH_INCLUDE)
BUILD_CPPFLAGS = $(INCLUDE)
CPPFLAGS = $(INCLUDE)
# keep EXTRA_OPTFLAGS last
BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
ifeq ($(DARWIN),Darwin)
# assume clang or clang compatible flags on OS X
BUILD_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
else
ifeq ($(CXX), llvm)
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-fno-delete-null-pointer-checks -Wall -Werror \
-Wno-deprecated-declarations -Wno-self-assign \
-Wno-unused-result -nostdlib -g
else
BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
-fno-delete-null-pointer-checks -Wall -Werror \
-Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict \
-Wno-unused-result -nostdlib -g
endif
endif
ifeq ($(CXX), llvm)
BUILD_LFLAGS =
BUILD_CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
LDFLAGS =
CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
else
BUILD_LFLAGS =
BUILD_CXXFLAGS = -Wno-unused-result
LDFLAGS =
CXXFLAGS = -Wno-unused-result
endif
ifeq ($(HOST_ARCH), IA32)
#
@ -117,18 +117,18 @@ ifeq ($(HOST_ARCH), IA32)
# so only do this is uname -m returns i386.
#
ifeq ($(DARWIN),Darwin)
BUILD_CFLAGS += -arch i386
BUILD_CPPFLAGS += -arch i386
BUILD_LFLAGS += -arch i386
CFLAGS += -arch i386
CPPFLAGS += -arch i386
LDFLAGS += -arch i386
endif
endif
# keep BUILD_OPTFLAGS last
BUILD_CFLAGS += $(BUILD_OPTFLAGS)
BUILD_CXXFLAGS += $(BUILD_OPTFLAGS)
CFLAGS += $(BUILD_OPTFLAGS)
CXXFLAGS += $(BUILD_OPTFLAGS)
# keep EXTRA_LDFLAGS last
BUILD_LFLAGS += $(EXTRA_LDFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
.PHONY: all
.PHONY: install

View File

@ -17,9 +17,9 @@ TOOL_INCLUDE = -I Pccts/h
OBJECTS = AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \
VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.o
ifeq ($(CXX), llvm)
VFR_CPPFLAGS = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)
VFR_CPPFLAGS = -Wno-deprecated-register -std=c++14 -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
else
VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)
VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
endif
# keep BUILD_OPTFLAGS last
VFR_CXXFLAGS = $(BUILD_OPTFLAGS)
@ -27,7 +27,7 @@ VFR_CXXFLAGS = $(BUILD_OPTFLAGS)
# keep EXTRA_LDFLAGS last
VFR_LFLAGS = $(EXTRA_LDFLAGS)
LINKER = $(BUILD_CXX)
LINKER = $(CXX)
EXTRA_CLEAN_OBJECTS = EfiVfrParser.cpp EfiVfrParser.h VfrParser.dlg VfrTokens.h VfrLexer.cpp VfrLexer.h VfrSyntax.cpp tokens.h
@ -60,16 +60,16 @@ Pccts/dlg/dlg:
BIN_DIR='.' $(MAKE) -C Pccts/dlg
ATokenBuffer.o: Pccts/h/ATokenBuffer.cpp
$(BUILD_CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
$(CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
DLexerBase.o: Pccts/h/DLexerBase.cpp
$(BUILD_CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
$(CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
AParser.o: Pccts/h/AParser.cpp
$(BUILD_CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
$(CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
VfrSyntax.o: VfrSyntax.cpp
$(BUILD_CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
$(CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
clean: localClean

View File

@ -157,7 +157,7 @@ PCCTS_H=../h
# $(DLG) -C2 parser.dlg scan.c
#
#set.$(OBJ_EXT): $(SET)/set.c
# $(BUILD_CC) $(BUILD_CFLAGS) -c $(OUT_OBJ)set.$(OBJ_EXT) $(SET)/set.c
# $(CC) $(CFLAGS) -c $(OUT_OBJ)set.$(OBJ_EXT) $(SET)/set.c
@ -165,17 +165,17 @@ PCCTS_H=../h
# UNIX (default)
#
ifeq ($(CXX), llvm)
BUILD_CC?=$(CLANG_BIN)clang
CC?=$(CLANG_BIN)clang
else
BUILD_CC?=gcc
CC?=gcc
endif
COPT=-O
ANTLR=${BIN_DIR}/antlr
DLG=${BIN_DIR}/dlg
OBJ_EXT=o
OUT_OBJ = -o
BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536
BUILD_CPPFLAGS=
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536
CPPFLAGS=
#
# SGI Users, use this CFLAGS
#
@ -184,7 +184,7 @@ OBJ=antlr.o scan.o err.o bits.o build.o fset2.o fset.o gen.o \
globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o
$(BIN_DIR)/antlr : $(OBJ) $(SRC)
$(BUILD_CC) $(BUILD_CFLAGS) -o $(BIN_DIR)/antlr $(OBJ)
$(CC) $(CFLAGS) -o $(BIN_DIR)/antlr $(OBJ)
# what files does PCCTS generate (both ANTLR and DLG)
PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h
@ -207,10 +207,10 @@ scan.o : scan.c mode.h tokens.h
# $(DLG) -C2 parser.dlg scan.c
set.o : $(SET)/set.c
$(BUILD_CC) $(BUILD_CFLAGS) -c -o set.o $(SET)/set.c
$(CC) $(CFLAGS) -c -o set.o $(SET)/set.c
%.o : %.c
$(BUILD_CC) -c $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $< -o $@
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
#
# ****** These next targets are common to UNIX and PC world ********

View File

@ -35,7 +35,7 @@ PCCTS_H=../h
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#$(DEF_FILE) $(LDFLAGS) ;
#<<
# bind $@ c:\os2\doscalls.lib
# copy *.exe ..\bin
@ -59,7 +59,7 @@ PCCTS_H=../h
#$@ /Tde /c
#
#$(LIBS)
#$(DEF_FILE) $(LFLAGS) ;
#$(DEF_FILE) $(LDFLAGS) ;
#|
# copy *.exe ..\bin
#
@ -83,7 +83,7 @@ PCCTS_H=../h
#
#$(LIBS: = +^
#)
#$(DEF_FILE) $(LFLAGS) ;
#$(DEF_FILE) $(LDFLAGS) ;
#<<
# copy *.exe ..\bin
#
@ -122,15 +122,15 @@ endif
COPT=-O
ANTLR=${BIN_DIR}/antlr
DLG=${BIN_DIR}/dlg
BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536
BUILD_CPPFLAGS=
CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536
CPPFLAGS=
OBJ_EXT=o
OUT_OBJ = -o
OBJ = dlg_p.o dlg_a.o main.o err.o set.o support.o output.o \
relabel.o automata.o
$(BIN_DIR)/dlg : $(OBJ) $(SRC)
$(BUILD_CC) $(BUILD_CFLAGS) -o $(BIN_DIR)/dlg $(OBJ)
$(CC) $(CFLAGS) -o $(BIN_DIR)/dlg $(OBJ)
SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
relabel.c automata.c
@ -142,19 +142,19 @@ SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \
# $(DLG) -C2 parser.dlg dlg_a.c
dlg_p.$(OBJ_EXT) : dlg_p.c dlg.h tokens.h mode.h
$(BUILD_CC) $(BUILD_CFLAGS) -c dlg_p.c
$(CC) $(CFLAGS) -c dlg_p.c
dlg_a.$(OBJ_EXT) : dlg_a.c dlg.h tokens.h mode.h
$(BUILD_CC) $(BUILD_CFLAGS) -c dlg_a.c
$(CC) $(CFLAGS) -c dlg_a.c
main.$(OBJ_EXT) : main.c dlg.h
$(BUILD_CC) $(BUILD_CFLAGS) -c main.c
$(CC) $(CFLAGS) -c main.c
set.$(OBJ_EXT) : $(SET)/set.c
$(BUILD_CC) -c $(BUILD_CFLAGS) $(SET)/set.c
$(CC) -c $(CFLAGS) $(SET)/set.c
%.o : %.c
$(BUILD_CC) -c $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) $< -o $@
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
lint:
lint *.c

View File

@ -89,7 +89,7 @@ PcdMakefileHeader = '''
'''
WindowsCFLAGS = 'CFLAGS = $(CFLAGS) /wd4200 /wd4034 /wd4101 '
LinuxCFLAGS = 'BUILD_CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
LinuxCFLAGS = 'CFLAGS += -Wno-pointer-to-int-cast -Wno-unused-variable '
PcdMakefileEnd = '''
!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.common
!INCLUDE $(BASE_TOOLS_PATH)\Source\C\Makefiles\ms.app