OSDN Git Service

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