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>
145 lines
3.9 KiB
Makefile
145 lines
3.9 KiB
Makefile
## @file
|
|
#
|
|
# The makefile can be invoked with
|
|
# HOST_ARCH = x86_64 or x64 for EM64T build
|
|
# HOST_ARCH = ia32 or IA32 for IA32 build
|
|
# HOST_ARCH = Arm or ARM for ARM build
|
|
#
|
|
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
ifndef HOST_ARCH
|
|
#
|
|
# If HOST_ARCH is not defined, then we use 'uname -m' to attempt
|
|
# try to figure out the appropriate HOST_ARCH.
|
|
#
|
|
uname_m = $(shell uname -m)
|
|
$(info Attempting to detect HOST_ARCH from 'uname -m': $(uname_m))
|
|
ifneq (,$(strip $(filter $(uname_m), x86_64 amd64)))
|
|
HOST_ARCH=X64
|
|
endif
|
|
ifeq ($(patsubst i%86,IA32,$(uname_m)),IA32)
|
|
HOST_ARCH=IA32
|
|
endif
|
|
ifneq (,$(findstring aarch64,$(uname_m)))
|
|
HOST_ARCH=AARCH64
|
|
else ifneq (,$(findstring arm64,$(uname_m)))
|
|
HOST_ARCH=AARCH64
|
|
else ifneq (,$(findstring arm,$(uname_m)))
|
|
HOST_ARCH=ARM
|
|
endif
|
|
ifneq (,$(findstring riscv64,$(uname_m)))
|
|
HOST_ARCH=RISCV64
|
|
endif
|
|
ifneq (,$(findstring loongarch64,$(uname_m)))
|
|
HOST_ARCH=LOONGARCH64
|
|
endif
|
|
ifndef HOST_ARCH
|
|
$(info Could not detected HOST_ARCH from uname results)
|
|
$(error HOST_ARCH is not defined!)
|
|
endif
|
|
$(info Detected HOST_ARCH of $(HOST_ARCH) using uname.)
|
|
endif
|
|
|
|
CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
|
|
LINUX:=$(findstring Linux, $(shell uname -s))
|
|
DARWIN:=$(findstring Darwin, $(shell uname -s))
|
|
CLANG:=$(shell $(CC) --version | grep clang)
|
|
ifneq ($(CLANG),)
|
|
CC ?= $(CLANG_BIN)clang
|
|
CXX ?= $(CLANG_BIN)clang++
|
|
AS ?= $(CLANG_BIN)clang
|
|
AR ?= $(CLANG_BIN)llvm-ar
|
|
LD ?= $(CLANG_BIN)llvm-ld
|
|
else ifeq ($(origin CC),default)
|
|
CC = gcc
|
|
CXX = g++
|
|
AS = gcc
|
|
AR = ar
|
|
LD = ld
|
|
endif
|
|
LINKER ?= $(CC)
|
|
ifeq ($(HOST_ARCH), IA32)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/Ia32/
|
|
|
|
else ifeq ($(HOST_ARCH), X64)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/X64/
|
|
|
|
else ifeq ($(HOST_ARCH), ARM)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/Arm/
|
|
|
|
else ifeq ($(HOST_ARCH), AARCH64)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/AArch64/
|
|
|
|
else ifeq ($(HOST_ARCH), RISCV64)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/RiscV64/
|
|
|
|
else ifeq ($(HOST_ARCH), LOONGARCH64)
|
|
ARCH_INCLUDE = -I $(MAKEROOT)/Include/LoongArch64/
|
|
|
|
else
|
|
$(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)
|
|
CPPFLAGS = $(INCLUDE)
|
|
|
|
# keep EXTRA_OPTFLAGS last
|
|
BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
|
|
|
|
ifeq ($(DARWIN),Darwin)
|
|
# assume clang or clang compatible flags on OS X
|
|
CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
|
|
-Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
|
|
else
|
|
ifneq ($(CLANG),)
|
|
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
|
|
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
|
|
ifneq ($(CLANG),)
|
|
LDFLAGS =
|
|
CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
|
|
else
|
|
LDFLAGS =
|
|
CXXFLAGS = -Wno-unused-result
|
|
endif
|
|
ifeq ($(HOST_ARCH), IA32)
|
|
#
|
|
# Snow Leopard is a 32-bit and 64-bit environment. uname -m returns i386, but gcc defaults
|
|
# to x86_64. So make sure tools match uname -m. You can manual have a 64-bit kernal on Snow Leopard
|
|
# so only do this is uname -m returns i386.
|
|
#
|
|
ifeq ($(DARWIN),Darwin)
|
|
CFLAGS += -arch i386
|
|
CPPFLAGS += -arch i386
|
|
LDFLAGS += -arch i386
|
|
endif
|
|
endif
|
|
|
|
# keep BUILD_OPTFLAGS last
|
|
CFLAGS += $(BUILD_OPTFLAGS)
|
|
CXXFLAGS += $(BUILD_OPTFLAGS)
|
|
|
|
# keep EXTRA_LDFLAGS last
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
|
|
.PHONY: all
|
|
.PHONY: install
|
|
.PHONY: clean
|
|
|
|
all:
|
|
|
|
$(MAKEROOT)/libs:
|
|
mkdir $(MAKEROOT)/libs
|
|
|
|
$(MAKEROOT)/bin:
|
|
mkdir $(MAKEROOT)/bin
|