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

@@ -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