blob: c0d2cbb7bcb52d6aa193acc0779882df9851fde1 [file] [log] [blame]
# The following variables will likely need to be modified, depending on where
# and how you built LLVM & Clang. They can be overridden in a command-line
# invocation of make, like:
#
# make LLVM_SRC_PATH=<path> LLVM_BIN_PATH=<path> \
# LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
# BINUTILS_BIN_PATH=<path> ...
#
# LLVM_SRC_PATH is the path to the root of the checked out source code. This
# directory should contain the configure script, the include/ and lib/
# directories of LLVM, Clang in tools/clang/, etc.
# Alternatively, if you're building vs. a binary download of LLVM, then
# LLVM_SRC_PATH can point to the main untarred directory.
LLVM_SRC_PATH ?= ../llvm
# LLVM_BIN_PATH is the directory where binaries are placed by the LLVM build
# process. It should contain the tools like clang, clang-format, llc,
# llvm-as, llvm-config, llvm-mc, pnacl-bcdis, and pnacl-freeze.
# It also contains developer libraries like libLLVMSupport.a.
# The default reflects a configure + make build.
LLVM_BIN_PATH ?= $(shell readlink -e \
../../out/llvm_x86_64_linux_work/Release+Asserts/bin)
# PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain.
# This is used as the default root for finding binutils, libcxx, etc.
PNACL_TOOLCHAIN_ROOT = $(shell readlink -e \
../../../toolchain/linux_x86/pnacl_newlib)
# CLANG_PATH is the location of the clang compiler to use for building
# the host binaries.
CLANG_PATH ?= $(shell readlink -e \
../../../../third_party/llvm-build/Release+Asserts/bin)
# LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should
# contain header files and corresponding libraries. This is used for
# building the host binaries in conjuction with clang.
LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT)
# The location of binutils tools (e.g., objdump) for testing.
BINUTILS_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin)
HOST_ARCH ?= x86_64
ifeq ($(HOST_ARCH),x86_64)
HOST_FLAGS = -m64 -stdlib=libc++
else
ifeq ($(HOST_ARCH),x86)
HOST_FLAGS = -m32 -stdlib=libc++
endif
endif
ifdef DEBUG
OBJDIR = build/Debug
OPTLEVEL = -O0
else
OBJDIR = build/Release
OPTLEVEL = -O2 -ffunction-sections -fdata-sections
endif
# The list of CXX defines that are dependent on build parameters.
CXX_DEFINES =
CXX_EXTRA =
LD_EXTRA =
ifdef MINIMAL
NOASSERT = 1
OBJDIR := $(OBJDIR)+Min
CXX_DEFINES += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
-DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 \
-DALLOW_MINIMAL_BUILD=1
else
CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
-DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 \
-DALLOW_MINIMAL_BUILD=0
endif
ifdef NOASSERT
ASSERTIONS = -DNDEBUG
else
ASSERTIONS =
OBJDIR := $(OBJDIR)+Asserts
endif
ifdef TSAN
OBJDIR := $(OBJDIR)+TSan
CXX_EXTRA += -fsanitize=thread
LD_EXTRA += -fsanitize=thread
endif
$(info -----------------------------------------------)
$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
$(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH))
$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
$(info Using CLANG_PATH = $(CLANG_PATH))
$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
$(info Using BINUTILS_BIN_PATH = $(BINUTILS_BIN_PATH))
$(info Using HOST_ARCH = $(HOST_ARCH))
$(info -----------------------------------------------)
LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags`
LLVM_LDFLAGS := `$(LLVM_BIN_PATH)/llvm-config --libs` \
`$(LLVM_BIN_PATH)/llvm-config --ldflags` \
`$(LLVM_BIN_PATH)/llvm-config --system-libs`
# It's recommended that CXX matches the compiler you used to build LLVM itself.
CCACHE := `command -v ccache`
CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
CXXFLAGS := $(LLVM_CXXFLAGS) -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
-fno-exceptions $(OPTLEVEL) $(ASSERTIONS) $(CXX_DEFINES) -g \
$(HOST_FLAGS) -pedantic -Wno-error=unused-parameter \
-I$(LIBCXX_INSTALL_PATH)/include/c++/v1 $(CXX_EXTRA)
LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
$(LD_EXTRA)
SRCS = \
assembler.cpp \
assembler_ia32.cpp \
IceCfg.cpp \
IceCfgNode.cpp \
IceELFObjectWriter.cpp \
IceELFSection.cpp \
IceFixups.cpp \
IceGlobalContext.cpp \
IceGlobalInits.cpp \
IceInst.cpp \
IceInstX8632.cpp \
IceIntrinsics.cpp \
IceLiveness.cpp \
IceOperand.cpp \
IceRegAlloc.cpp \
IceRNG.cpp \
IceTargetLowering.cpp \
IceTargetLoweringX8632.cpp \
IceThreading.cpp \
IceTimerTree.cpp \
IceTranslator.cpp \
IceTypes.cpp \
main.cpp \
PNaClTranslator.cpp
ifndef MINIMAL
SRCS += IceConverter.cpp \
IceTypeConverter.cpp
endif
OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
UNITTEST_SRCS = \
BitcodeMunge.cpp \
IceELFSectionTest.cpp \
IceParseInstsTest.cpp
UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
# Keep all the first target so it's the default.
all: $(OBJDIR)/pnacl-sz make_symlink runtime
# Creates symbolic link so that testing is easier. Also runs
# pnacl-sz to verify that the defines flags have valid values,
# as well as describe the corresponding build attributes.
make_symlink: $(OBJDIR)/pnacl-sz
rm -rf pnacl-sz
ln -s $(OBJDIR)/pnacl-sz
@echo "Build Attributes:"
@$(OBJDIR)/pnacl-sz --build-atts
.PHONY: all make_symlink runtime bloat
$(OBJDIR)/pnacl-sz: $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
-Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
$(CXX) -c $(CXXFLAGS) $< -o $@
$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -lgtest -lgtest_main -ldl \
-Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
unittest/*.h src/*.h src/*.def
$(CXX) -c $(CXXFLAGS) \
-Isrc/ \
-I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
-DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
$< -o $@
$(OBJS): | $(OBJDIR)
$(UNITTEST_OBJS): | $(OBJDIR)/unittest
$(OBJDIR):
@mkdir -p $@
$(OBJDIR)/unittest: $(OBJDIR)
@mkdir -p $@
RT_SRC := runtime/szrt.c runtime/szrt_ll.ll
RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o
runtime: $(RT_OBJ)
# Use runtime.is.built so that build-runtime.py is invoked only once
# even in a parallel build.
.INTERMEDIATE: runtime.is.built
$(RT_OBJ): runtime.is.built
runtime.is.built: $(RT_SRC)
@echo ================ Building Subzero runtime ================
./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
check-lit: $(OBJDIR)/pnacl-sz make_symlink
LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
BINUTILS_BIN_PATH=$(BINUTILS_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
ifdef MINIMAL
check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
@echo "Crosstests disabled, minimal build"
else
check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
# Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
# For (slow) sandboxed tests, limit to Om1/sse4.1.
./pydir/crosstest_generator.py -v --lit \
-i native,sse2 -i native,sse4.1,test_vector_ops \
-i sandbox,sse4.1,Om1
LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
endif
check-unit: $(OBJDIR)/run_unittests
$(OBJDIR)/run_unittests
check: check-lit check-unit check-xtest
FORMAT_BLACKLIST =
# Add one of the following lines for each source file to ignore.
FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
format:
$(LLVM_BIN_PATH)/clang-format -style=LLVM -i \
`find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
format-diff:
git diff -U0 `git merge-base HEAD master` | \
PATH=$(LLVM_BIN_PATH):$(PATH) \
$(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
-p1 -style=LLVM -i
bloat: make_symlink
nm -C -S -l pnacl-sz | \
bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
@echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
clean:
rm -rf pnacl-sz *.o $(OBJDIR) build/pnacl-sz.bloat.json
clean-all: clean
rm -rf build/