OSDN Git Service

Subzero: Include commit count in revision string.
[android-x86/external-swiftshader.git] / Makefile.standalone
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:
4 #
5 #   make LLVM_SRC_PATH=<path> LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
6 #        PNACL_BIN_PATH=<path> ...
7 #
8
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
15
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)
20
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()")
24
25 # TOOLCHAIN_ROOT is the location of NaCl/PNaCl toolchains and other
26 # tools like qemu.
27 TOOLCHAIN_ROOT ?= $(shell readlink -e $(NACL_ROOT)/toolchain/linux_x86)
28
29 # PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain.
30 # This is used as the default root for finding binutils, libcxx, etc.
31 PNACL_TOOLCHAIN_ROOT ?= $(shell readlink -e $(TOOLCHAIN_ROOT)/pnacl_newlib_raw)
32
33 # The location of PNaCl tools (e.g., binutils objdump, pnacl-clang++, etc.).
34 PNACL_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin)
35
36 # Allow tests to be overridden, e.g.:
37 #   make -f Makefile.standalone check-lit \
38 #     CHECK_LIT_TESTS="tests_lit/llvm2ice_tests/{alloc,arith}.ll"
39 #   make -f Makefile.standalone check-xtest \
40 #     CHECK_XTEST_TESTS=crosstest/Output/simple_loop_x8632_native_O2_sse2.xtest
41 CHECK_LIT_TESTS ?= tests_lit
42 CHECK_XTEST_TESTS ?= crosstest/Output
43
44 # Hack to auto-detect autoconf versus cmake build of LLVM.  If the LLVM tools
45 # were dynamically linked with something like libLLVM-3.7svn.so, it is an
46 # autoconf build, otherwise it is a cmake build.  AUTOCONF is set to 0 for
47 # cmake, nonzero for autoconf.
48 AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-)
49
50 # CLANG_PATH is the location of the clang compiler to use for building
51 # the host binaries.
52 CLANG_PATH ?= $(shell readlink -e \
53   $(NACL_ROOT)/../third_party/llvm-build/Release+Asserts/bin)
54
55 # LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should
56 # contain header files and corresponding libraries. This is used for
57 # building the host binaries in conjuction with clang.
58 LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT)
59 STDLIB_FLAGS := -stdlib=libc++ -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
60
61 HOST_ARCH ?= x86_64
62 ifeq ($(HOST_ARCH),x86_64)
63   HOST_FLAGS = -m64
64 else
65   ifeq ($(HOST_ARCH),x86)
66     HOST_FLAGS = -m32
67   endif
68 endif
69
70 ifdef DEBUG
71   OBJDIR = build/Debug
72   OPTLEVEL = -O0
73   LINKOPTLEVEL = -O0
74 else
75   OBJDIR = build/Release
76   OPTLEVEL = -O2 -ffunction-sections -fdata-sections
77   LINKOPTLEVEL = -O2
78 endif
79
80 # The list of CXX defines that are dependent on build parameters.
81 BASE_CXX_DEFINES =
82 CXX_EXTRA =
83 LD_EXTRA =
84
85 ifdef MINIMAL
86   NOASSERT = 1
87   NODUMP = 1
88   OBJDIR := $(OBJDIR)+Min
89   BASE_CXX_DEFINES += -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
90     -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_TIMERS=0 -DALLOW_MINIMAL_BUILD=1
91 else
92   BASE_CXX_DEFINES += -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
93     -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_TIMERS=1 -DALLOW_MINIMAL_BUILD=0
94 endif
95
96 ifdef NODUMP
97   OBJDIR := $(OBJDIR)+NoDump
98   BASE_CXX_DEFINES += -DALLOW_DUMP=0
99 else
100   BASE_CXX_DEFINES += -DALLOW_DUMP=1
101 endif
102
103 # Restrict to a single supported target.  Current options:
104 #   SZTARGET=ARM32
105 #   SZTARGET=MIPS32
106 #   SZTARGET=X8632
107 #   SZTARGET=X8664
108 ifdef SZTARGET
109   OBJDIR := $(OBJDIR)+T_$(SZTARGET)
110   BASE_CXX_DEFINES += -DSZTARGET=$(SZTARGET)
111 endif
112
113 BASE_CXX_DEFINES += -DPNACL_LLVM
114 SZ_COMMIT_COUNT := $(shell git rev-list --count HEAD)
115 SZ_GIT_HASH := $(shell git rev-parse HEAD)
116 BASE_CXX_DEFINES += -DSUBZERO_REVISION=$(SZ_COMMIT_COUNT)_$(SZ_GIT_HASH)
117
118 CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
119
120 ifdef NOASSERT
121   ASSERTIONS = -DNDEBUG
122 else
123   ASSERTIONS =
124   OBJDIR := $(OBJDIR)+Asserts
125 endif
126
127 ifdef UBSAN
128   OBJDIR := $(OBJDIR)+UBSan
129   CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr \
130                -fno-sanitize=nonnull-attribute
131   LD_EXTRA += -fsanitize=undefined
132 endif
133
134 ifdef UBSAN_TRAP
135   OBJDIR := $(OBJDIR)+UBSan_Trap
136   CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error \
137                -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
138   LD_EXTRA += -fsanitize=undefined-trap
139 endif
140
141 ifdef TSAN
142   OBJDIR := $(OBJDIR)+TSan
143   CXX_EXTRA += -fsanitize=thread
144   LD_EXTRA += -fsanitize=thread
145 endif
146
147 ifdef ASAN
148   OBJDIR := $(OBJDIR)+ASan
149   CXX_EXTRA += -fsanitize=address
150   LD_EXTRA += -fsanitize=address
151 endif
152
153 ifdef MSAN
154   # TODO(ascull): this has an as yet undiagnosed uninitialized memory access
155   OBJDIR := $(OBJDIR)+MSan
156   CXX_EXTRA += -fsanitize=memory
157   LD_EXTRA += -fsanitize=memory
158 endif
159
160 ifdef FORCEASM
161   FORCEASM_FLAG = --filetype=asm
162   # With --filetype=asm and --sandbox, the llvm-mc assembler emits the lock and
163   # 16-bit prefixes in the "wrong" order, causing the validator to reject the
164   # resulting nexe.  So we just disable those tests for now.
165   FORCEASM_XTEST_EXCLUDES = -e x8632,sandbox,test_sync_atomic
166   FORCEASM_LIT_PARAM = --param=FORCEASM
167   # x86 sandboxing lit tests are disabled because filetype=asm does not
168   # handle bundle_lock pad-to-end correctly.
169   # TODO(jpp): fix this.
170   FORCEASM_LIT_TEST_EXCLUDES = --filter='^(?!.*/x86/sandboxing.ll).*'
171 else
172   FORCEASM_FLAG =
173   FORCEASM_XTEST_EXCLUDES =
174   FORCEASM_LIT_PARAM =
175   FORCEASM_LIT_TEST_EXCLUDES =
176 endif
177
178 ifdef LINUX_MALLOC_PROFILE
179   OBJDIR := $(OBJDIR)+MalProf
180   CXX_EXTRA += -DALLOW_LINUX_MALLOC_PROFILE=1
181   LD_EXTRA += -Wl,--export-dynamic
182 endif
183
184 SB_OBJDIR := $(OBJDIR)+Sandboxed
185 SBB_OBJDIR := $(OBJDIR)+SandboxedBrowser
186
187 V8_DIR = $(NACL_ROOT)/../v8
188 V8_CXXFLAGS := -I$(V8_DIR)
189
190 $(info -----------------------------------------------)
191 $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
192 $(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
193 $(info Using NACL_ROOT = $(NACL_ROOT))
194 $(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
195 $(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
196 $(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
197 $(info Using CLANG_PATH = $(CLANG_PATH))
198 $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
199 $(info Using HOST_ARCH     = $(HOST_ARCH))
200 $(info -----------------------------------------------)
201
202 LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
203 SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
204
205 # Listing specific libraries that are needed for pnacl-sz
206 # and the unittests, since we build "tools-only" for the
207 # sandboxed_translators (which doesn't include every library
208 # listed by llvm-config).
209
210 LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
211     -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
212     -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
213
214 ifeq ($(AUTOCONF), 0)
215   # LLVM cmake build
216   LLVM_LIBS := $(LLVM_LIBS_LIST)
217   # For the cmake build, the gtest libs end up in the same place as the LLVM
218   # libs, so no "-L..." arg is needed.
219   GTEST_LIB_PATH ?=
220   CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
221 else
222   # LLVM autoconf build
223   LLVM_LIBS := -lLLVM-3.7svn
224   GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
225   ifneq ($(wildcard \
226            ../../out/llvm_x86_64_linux_work/Release+Asserts/bin/clang-format),)
227     CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
228   else
229     CLANG_FORMAT_PATH ?= \
230                      ../../out/llvm_x86_64_linux_debug_work/Debug+Asserts/bin
231   endif
232 endif
233
234 LLVM_LDFLAGS := $(LLVM_LIBS) \
235                 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
236                 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
237 SB_LLVM_LDFLAGS := -Wl,--start-group $(LLVM_LIBS_LIST) -Wl,--end-group \
238                    -L$(SB_LLVM_PATH)/lib
239
240 CCACHE := `command -v ccache`
241 CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
242 SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
243 SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
244 SB_FINALIZE := $(PNACL_BIN_PATH)/pnacl-finalize --no-strip-syms
245
246 # Extra warnings that LLVM's build system adds in addition to -Wall.
247 LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
248
249 # Use g++ to compile, to check for errors/warnings that clang++ might have
250 # missed.  It's unlikely to link, unless LLVM was also built with g++, so the
251 # compile_only target should be used.  Note: This ifdef section is deliberately
252 # placed here instead of with the other ifdef sections, so that its redefinition
253 # of CXX/STDLIB_FLAGS/LLVM_EXTRA_WARNINGS follows their normal definitions.
254 ifdef GPLUSPLUS
255   CXX := CCACHE_CPP2=yes $(CCACHE) g++
256   STDLIB_FLAGS :=
257   LLVM_EXTRA_WARNINGS := \
258     -Wcast-qual \
259     -Wno-comment \
260     -Wno-long-long \
261     -Wno-maybe-uninitialized \
262     -Wno-missing-field-initializers \
263     -Wno-unused-parameter \
264     -Wwrite-strings
265   OBJDIR := $(OBJDIR)+Gplusplus
266 endif
267
268 BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -fno-rtti \
269   -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
270   $(LLVM_EXTRA_WARNINGS) $(CXX_EXTRA) -MP -MD -Werror
271
272 ifdef WASM
273   BASE_CXXFLAGS := $(BASE_CXXFLAGS) $(V8_CXXFLAGS) -DALLOW_WASM=1
274   OBJDIR := $(OBJDIR)+Wasm
275 else
276   BASE_CXXFLAGS := $(BASE_CXXFLAGS) -DALLOW_WASM=0
277 endif
278
279 # TODO(stichnot,jpp): Restructure static fields in template classes to avoid
280 # needing -Wno-undefined-var-template .
281 CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
282   $(STDLIB_FLAGS) -Wno-undefined-var-template
283 SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(BASE_CXX_DEFINES) \
284                -Wno-unknown-pragmas -I$(NACL_ROOT) -I$(NACL_ROOT)/..
285
286 LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
287   $(LD_EXTRA) $(STDLIB_FLAGS)
288 # Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
289 SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
290
291 # List the target-specific source files first, which generally take longer to
292 # compile, in the hope of improving parallel build time.
293 SRCS = \
294   IceAssemblerARM32.cpp \
295   IceInstARM32.cpp \
296   IceInstMIPS32.cpp \
297   IceInstX8632.cpp \
298   IceInstX8664.cpp \
299   IceTargetLowering.cpp \
300   IceTargetLoweringARM32.cpp \
301   IceTargetLoweringMIPS32.cpp \
302   IceTargetLoweringX86.cpp \
303   IceTargetLoweringX8632.cpp \
304   IceTargetLoweringX8664.cpp \
305   IceAssembler.cpp \
306   IceBrowserCompileServer.cpp \
307   IceCfg.cpp \
308   IceCfgNode.cpp \
309   IceClFlags.cpp \
310   IceCompiler.cpp \
311   IceCompileServer.cpp \
312   IceELFObjectWriter.cpp \
313   IceELFSection.cpp \
314   IceFixups.cpp \
315   IceGlobalContext.cpp \
316   IceGlobalInits.cpp \
317   IceInst.cpp \
318   IceIntrinsics.cpp \
319   IceLiveness.cpp \
320   IceLoopAnalyzer.cpp \
321   IceMangling.cpp \
322   IceMemory.cpp \
323   IceOperand.cpp \
324   IceRangeSpec.cpp \
325   IceRegAlloc.cpp \
326   IceRevision.cpp \
327   IceRNG.cpp \
328   IceSwitchLowering.cpp \
329   IceThreading.cpp \
330   IceTimerTree.cpp \
331   IceTranslator.cpp \
332   IceTypes.cpp \
333   IceVariableSplitting.cpp \
334   LinuxMallocProfiling.cpp \
335   main.cpp \
336   PNaClTranslator.cpp
337
338 ifndef MINIMAL
339   SRCS += \
340     IceASanInstrumentation.cpp \
341     IceConverter.cpp \
342     IceInstrumentation.cpp \
343     IceTypeConverter.cpp
344 endif
345
346 ifdef WASM
347   SRCS += \
348     WasmTranslator.cpp
349 endif
350
351 OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
352 SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
353 SBB_OBJS=$(patsubst %.cpp, $(SBB_OBJDIR)/%.o, $(SRCS))
354
355 UNITTEST_SRCS = \
356   BitcodeMunge.cpp \
357   IceELFSectionTest.cpp \
358   IceParseInstsTest.cpp
359
360 # The X86 assembler tests take too long to compile. Given how infrequently the
361 # assembler will change, we disable them.
362 ifdef CHECK_X86_ASM
363   ifndef DEBUG
364   $(error Run check-unit with DEBUG=1 lest your machine perish)
365   endif
366   UNITTEST_SRCS += AssemblerX8632/LowLevel.cpp \
367     AssemblerX8632/DataMov.cpp \
368     AssemblerX8632/Locked.cpp \
369     AssemblerX8632/GPRArith.cpp \
370     AssemblerX8632/XmmArith.cpp \
371     AssemblerX8632/ControlFlow.cpp \
372     AssemblerX8632/Other.cpp \
373     AssemblerX8632/X87.cpp \
374     AssemblerX8664/LowLevel.cpp \
375     AssemblerX8664/DataMov.cpp \
376     AssemblerX8664/Locked.cpp \
377     AssemblerX8664/GPRArith.cpp \
378     AssemblerX8664/XmmArith.cpp \
379     AssemblerX8664/ControlFlow.cpp \
380     AssemblerX8664/Other.cpp
381 endif
382
383 UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
384 UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
385
386 NEXES = $(SB_OBJDIR)/pnacl-sz.x8632.nexe \
387         $(SB_OBJDIR)/pnacl-sz.x8664.nexe \
388         $(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe \
389         $(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe
390 NEXES_LITE = $(SB_OBJDIR)/pnacl-sz.x8664.nexe
391
392 # Keep all the first target so it's the default.
393 all: $(OBJDIR)/pnacl-sz make_symlink runtime
394
395 ifdef TSAN
396 sb sb-lite:
397         @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
398 else
399 sb: $(NEXES) sb_make_symlink exists-sbtc
400 sb-lite: $(NEXES_LITE) exists-sbtc
401 endif
402
403 # SHOW_BUILD_ATTS is an executable that is run to show what build
404 # attributes were used to build pnacl-sz.
405 SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
406
407 # Creates symbolic link so that testing is easier. Also runs
408 # pnacl-sz to verify that the defines flags have valid values,
409 # as well as describe the corresponding build attributes.
410 make_symlink: $(OBJDIR)/pnacl-sz
411         rm -rf pnacl-sz
412         ln -s $(OBJDIR)/pnacl-sz
413         @echo "Build Attributes:"
414         @$(SHOW_BUILD_ATTS)
415
416 sb_make_symlink: $(NEXES)
417         $(foreach nexe,$(NEXES),rm -rf $(notdir $(nexe)); ln -s $(nexe);)
418
419 %.pexe : %.nonfinal.pexe
420         $(SB_FINALIZE) -o $@ $<
421
422 .PHONY: all compile_only make_symlink runtime bloat sb docs help \
423   help-check-lit help-check-xtest exists-nonsfi-x8632 \
424   exists-nonsfi-arm32 exists-sbtc exists-spec
425
426 compile_only: $(OBJS)
427
428 V8_LIBDIR=$(V8_DIR)/out/native/lib.target
429
430 ifdef WASM
431   V8_LIBS := \
432     $(V8_LIBDIR)/libv8.so \
433     $(V8_LIBDIR)/libicuuc.so \
434     $(V8_LIBDIR)/libicui18n.so
435 endif
436
437 $(OBJDIR)/pnacl-sz: $(OBJS)
438         $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
439           -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) $(V8_LIBS)
440
441 $(SB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SB_OBJS)
442         $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS)
443
444 $(SBB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SBB_OBJS)
445         $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS) \
446           --pnacl-disable-abi-check
447
448 $(SB_OBJDIR)/pnacl-sz.x8632.nexe: $(SB_OBJDIR)/pnacl-sz.pexe
449         $(SB_TRANSLATE) -arch x86-32 $^ -o $@
450
451 $(SB_OBJDIR)/pnacl-sz.x8664.nexe: $(SB_OBJDIR)/pnacl-sz.pexe
452         $(SB_TRANSLATE) -arch x86-64 $^ -o $@
453
454 $(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe
455         $(SB_TRANSLATE) -arch x86-32 $^ -o $@
456
457 $(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe
458         $(SB_TRANSLATE) -arch x86-64 $^ -o $@
459
460 src/IceRegistersARM32.def: pydir/gen_arm32_reg_tables.py
461         python $< > $@
462
463 -include $(foreach dep,$(SRCS:.cpp=.d),$(OBJDIR)/$(dep))
464 $(OBJS): $(OBJDIR)/%.o: src/%.cpp
465         $(CXX) -c $(CXXFLAGS) $< -o $@
466
467 -include $(foreach dep,$(SRCS:.cpp=.d),$(SB_OBJDIR)/$(dep))
468 $(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp
469         $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=0 $< -o $@
470
471 -include $(foreach dep,$(SRCS:.cpp=.d),$(SBB_OBJDIR)/$(dep))
472 $(SBB_OBJS): $(SBB_OBJDIR)/%.o: src/%.cpp
473         $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=1 $< -o $@
474
475 $(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
476         $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
477           -lgtest -lgtest_main -ldl \
478           -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
479
480 -include $(foreach dep,$(UNITTEST_SRCS:.cpp=.d),$(OBJDIR)/unittest/$(dep))
481 $(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp
482         $(CXX) -c $(CXXFLAGS) \
483           -Isrc/ \
484           -Iunittest/ \
485           -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
486           -I$(LLVM_SRC_PATH) \
487           -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
488           -Wno-expansion-to-defined \
489           $< -o $@
490
491 $(OBJS): | $(OBJDIR)
492 $(SB_OBJS): | $(SB_OBJDIR)
493 $(SBB_OBJS): | $(SBB_OBJDIR)
494
495 $(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 \
496                     $(OBJDIR)/unittest/AssemblerX8664
497
498 $(OBJDIR):
499         @mkdir -p $@
500 $(SB_OBJDIR):
501         @mkdir -p $@
502 $(SBB_OBJDIR):
503         @mkdir -p $@
504
505 $(OBJDIR)/unittest: $(OBJDIR)
506         @mkdir -p $@
507
508 $(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest
509         @mkdir -p $@
510 $(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest
511         @mkdir -p $@
512
513 RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c \
514           runtime/szrt_asm_x8632.s runtime/szrt_asm_x8664.s \
515           runtime/szrt_asm_arm32.s runtime/szrt_asan.c
516 RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
517           build/runtime/szrt_nonsfi_x8632.o \
518           build/runtime/szrt_native_x8664.o build/runtime/szrt_sb_x8664.o \
519           build/runtime/szrt_nonsfi_x8664.o \
520           build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o \
521           build/runtime/szrt_nonsfi_arm32.o \
522           build/runtime/szrt_asan_x8632.o build/runtime/szrt_asan_x8664.o \
523           build/runtime/szrt_asan_arm32.o
524
525 runtime: $(RT_OBJ)
526
527 # Use runtime.is.built so that build-runtime.py is invoked only once
528 # even in a parallel build.
529 .INTERMEDIATE: runtime.is.built
530 $(RT_OBJ): runtime.is.built
531 runtime.is.built: $(RT_SRC) pydir/build-runtime.py
532         @echo ================ Building Subzero runtime ================
533         ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
534
535 check-lit: $(OBJDIR)/pnacl-sz make_symlink runtime
536         PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
537         $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_LIT_TESTS) \
538             $(FORCEASM_LIT_TEST_EXCLUDES) $(FORCEASM_LIT_PARAM)
539
540 ifdef MINIMAL
541 check-xtest check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime
542         @echo "Crosstests disabled, minimal build"
543 else
544 check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime \
545   exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
546        # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
547        # For (slow) sandboxed tests, limit to Om1/sse4.1.
548        # run.py (used to run the sandboxed xtests) does not support
549        # specifying -cpu cortex-a15 to qemu, hence we disable the
550        # hwdiv-arm tests.
551         ./pydir/crosstest_generator.py -v --lit \
552           --toolchain-root $(TOOLCHAIN_ROOT) \
553           $(FORCEASM_FLAG) \
554           $(FORCEASM_XTEST_EXCLUDES) \
555           -i x8632,native,sse2 \
556           -i x8632,native,sse4.1,test_vector_ops \
557           -i x8632,sandbox,sse4.1,Om1 \
558           -i x8632,nonsfi,sse2,O2 \
559           -i x8664,native,sse2 \
560           -i x8664,native,sse4.1,test_vector_ops \
561           -i x8664,sandbox,sse4.1,Om1 \
562           -i arm32 \
563           -e arm32,sandbox,hwdiv-arm
564         PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
565         $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
566 check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \
567   exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
568        # Do all native/sse2/neon tests, which are relatively fast.
569        # Limit to test_global+mem_intrin for sandbox+nonsfi because sandbox and
570        # nonsfi builds are slow, and test_global and mem_intrin are the most
571        # common sources of problems.
572         ./pydir/crosstest_generator.py -v --lit \
573           --toolchain-root $(TOOLCHAIN_ROOT) \
574           $(FORCEASM_FLAG) \
575           $(FORCEASM_XTEST_EXCLUDES) \
576           -i x8632,native,sse2,O2 \
577           -i x8664,native,sse2,O2 \
578           -i arm32,native,neon,O2 \
579           -i x8632,sse2,O2,test_global \
580           -i x8632,sse2,O2,mem_intrin \
581           -i x8664,sse2,O2,test_global \
582           -i x8664,sse2,O2,mem_intrin \
583           -i arm32,neon,O2,test_global \
584           -i arm32,neon,O2,mem_intrin \
585           -e x8664,nonsfi
586         PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
587         $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
588 crosstest/test_arith_ll.ll: pydir/gen_test_arith_ll.py
589         python $< > $@
590 endif
591
592 check-unit: $(OBJDIR)/run_unittests
593         $(OBJDIR)/run_unittests
594
595 # List the spec2k components in roughly reverse order of runtime, to help with
596 # parallel execution speed.
597 ALLSPEC := 253.perlbmk 177.mesa 188.ammp 256.bzip2 164.gzip 179.art 183.equake \
598            175.vpr 176.gcc 181.mcf 186.crafty 197.parser 254.gap 255.vortex \
599            300.twolf 252.eon
600 .PHONY: $(ALLSPEC)
601
602 TARGET := x8632
603 ifeq ($(TARGET),x8632)
604   TARGETFLAG=x8632
605   SETUP=SetupGccX8632Opt
606   SPEC := --filetype=obj
607 endif
608 ifeq ($(TARGET),x8664)
609   TARGETFLAG=x8664
610   SETUP=SetupGccX8664Opt
611   SPEC := --filetype=obj
612 endif
613 ifeq ($(TARGET),arm32)
614   TARGETFLAG=arm32
615   SETUP=SetupGccArmOpt
616   SPEC := --filetype=obj
617 endif
618 SPECFLAGS := -O2
619 SPECRUN := --run
620 %.spec2k: % $(OBJDIR)/pnacl-sz make_symlink runtime
621         ./pydir/szbuild_spec2k.py -v \
622           $(SPECFLAGS) --target=$(TARGETFLAG) $(SPEC) $< $(SPECRUN)
623
624 check-spec: exists-spec $(ALLSPEC:=.spec2k)
625
626 check: check-lit check-unit check-xtest
627
628 NONSFI_LOADER_X8632 = \
629   $(NACL_ROOT)/scons-out/opt-linux-x86-32/obj/src/nonsfi/loader/nonsfi_loader
630 NONSFI_LOADER_ARM32 = \
631   $(NACL_ROOT)/scons-out/opt-linux-arm/obj/src/nonsfi/loader/nonsfi_loader
632 SBTC_LIBFILE = $(SB_LLVM_PATH)/lib/libLLVMSupport.a
633 SPEC_SAMPLE_PEXE = $(NACL_ROOT)/tests/spec2k/176.gcc/gcc.opt.stripped.pexe
634
635 exists-nonsfi-x8632:
636         @if [ ! -f $(NONSFI_LOADER_X8632) ] ; then \
637           echo "Missing file $(NONSFI_LOADER_X8632)"; \
638           echo "Consider running './scons nonsfi_loader'" \
639                "in the native_client directory."; \
640           exit 1 ; \
641         fi
642
643 exists-nonsfi-arm32:
644         @if [ ! -f $(NONSFI_LOADER_ARM32) ] ; then \
645           echo "Missing file $(NONSFI_LOADER_ARM32)"; \
646           echo "Consider running './scons platform=arm nonsfi_loader'" \
647                "in the native_client directory."; \
648           exit 1 ; \
649         fi
650
651 exists-sbtc:
652         @if [ ! -f $(SBTC_LIBFILE) ] ; then \
653           echo "Missing file $(SBTC_LIBFILE)"; \
654           echo "Consider running 'toolchain_build_pnacl.py --build-sbtc'."; \
655           exit 1 ; \
656         fi
657
658 exists-spec:
659         @if [ ! -f $(SPEC_SAMPLE_PEXE) ] ; then \
660           echo "Missing file $(SPEC_SAMPLE_PEXE)"; \
661           echo "Consider running" \
662                "'./run_all.sh BuildBenchmarks 0 SetupPnaclX8632Opt'" \
663                "in the native_client/tests/spec2k directory."; \
664           exit 1 ; \
665         fi
666
667 check-presubmit presubmit: exists-nonsfi-x8632 exists-nonsfi-arm32 \
668   exists-sbtc exists-spec
669 # Make sure clang-format gets run.
670         +make -f Makefile.standalone format
671 # Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
672         +make -f Makefile.standalone \
673           MINIMAL=1 check
674 # Check that there are no g++ build errors or warnings.
675         +make -f Makefile.standalone \
676           GPLUSPLUS=1 compile_only
677 # Check the x86 assembler unit tests.
678         +make -f Makefile.standalone \
679           DEBUG=1 CHECK_X86_ASM=1 check-unit sb
680 # Run lit tests, cross tests, unit tests, and spec2k/x86-32.
681         +make -f Makefile.standalone \
682           check check-spec
683 # Run spec2k/x86-64.
684         +make -f Makefile.standalone \
685           TARGET=x8664 check-spec
686 # Run spec2k/x86-64 with sandboxing.
687         +make -f Makefile.standalone \
688           SPECFLAGS='-O2 --sandbox' TARGET=x8664 check-spec
689 # Build spec2k under -Om1/x86-32, to check for liveness errors.
690         +make -f Makefile.standalone \
691           SPECFLAGS='-Om1' SPECRUN= check-spec
692 # Build spec2k under -Om1/x86-64, to check for liveness errors.
693         +make -f Makefile.standalone \
694           SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec
695 # Run spec2k for x86-32 without advanced phi lowering.
696         +make -f Makefile.standalone \
697           SPECFLAGS='-O2 --sz=--phi-edge-split=0' check-spec
698 # Run spec2k for x86-64 without advanced phi lowering.
699         +make -f Makefile.standalone \
700           SPECFLAGS='-O2 --sz=--phi-edge-split=0' TARGET=x8664 check-spec
701 # Run cross tests and lit tests to validate filetype=asm output.
702         +make -f Makefile.standalone \
703           FORCEASM=1 check-xtest check-lit
704 # Build spec2k for arm32.
705         +make -f Makefile.standalone \
706           TARGET=arm32 SPECRUN= check-spec
707 # Build spec2k under -Om1/arm32.
708         +make -f Makefile.standalone \
709           TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec
710 # Run a few spec2k tests for arm32 using qemu. Keep the list sorted in
711 # roughly reverse order of runtime.
712         +make -f Makefile.standalone \
713           TARGET=arm32 ALLSPEC='252.eon 254.gap 176.gcc 181.mcf' check-spec
714 # Provide validation of user awesomeness!
715         echo Success
716
717 presubmit-lite: exists-nonsfi-x8632 exists-nonsfi-arm32 \
718   exists-sbtc exists-spec
719 # Make sure clang-format gets run.
720         +make -f Makefile.standalone format
721 # Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
722         +make -f Makefile.standalone \
723           MINIMAL=1 check sb-lite
724 # Check that there are no g++ build errors or warnings.
725         +make -f Makefile.standalone \
726           GPLUSPLUS=1 compile_only
727 # Run lit tests, cross tests, unit tests, and spec2k/x86-32.
728         +make -f Makefile.standalone \
729           check-lit check-unit check-spec
730         +make -f Makefile.standalone \
731           check-xtest-lite
732 # Run spec2k/x86-64.
733         +make -f Makefile.standalone \
734           TARGET=x8664 check-spec
735 # Build spec2k under -Om1/x86-32, to check for liveness errors.
736         +make -f Makefile.standalone \
737           SPECFLAGS='-Om1' SPECRUN= check-spec
738 # Build spec2k under -Om1/x86-64, to check for liveness errors.
739         +make -f Makefile.standalone \
740           SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec
741 # Run cross tests and lit tests to validate filetype=asm output.
742         +make -f Makefile.standalone \
743           FORCEASM=1 check-lit
744         +make -f Makefile.standalone \
745           FORCEASM=1 check-xtest-lite
746 # Build spec2k under -Om1/arm32.
747         +make -f Makefile.standalone \
748           TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec
749 # Run a few spec2k tests for arm32 using qemu. Keep the list sorted in
750 # roughly reverse order of runtime.
751         +make -f Makefile.standalone \
752           TARGET=arm32 ALLSPEC='254.gap 176.gcc 181.mcf' check-spec
753 # Provide validation of user awesomeness!
754         echo Success
755
756 FORMAT_BLACKLIST =
757 # Add one of the following lines for each source file to ignore.
758 FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
759 FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
760 FORMAT_BLACKLIST += ! -name assembler_arm.h
761 FORMAT_BLACKLIST += ! -name assembler_arm.cc
762 FORMAT_BLACKLIST += ! -path "./wasm-install/*"
763 FORMAT_BLACKLIST += ! -path "./pnacl-llvm/*"
764 format:
765         $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
766           `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
767
768 format-diff:
769         git diff -U0 `git merge-base HEAD master` | \
770           PATH=$(PNACL_BIN_PATH):$(PATH) \
771           $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
772           -p1 -style=LLVM -i
773
774 bloat: make_symlink
775         nm -C -S -l pnacl-sz | \
776           bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
777         @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
778
779 bloat-sb: sb_make_symlink
780         $(foreach nexe,$(NEXES),nm -C -S -l $(nexe) | bloat/bloat.py \
781           --nm-output=/dev/stdin syms > build/$(notdir $(nexe)).bloat.json;)
782         @echo "See Subzero size breakdown in:"
783         @$(foreach nexe,$(NEXES),echo "  bloat/$(notdir $(nexe)).bloat.html";)
784
785 docs:
786         make -C docs -f Makefile.standalone
787
788 help:
789         @cat Makefile.standalone-help/help.txt
790
791 help-check-lit:
792         @cat Makefile.standalone-help/check-lit.txt
793
794 help-check-xtest:
795         @cat Makefile.standalone-help/check-xtest.txt
796
797 clean:
798         rm -rf pnacl-sz *.o $(foreach nexe,$(NEXES),$(notdir $(nexe))) \
799           $(OBJDIR) $(SB_OBJDIR) $(SBB_OBJDIR) build/*.bloat.json
800
801 clean-all: clean
802         rm -rf build/ crosstest/Output/