1 # The following variables will likely need to be modified, depending on where
2 # and how you built LLVM & Clang. They can be overridden in a command-line
3 # invocation of make, like:
5 # make LLVM_SRC_PATH=<path> LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
6 # PNACL_BIN_PATH=<path> ...
9 # LLVM_SRC_PATH is the path to the root of the checked out source code. This
10 # directory should contain the configure script, the include/ and lib/
11 # directories of LLVM, Clang in tools/clang/, etc.
12 # Alternatively, if you're building vs. a binary download of LLVM, then
13 # LLVM_SRC_PATH can point to the main untarred directory.
14 LLVM_SRC_PATH ?= ../llvm
16 # The x86-32-specific sandboxed translator directory.
17 # It holds sandboxed versions of libraries and binaries.
18 SB_LLVM_PATH ?= $(shell readlink -e \
19 ../../out/sandboxed_translators_work/translator-i686/llvm-sb/Release)
21 # NACL_ROOT is the root of the native client repository.
22 NACL_ROOT ?= $(shell python -c "import sys; sys.path.insert(0, 'pydir'); \
23 import utils; print utils.FindBaseNaCl()")
25 # PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain.
26 # This is used as the default root for finding binutils, libcxx, etc.
27 PNACL_TOOLCHAIN_ROOT ?= $(shell readlink -e \
28 $(NACL_ROOT)/toolchain/linux_x86/pnacl_newlib_raw)
30 # The location of PNaCl tools (e.g., binutils objdump, pnacl-clang++, etc.).
31 PNACL_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin)
33 # Hack to auto-detect autoconf versus cmake build of LLVM. If the LLVM tools
34 # were dynamically linked with something like libLLVM-3.6svn.so, it is an
35 # autoconf build, otherwise it is a cmake build. AUTOCONF is set to 0 for
36 # cmake, nonzero for autoconf.
37 AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-)
39 # CLANG_PATH is the location of the clang compiler to use for building
41 CLANG_PATH ?= $(shell readlink -e \
42 $(NACL_ROOT)/../third_party/llvm-build/Release+Asserts/bin)
44 # LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should
45 # contain header files and corresponding libraries. This is used for
46 # building the host binaries in conjuction with clang.
47 LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT)
48 STDLIB_FLAGS := -stdlib=libc++ -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
51 ifeq ($(HOST_ARCH),x86_64)
54 ifeq ($(HOST_ARCH),x86)
64 OBJDIR = build/Release
65 OPTLEVEL = -O2 -ffunction-sections -fdata-sections
69 # The list of CXX defines that are dependent on build parameters.
76 OBJDIR := $(OBJDIR)+Min
77 BASE_CXX_DEFINES += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
78 -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 \
79 -DALLOW_MINIMAL_BUILD=1
81 BASE_CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
82 -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 \
83 -DALLOW_MINIMAL_BUILD=0
86 SB_CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=1
87 CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
93 OBJDIR := $(OBJDIR)+Asserts
97 OBJDIR := $(OBJDIR)+TSan
98 CXX_EXTRA += -fsanitize=thread
99 LD_EXTRA += -fsanitize=thread
102 SB_OBJDIR := $(OBJDIR)+Sandboxed
104 $(info -----------------------------------------------)
105 $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
106 $(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
107 $(info Using NACL_ROOT = $(NACL_ROOT))
108 $(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
109 $(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
110 $(info Using CLANG_PATH = $(CLANG_PATH))
111 $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
112 $(info Using HOST_ARCH = $(HOST_ARCH))
113 $(info -----------------------------------------------)
115 LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
116 SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
118 # Listing specific libraries that are needed for pnacl-sz
119 # and the unittests, since we build "tools-only" for the
120 # sandboxed_translators (which doesn't include every library
121 # listed by llvm-config).
123 LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
124 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
125 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
127 ifeq ($(AUTOCONF), 0)
129 LLVM_LIBS := $(LLVM_LIBS_LIST)
130 # For the cmake build, the gtest libs end up in the same place as the LLVM
131 # libs, so no "-L..." arg is needed.
133 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
135 # LLVM autoconf build
136 LLVM_LIBS := -lLLVM-3.6svn
137 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
138 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
141 LLVM_LDFLAGS := $(LLVM_LIBS) \
142 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
143 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
144 SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
145 -L$(SB_LLVM_PATH)/lib
147 CCACHE := `command -v ccache`
148 CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
149 SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
150 SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
152 BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
153 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
154 -Wno-error=unused-parameter $(CXX_EXTRA)
156 CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
158 SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(SB_CXX_DEFINES)
160 LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
161 $(LD_EXTRA) $(STDLIB_FLAGS)
162 # Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
163 SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
168 IceBrowserCompileServer.cpp \
173 IceCompileServer.cpp \
174 IceELFObjectWriter.cpp \
177 IceGlobalContext.cpp \
187 IceTargetLowering.cpp \
188 IceTargetLoweringARM32.cpp \
189 IceTargetLoweringX8632.cpp \
198 SRCS += IceConverter.cpp \
202 OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
203 SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
207 IceELFSectionTest.cpp \
208 IceParseInstsTest.cpp
210 UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
211 UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
213 # Keep all the first target so it's the default.
214 all: $(OBJDIR)/pnacl-sz make_symlink runtime
218 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
220 sb: $(SB_OBJDIR)/pnacl-sz.x86-32.nexe
223 # Creates symbolic link so that testing is easier. Also runs
224 # pnacl-sz to verify that the defines flags have valid values,
225 # as well as describe the corresponding build attributes.
226 make_symlink: $(OBJDIR)/pnacl-sz
228 ln -s $(OBJDIR)/pnacl-sz
229 @echo "Build Attributes:"
230 @$(OBJDIR)/pnacl-sz --build-atts
232 .PHONY: all make_symlink runtime bloat sb
234 $(OBJDIR)/pnacl-sz: $(OBJS)
235 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
236 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
238 $(SB_OBJDIR)/pnacl-sz.x86-32.nexe: $(SB_OBJS)
239 $(eval PNACL_SZ_BASE := $(patsubst %.nexe, %, $@))
240 $(SB_CXX) $(SB_LDFLAGS) -o $(PNACL_SZ_BASE).nonfinal.pexe $^ \
242 $(SB_TRANSLATE) -arch x86-32 $(PNACL_SZ_BASE).nonfinal.pexe -o $@ \
243 --allow-llvm-bitcode-input
245 # TODO(stichnot): Be more precise than "*.h" here and elsewhere.
246 $(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
247 $(CXX) -c $(CXXFLAGS) $< -o $@
249 $(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
250 $(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
252 $(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
253 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
254 -lgtest -lgtest_main -ldl \
255 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
257 $(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
258 unittest/*.h src/*.h src/*.def
259 $(CXX) -c $(CXXFLAGS) \
261 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
262 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
266 $(SB_OBJS): | $(SB_OBJDIR)
268 $(UNITTEST_OBJS): | $(OBJDIR)/unittest
275 $(OBJDIR)/unittest: $(OBJDIR)
278 RT_SRC := runtime/szrt.c runtime/szrt_ll.ll
279 RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o
283 # Use runtime.is.built so that build-runtime.py is invoked only once
284 # even in a parallel build.
285 .INTERMEDIATE: runtime.is.built
286 $(RT_OBJ): runtime.is.built
287 runtime.is.built: $(RT_SRC)
288 @echo ================ Building Subzero runtime ================
289 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
291 check-lit: $(OBJDIR)/pnacl-sz make_symlink
292 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
293 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
296 check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
297 @echo "Crosstests disabled, minimal build"
299 check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
300 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
301 # For (slow) sandboxed tests, limit to Om1/sse4.1.
302 ./pydir/crosstest_generator.py -v --lit \
303 -i native,sse2 -i native,sse4.1,test_vector_ops \
304 -i sandbox,sse4.1,Om1
305 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
306 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
309 check-unit: $(OBJDIR)/run_unittests
310 $(OBJDIR)/run_unittests
312 check: check-lit check-unit check-xtest
315 # Add one of the following lines for each source file to ignore.
316 FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
318 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
319 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
322 git diff -U0 `git merge-base HEAD master` | \
323 PATH=$(PNACL_BIN_PATH):$(PATH) \
324 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
328 nm -C -S -l pnacl-sz | \
329 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
330 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
333 rm -rf pnacl-sz *.o $(OBJDIR) $(SB_OBJDIR) build/pnacl-sz.bloat.json