| # 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> ... | 
 | # | 
 |  | 
 | # 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 opt, llc and clang. The default | 
 | # reflects a debug build with autotools (configure & make). | 
 | LLVM_BIN_PATH ?= $(shell readlink -e \ | 
 | 	../../out/llvm_x86_64_linux_work/Release+Asserts/bin) | 
 |  | 
 | # LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should | 
 | # contain header files and corresponding libraries | 
 | LIBCXX_INSTALL_PATH ?= $(shell readlink -e \ | 
 | 	../../../toolchain/linux_x86/pnacl_newlib) | 
 |  | 
 | # CLANG_PATH is the location of the clang compiler to use. | 
 | CLANG_PATH ?= $(shell readlink -e \ | 
 | 	../../../../third_party/llvm-build/Release+Asserts/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 | 
 | endif | 
 |  | 
 | # The list of CXX defines that are dependent on build parameters. | 
 | CXX_DEFINES = | 
 |  | 
 | ifdef MINIMAL | 
 |   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 | 
 | 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 | 
 | endif | 
 |  | 
 | ifdef NOASSERT | 
 |   ASSERTIONS = -DNDEBUG | 
 | else | 
 |   ASSERTIONS = | 
 |   OBJDIR := $(OBJDIR)+Asserts | 
 | endif | 
 |  | 
 | $(info -----------------------------------------------) | 
 | $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH)) | 
 | $(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH)) | 
 | $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH)) | 
 | $(info Using CLANG_PATH = $(CLANG_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=c++11 -Wall -Wextra -Werror -fno-rtti \ | 
 | 	-fno-exceptions $(OPTLEVEL) $(ASSERTIONS) $(CXX_DEFINES) -g \ | 
 | 	$(HOST_FLAGS) -Wno-error=unused-parameter \ | 
 | 	-I$(LIBCXX_INSTALL_PATH)/include/c++/v1 | 
 | LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib | 
 |  | 
 | SRCS = \ | 
 | 	assembler.cpp \ | 
 | 	assembler_ia32.cpp \ | 
 | 	IceCfg.cpp \ | 
 | 	IceCfgNode.cpp \ | 
 | 	IceGlobalContext.cpp \ | 
 | 	IceGlobalInits.cpp \ | 
 | 	IceInst.cpp \ | 
 | 	IceInstX8632.cpp \ | 
 | 	IceIntrinsics.cpp \ | 
 | 	IceLiveness.cpp \ | 
 | 	IceMemoryRegion.cpp \ | 
 | 	IceOperand.cpp \ | 
 | 	IceRegAlloc.cpp \ | 
 | 	IceRNG.cpp \ | 
 | 	IceTargetLowering.cpp \ | 
 | 	IceTargetLoweringX8632.cpp \ | 
 | 	IceTimerTree.cpp \ | 
 | 	IceTranslator.cpp \ | 
 | 	IceTypeConverter.cpp \ | 
 | 	IceTypes.cpp \ | 
 | 	llvm2ice.cpp \ | 
 | 	PNaClTranslator.cpp | 
 |  | 
 | ifndef MINIMAL | 
 |   SRCS += IceConverter.cpp | 
 | endif | 
 |  | 
 | OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS)) | 
 |  | 
 | # Keep all the first target so it's the default. | 
 | all: $(OBJDIR)/llvm2ice make_symlink | 
 |  | 
 | # Creates symbolic link so that testing is easier. Also runs | 
 | # llvm2ice to verify that the defines flags have valid values, | 
 | # as well as describe the corresponding build attributes. | 
 | make_symlink: $(OBJDIR)/llvm2ice | 
 | 	rm -rf llvm2ice | 
 | 	ln -s $(OBJDIR)/llvm2ice | 
 | 	@echo "Build Attributes:" | 
 | 	@$(OBJDIR)/llvm2ice --build-atts | 
 |  | 
 | .PHONY: all make_symlink | 
 |  | 
 | # TODO(kschimpf): Fix python scripts to directly get build attributes | 
 | # rather than generating $(OBJDIR)/llvm2ice.build_atts. | 
 | $(OBJDIR)/llvm2ice: $(OBJS) | 
 | 	$(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \ | 
 |                -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) | 
 |  | 
 | # TODO: Be more precise than "*.h" here and elsewhere. | 
 | $(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def | 
 | 	$(CXX) -c $(CXXFLAGS) $< -o $@ | 
 |  | 
 | $(OBJS): | $(OBJDIR) | 
 |  | 
 | $(OBJDIR): | 
 | 	@mkdir -p $@ | 
 |  | 
 | check-lit: llvm2ice make_symlink | 
 | 	LLVM_BIN_PATH=$(LLVM_BIN_PATH) \ | 
 | 	$(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit | 
 |  | 
 | ifdef MINIMAL | 
 | check: check-lit | 
 | 	@echo "Crosstests ignored, minimal build" | 
 | else | 
 | check: check-lit | 
 | 	(cd crosstest; ./runtests.sh) | 
 | endif | 
 |  | 
 | # TODO: Fix the use of wildcards. | 
 | # Assumes clang-format is within $PATH. | 
 | format: | 
 | 	clang-format -style=LLVM -i src/*.h src/*.cpp | 
 |  | 
 | # Assumes clang-format-diff.py is within $PATH, and that the | 
 | # clang-format it calls is also within $PATH.  This may require adding | 
 | # a component to $PATH, or creating symlinks within some existing | 
 | # $PATH component.  Uses the one in /usr/lib/clang-format/ if it | 
 | # exists. | 
 | ifeq (,$(wildcard /usr/lib/clang-format/clang-format-diff.py)) | 
 |   CLANG_FORMAT_DIFF = clang-format-diff.py | 
 | else | 
 |   CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py | 
 | endif | 
 | format-diff: | 
 | 	git diff -U0 `git merge-base HEAD master` | \ | 
 | 	$(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i | 
 |  | 
 | clean: | 
 | 	rm -rf llvm2ice *.o $(OBJDIR) | 
 |  | 
 | clean-all: clean | 
 | 	rm -rf build/ |