blob: 201a8e4501fb04ed142bce617f7304ceedd239b3 [file] [log] [blame]
Derek Schuffbc643132014-05-22 16:39:25 -07001# 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#
Jim Stichnoth0a9e1262015-04-21 09:59:21 -07005# make LLVM_SRC_PATH=<path> LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
Jan Voung44c3a802015-03-27 16:29:08 -07006# PNACL_BIN_PATH=<path> ...
Derek Schuffbc643132014-05-22 16:39:25 -07007#
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.
14LLVM_SRC_PATH ?= ../llvm
15
Jan Voung44c3a802015-03-27 16:29:08 -070016# The x86-32-specific sandboxed translator directory.
17# It holds sandboxed versions of libraries and binaries.
18SB_LLVM_PATH ?= $(shell readlink -e \
Jim Stichnoth2e7de232015-11-02 08:25:57 -080019 ../../out/sandboxed_translators_work/translator-i686/llvm-sb/Release)
Jan Voung44c3a802015-03-27 16:29:08 -070020
21# NACL_ROOT is the root of the native client repository.
22NACL_ROOT ?= $(shell python -c "import sys; sys.path.insert(0, 'pydir'); \
Jim Stichnoth2e7de232015-11-02 08:25:57 -080023 import utils; print utils.FindBaseNaCl()")
Jan Voung44c3a802015-03-27 16:29:08 -070024
Jan Voung8e32fed2015-06-17 10:16:23 -070025# TOOLCHAIN_ROOT is the location of NaCl/PNaCl toolchains and other
26# tools like qemu.
27TOOLCHAIN_ROOT ?= $(shell readlink -e $(NACL_ROOT)/toolchain/linux_x86)
28
Jan Voung68a06332015-03-05 14:33:38 -080029# PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain.
30# This is used as the default root for finding binutils, libcxx, etc.
Jan Voung8e32fed2015-06-17 10:16:23 -070031PNACL_TOOLCHAIN_ROOT ?= $(shell readlink -e $(TOOLCHAIN_ROOT)/pnacl_newlib_raw)
Jan Voung44c3a802015-03-27 16:29:08 -070032
33# The location of PNaCl tools (e.g., binutils objdump, pnacl-clang++, etc.).
34PNACL_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070035
Reed Kotler2c3c82e2016-01-21 20:33:08 -080036# 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
41CHECK_LIT_TESTS ?= tests_lit
42CHECK_XTEST_TESTS ?= crosstest/Output
43
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070044# Hack to auto-detect autoconf versus cmake build of LLVM. If the LLVM tools
Jim Stichnothe5b58fb2015-06-01 15:17:20 -070045# were dynamically linked with something like libLLVM-3.7svn.so, it is an
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070046# autoconf build, otherwise it is a cmake build. AUTOCONF is set to 0 for
47# cmake, nonzero for autoconf.
48AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-)
49
Jan Voung68a06332015-03-05 14:33:38 -080050# CLANG_PATH is the location of the clang compiler to use for building
51# the host binaries.
Karl Schimpf8fcefc32014-09-15 12:56:50 -070052CLANG_PATH ?= $(shell readlink -e \
Jim Stichnoth2e7de232015-11-02 08:25:57 -080053 $(NACL_ROOT)/../third_party/llvm-build/Release+Asserts/bin)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070054
Jan Voung68a06332015-03-05 14:33:38 -080055# 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.
58LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT)
Karl Schimpf9d928542015-04-16 15:08:05 -070059STDLIB_FLAGS := -stdlib=libc++ -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
Jan Voung68a06332015-03-05 14:33:38 -080060
Jan Voung4c127ba2014-09-19 13:11:36 -070061HOST_ARCH ?= x86_64
Jan Voung839c4ce2014-07-28 15:19:43 -070062ifeq ($(HOST_ARCH),x86_64)
Jim Stichnoth6c6adf12015-04-07 14:22:25 -070063 HOST_FLAGS = -m64
Jan Voung839c4ce2014-07-28 15:19:43 -070064else
65 ifeq ($(HOST_ARCH),x86)
Jim Stichnoth6c6adf12015-04-07 14:22:25 -070066 HOST_FLAGS = -m32
Jan Voung839c4ce2014-07-28 15:19:43 -070067 endif
68endif
69
Jim Stichnothfddef242014-09-26 18:53:41 -070070ifdef DEBUG
71 OBJDIR = build/Debug
72 OPTLEVEL = -O0
Jan Voung44c3a802015-03-27 16:29:08 -070073 LINKOPTLEVEL = -O0
Jim Stichnothfddef242014-09-26 18:53:41 -070074else
75 OBJDIR = build/Release
Jim Stichnotha49e9d92014-12-07 14:25:34 -080076 OPTLEVEL = -O2 -ffunction-sections -fdata-sections
Jan Voung44c3a802015-03-27 16:29:08 -070077 LINKOPTLEVEL = -O2
Jim Stichnothfddef242014-09-26 18:53:41 -070078endif
79
Karl Schimpfb262c5e2014-10-27 14:41:57 -070080# The list of CXX defines that are dependent on build parameters.
Jan Voung44c3a802015-03-27 16:29:08 -070081BASE_CXX_DEFINES =
Jim Stichnothfa4efea2015-01-27 05:06:03 -080082CXX_EXTRA =
83LD_EXTRA =
Karl Schimpfb262c5e2014-10-27 14:41:57 -070084
85ifdef MINIMAL
Jim Stichnothe3c02c22014-12-05 14:16:07 -080086 NOASSERT = 1
Jim Stichnothb88d8c82016-03-11 15:33:00 -080087 NODUMP = 1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070088 OBJDIR := $(OBJDIR)+Min
Jim Stichnothb88d8c82016-03-11 15:33:00 -080089 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
Karl Schimpfb262c5e2014-10-27 14:41:57 -070091else
Jim Stichnothb88d8c82016-03-11 15:33:00 -080092 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
94endif
95
96ifdef NODUMP
97 OBJDIR := $(OBJDIR)+NoDump
98 BASE_CXX_DEFINES += -DALLOW_DUMP=0
99else
100 BASE_CXX_DEFINES += -DALLOW_DUMP=1
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700101endif
102
Jim Stichnoth999a22f2016-03-12 10:22:53 -0800103# Restrict to a single supported target. Current options:
104# SZTARGET=ARM32
105# SZTARGET=MIPS32
106# SZTARGET=X8632
107# SZTARGET=X8664
108ifdef SZTARGET
109 OBJDIR := $(OBJDIR)+T_$(SZTARGET)
110 BASE_CXX_DEFINES += -DSZTARGET=$(SZTARGET)
111endif
112
Jim Stichnothf5fdd232016-05-09 12:24:36 -0700113BASE_CXX_DEFINES += -DPNACL_LLVM
114
Jan Voung44c3a802015-03-27 16:29:08 -0700115CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
116
Jim Stichnoth9c234e22014-10-01 09:28:21 -0700117ifdef NOASSERT
118 ASSERTIONS = -DNDEBUG
119else
120 ASSERTIONS =
121 OBJDIR := $(OBJDIR)+Asserts
122endif
123
Andrew Scull6ef79492015-09-09 15:50:42 -0700124ifdef UBSAN
125 OBJDIR := $(OBJDIR)+UBSan
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800126 CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr \
127 -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700128 LD_EXTRA += -fsanitize=undefined
129endif
130
131ifdef UBSAN_TRAP
132 OBJDIR := $(OBJDIR)+UBSan_Trap
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800133 CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error \
134 -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700135 LD_EXTRA += -fsanitize=undefined-trap
136endif
137
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800138ifdef TSAN
139 OBJDIR := $(OBJDIR)+TSan
140 CXX_EXTRA += -fsanitize=thread
141 LD_EXTRA += -fsanitize=thread
142endif
143
Andrew Scull86df4e92015-07-30 13:54:44 -0700144ifdef ASAN
145 OBJDIR := $(OBJDIR)+ASan
146 CXX_EXTRA += -fsanitize=address
147 LD_EXTRA += -fsanitize=address
148endif
149
Andrew Scull6ef79492015-09-09 15:50:42 -0700150ifdef MSAN
Andrew Scull00741a02015-09-16 19:04:09 -0700151 # TODO(ascull): this has an as yet undiagnosed uninitialized memory access
Andrew Scull6ef79492015-09-09 15:50:42 -0700152 OBJDIR := $(OBJDIR)+MSan
153 CXX_EXTRA += -fsanitize=memory
154 LD_EXTRA += -fsanitize=memory
155endif
156
David Sehrb19d39c2016-01-13 14:17:37 -0800157ifdef FORCEASM
158 FORCEASM_FLAG = --filetype=asm
159 # With --filetype=asm and --sandbox, the llvm-mc assembler emits the lock and
160 # 16-bit prefixes in the "wrong" order, causing the validator to reject the
161 # resulting nexe. So we just disable those tests for now.
162 FORCEASM_XTEST_EXCLUDES = -e x8632,sandbox,test_sync_atomic
163 FORCEASM_LIT_PARAM = --param=FORCEASM
John Porto27fddcc2016-02-02 15:06:09 -0800164 # x86 sandboxing lit tests are disabled because filetype=asm does not
165 # handle bundle_lock pad-to-end correctly.
John Porto56958cb2016-01-14 09:18:18 -0800166 # TODO(jpp): fix this.
167 FORCEASM_LIT_TEST_EXCLUDES = --filter='^(?!.*/x86/sandboxing.ll).*'
David Sehrb19d39c2016-01-13 14:17:37 -0800168else
169 FORCEASM_FLAG =
170 FORCEASM_XTEST_EXCLUDES =
171 FORCEASM_LIT_PARAM =
John Porto56958cb2016-01-14 09:18:18 -0800172 FORCEASM_LIT_TEST_EXCLUDES =
David Sehrb19d39c2016-01-13 14:17:37 -0800173endif
174
David Sehr4c16ac02016-03-17 13:51:42 -0700175ifdef LINUX_MALLOC_PROFILE
176 OBJDIR := $(OBJDIR)+MalProf
177 CXX_EXTRA += -DALLOW_LINUX_MALLOC_PROFILE=1
178 LD_EXTRA += -Wl,--export-dynamic
179endif
180
Jan Voung44c3a802015-03-27 16:29:08 -0700181SB_OBJDIR := $(OBJDIR)+Sandboxed
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800182SBB_OBJDIR := $(OBJDIR)+SandboxedBrowser
Jan Voung44c3a802015-03-27 16:29:08 -0700183
Eric Holk16f80612016-04-04 17:07:42 -0700184V8_DIR = $(NACL_ROOT)/../v8
185V8_CXXFLAGS := -I$(V8_DIR)
186
Derek Schuffbc643132014-05-22 16:39:25 -0700187$(info -----------------------------------------------)
188$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
Jan Voung44c3a802015-03-27 16:29:08 -0700189$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
190$(info Using NACL_ROOT = $(NACL_ROOT))
Jan Voung8e32fed2015-06-17 10:16:23 -0700191$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
Jan Voung68a06332015-03-05 14:33:38 -0800192$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
Jan Voung44c3a802015-03-27 16:29:08 -0700193$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700194$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung68a06332015-03-05 14:33:38 -0800195$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -0700196$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -0700197$(info -----------------------------------------------)
198
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700199LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
Jan Voung44c3a802015-03-27 16:29:08 -0700200SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
201
202# Listing specific libraries that are needed for pnacl-sz
203# and the unittests, since we build "tools-only" for the
204# sandboxed_translators (which doesn't include every library
205# listed by llvm-config).
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700206
207LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
208 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
209 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
210
211ifeq ($(AUTOCONF), 0)
212 # LLVM cmake build
Karl Schimpf28f3f732015-06-24 09:32:40 -0700213 LLVM_LIBS := $(LLVM_LIBS_LIST)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700214 # For the cmake build, the gtest libs end up in the same place as the LLVM
215 # libs, so no "-L..." arg is needed.
216 GTEST_LIB_PATH ?=
217 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
218else
219 # LLVM autoconf build
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700220 LLVM_LIBS := -lLLVM-3.7svn
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700221 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
222 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
223endif
224
Jan Voung44c3a802015-03-27 16:29:08 -0700225LLVM_LDFLAGS := $(LLVM_LIBS) \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700226 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
227 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
Jim Stichnoth7a20a402016-02-24 21:32:53 -0800228SB_LLVM_LDFLAGS := -Wl,--start-group $(LLVM_LIBS_LIST) -Wl,--end-group \
Jan Voung44c3a802015-03-27 16:29:08 -0700229 -L$(SB_LLVM_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -0700230
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -0700231CCACHE := `command -v ccache`
232CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung44c3a802015-03-27 16:29:08 -0700233SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
234SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
Jim Stichnoth7a20a402016-02-24 21:32:53 -0800235SB_FINALIZE := $(PNACL_BIN_PATH)/pnacl-finalize --no-strip-syms
Jan Voung839c4ce2014-07-28 15:19:43 -0700236
Jan Voungc2648c22015-07-30 21:29:14 -0700237# Extra warnings that LLVM's build system adds in addition to -Wall.
238LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
239
Jim Stichnothcaeaa272016-01-10 12:53:44 -0800240# Use g++ to compile, to check for errors/warnings that clang++ might have
241# missed. It's unlikely to link, unless LLVM was also built with g++, so the
242# compile_only target should be used. Note: This ifdef section is deliberately
243# placed here instead of with the other ifdef sections, so that its redefinition
244# of CXX/STDLIB_FLAGS/LLVM_EXTRA_WARNINGS follows their normal definitions.
245ifdef GPLUSPLUS
246 CXX := CCACHE_CPP2=yes $(CCACHE) g++
247 STDLIB_FLAGS :=
Jim Stichnothb0051df2016-01-13 11:39:15 -0800248 LLVM_EXTRA_WARNINGS := \
249 -Wcast-qual \
250 -Wno-comment \
251 -Wno-long-long \
252 -Wno-maybe-uninitialized \
253 -Wno-missing-field-initializers \
254 -Wno-unused-parameter \
255 -Wwrite-strings
Jim Stichnothcaeaa272016-01-10 12:53:44 -0800256 OBJDIR := $(OBJDIR)+Gplusplus
257endif
258
Eric Holk16f80612016-04-04 17:07:42 -0700259BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -fno-rtti \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800260 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
Eric Holk67c7c412016-04-15 13:05:37 -0700261 $(LLVM_EXTRA_WARNINGS) $(CXX_EXTRA) -MP -MD -Werror
Jan Voung44c3a802015-03-27 16:29:08 -0700262
Eric Holk16f80612016-04-04 17:07:42 -0700263ifdef WASM
Eric Holk16f80612016-04-04 17:07:42 -0700264 BASE_CXXFLAGS := $(BASE_CXXFLAGS) $(V8_CXXFLAGS) -DALLOW_WASM=1
265 OBJDIR := $(OBJDIR)+Wasm
266else
Eric Holk67c7c412016-04-15 13:05:37 -0700267 BASE_CXXFLAGS := $(BASE_CXXFLAGS) -DALLOW_WASM=0
Eric Holk16f80612016-04-04 17:07:42 -0700268endif
269
Jim Stichnoth7146e992016-05-02 12:06:22 -0700270# TODO(stichnot,jpp): Restructure static fields in template classes to avoid
271# needing -Wno-undefined-var-template .
Jan Voung44c3a802015-03-27 16:29:08 -0700272CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
Jim Stichnoth7146e992016-05-02 12:06:22 -0700273 $(STDLIB_FLAGS) -Wno-undefined-var-template
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800274SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(BASE_CXX_DEFINES) \
275 -Wno-unknown-pragmas -I$(NACL_ROOT) -I$(NACL_ROOT)/..
Jan Voung44c3a802015-03-27 16:29:08 -0700276
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800277LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800278 $(LD_EXTRA) $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700279# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
280SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700281
Jim Stichnothc59288b2015-11-09 11:38:40 -0800282# List the target-specific source files first, which generally take longer to
283# compile, in the hope of improving parallel build time.
Karl Schimpfab06df32014-10-29 14:58:25 -0700284SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800285 IceAssemblerARM32.cpp \
Jim Stichnothc59288b2015-11-09 11:38:40 -0800286 IceInstARM32.cpp \
287 IceInstMIPS32.cpp \
288 IceInstX8632.cpp \
289 IceInstX8664.cpp \
290 IceTargetLowering.cpp \
291 IceTargetLoweringARM32.cpp \
292 IceTargetLoweringMIPS32.cpp \
David Sehr6b80cf12016-01-21 23:16:58 -0800293 IceTargetLoweringX86.cpp \
Jim Stichnothc59288b2015-11-09 11:38:40 -0800294 IceTargetLoweringX8632.cpp \
295 IceTargetLoweringX8664.cpp \
296 IceAssembler.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800297 IceBrowserCompileServer.cpp \
298 IceCfg.cpp \
299 IceCfgNode.cpp \
300 IceClFlags.cpp \
301 IceCompiler.cpp \
302 IceCompileServer.cpp \
303 IceELFObjectWriter.cpp \
304 IceELFSection.cpp \
305 IceFixups.cpp \
306 IceGlobalContext.cpp \
307 IceGlobalInits.cpp \
308 IceInst.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800309 IceIntrinsics.cpp \
310 IceLiveness.cpp \
311 IceLoopAnalyzer.cpp \
Jim Stichnoth98ba0062016-03-07 09:26:22 -0800312 IceMangling.cpp \
John Portoe82b5602016-02-24 15:58:55 -0800313 IceMemory.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800314 IceOperand.cpp \
Jim Stichnothdd6dcfa2016-04-18 12:52:09 -0700315 IceRangeSpec.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800316 IceRegAlloc.cpp \
317 IceRNG.cpp \
318 IceSwitchLowering.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800319 IceThreading.cpp \
320 IceTimerTree.cpp \
321 IceTranslator.cpp \
322 IceTypes.cpp \
David Sehr4c16ac02016-03-17 13:51:42 -0700323 LinuxMallocProfiling.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800324 main.cpp \
325 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700326
Karl Schimpfab06df32014-10-29 14:58:25 -0700327ifndef MINIMAL
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800328 SRCS += \
Thomas Lively7f0ab862016-06-14 14:06:17 -0700329 IceASanInstrumentation.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800330 IceConverter.cpp \
Thomas Lively7f0ab862016-06-14 14:06:17 -0700331 IceInstrumentation.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800332 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700333endif
334
Eric Holk16f80612016-04-04 17:07:42 -0700335ifdef WASM
336 SRCS += \
337 WasmTranslator.cpp
338endif
339
Jim Stichnothfddef242014-09-26 18:53:41 -0700340OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Jan Voung44c3a802015-03-27 16:29:08 -0700341SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800342SBB_OBJS=$(patsubst %.cpp, $(SBB_OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700343
Jan Voung08c3bcd2014-12-01 17:55:16 -0800344UNITTEST_SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800345 BitcodeMunge.cpp \
346 IceELFSectionTest.cpp \
347 IceParseInstsTest.cpp
John Porto59f2d922015-07-31 13:45:48 -0700348
349# The X86 assembler tests take too long to compile. Given how infrequently the
350# assembler will change, we disable them.
351ifdef CHECK_X86_ASM
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800352 ifndef DEBUG
353 $(error Run check-unit with DEBUG=1 lest your machine perish)
354 endif
John Porto59f2d922015-07-31 13:45:48 -0700355 UNITTEST_SRCS += AssemblerX8632/LowLevel.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800356 AssemblerX8632/DataMov.cpp \
357 AssemblerX8632/Locked.cpp \
358 AssemblerX8632/GPRArith.cpp \
359 AssemblerX8632/XmmArith.cpp \
360 AssemblerX8632/ControlFlow.cpp \
361 AssemblerX8632/Other.cpp \
362 AssemblerX8632/X87.cpp \
363 AssemblerX8664/LowLevel.cpp \
364 AssemblerX8664/DataMov.cpp \
365 AssemblerX8664/Locked.cpp \
366 AssemblerX8664/GPRArith.cpp \
367 AssemblerX8664/XmmArith.cpp \
368 AssemblerX8664/ControlFlow.cpp \
369 AssemblerX8664/Other.cpp
John Porto59f2d922015-07-31 13:45:48 -0700370endif
Jan Voung08c3bcd2014-12-01 17:55:16 -0800371
372UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800373UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800374
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800375NEXES = $(SB_OBJDIR)/pnacl-sz.x8632.nexe \
376 $(SB_OBJDIR)/pnacl-sz.x8664.nexe \
377 $(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe \
378 $(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700379NEXES_LITE = $(SB_OBJDIR)/pnacl-sz.x8664.nexe
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800380
Derek Schuffbc643132014-05-22 16:39:25 -0700381# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800382all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700383
Jan Voung44c3a802015-03-27 16:29:08 -0700384ifdef TSAN
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700385sb sb-lite:
Jan Voung44c3a802015-03-27 16:29:08 -0700386 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
387else
Jim Stichnoth96fac392016-03-11 14:58:23 -0800388sb: $(NEXES) sb_make_symlink exists-sbtc
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700389sb-lite: $(NEXES_LITE) exists-sbtc
Jan Voung44c3a802015-03-27 16:29:08 -0700390endif
391
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700392# SHOW_BUILD_ATTS is an executable that is run to show what build
393# attributes were used to build pnacl-sz.
Karl Schimpfcb6e95a2015-07-23 09:10:03 -0700394SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700395
Karl Schimpf6af63362014-10-29 14:55:00 -0700396# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800397# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700398# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800399make_symlink: $(OBJDIR)/pnacl-sz
400 rm -rf pnacl-sz
401 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700402 @echo "Build Attributes:"
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700403 @$(SHOW_BUILD_ATTS)
Derek Schuffbc643132014-05-22 16:39:25 -0700404
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800405sb_make_symlink: $(NEXES)
406 $(foreach nexe,$(NEXES),rm -rf $(notdir $(nexe)); ln -s $(nexe);)
407
408%.pexe : %.nonfinal.pexe
409 $(SB_FINALIZE) -o $@ $<
Jim Stichnoth7a20a402016-02-24 21:32:53 -0800410
Reed Kotler2c3c82e2016-01-21 20:33:08 -0800411.PHONY: all compile_only make_symlink runtime bloat sb docs help \
Jim Stichnoth96fac392016-03-11 14:58:23 -0800412 help-check-lit help-check-xtest exists-nonsfi-x8632 \
413 exists-nonsfi-arm32 exists-sbtc exists-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800414
415compile_only: $(OBJS)
Jim Stichnothfddef242014-09-26 18:53:41 -0700416
Eric Holk16f80612016-04-04 17:07:42 -0700417V8_LIBDIR=$(V8_DIR)/out/native/lib.target
418
419ifdef WASM
420 V8_LIBS := \
421 $(V8_LIBDIR)/libv8.so \
422 $(V8_LIBDIR)/libicuuc.so \
423 $(V8_LIBDIR)/libicui18n.so
424endif
425
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800426$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800427 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Eric Holk16f80612016-04-04 17:07:42 -0700428 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) $(V8_LIBS)
Derek Schuffbc643132014-05-22 16:39:25 -0700429
Jim Stichnoth7a20a402016-02-24 21:32:53 -0800430$(SB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SB_OBJS)
431 $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS)
432
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800433$(SBB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SBB_OBJS)
434 $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS) \
435 --pnacl-disable-abi-check
Jim Stichnoth7a20a402016-02-24 21:32:53 -0800436
437$(SB_OBJDIR)/pnacl-sz.x8632.nexe: $(SB_OBJDIR)/pnacl-sz.pexe
438 $(SB_TRANSLATE) -arch x86-32 $^ -o $@
439
440$(SB_OBJDIR)/pnacl-sz.x8664.nexe: $(SB_OBJDIR)/pnacl-sz.pexe
441 $(SB_TRANSLATE) -arch x86-64 $^ -o $@
Jan Voung44c3a802015-03-27 16:29:08 -0700442
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800443$(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe
444 $(SB_TRANSLATE) -arch x86-32 $^ -o $@
445
446$(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe
447 $(SB_TRANSLATE) -arch x86-64 $^ -o $@
448
John Porto2187c842015-12-16 07:48:25 -0800449src/IceRegistersARM32.def: pydir/gen_arm32_reg_tables.py
450 python $< > $@
451
John Porto70e3f1c2016-03-16 04:20:49 -0700452-include $(foreach dep,$(SRCS:.cpp=.d),$(OBJDIR)/$(dep))
453$(OBJS): $(OBJDIR)/%.o: src/%.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700454 $(CXX) -c $(CXXFLAGS) $< -o $@
455
John Porto70e3f1c2016-03-16 04:20:49 -0700456-include $(foreach dep,$(SRCS:.cpp=.d),$(SB_OBJDIR)/$(dep))
457$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800458 $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=0 $< -o $@
459
John Porto70e3f1c2016-03-16 04:20:49 -0700460-include $(foreach dep,$(SRCS:.cpp=.d),$(SBB_OBJDIR)/$(dep))
461$(SBB_OBJS): $(SBB_OBJDIR)/%.o: src/%.cpp
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800462 $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=1 $< -o $@
Jan Voung44c3a802015-03-27 16:29:08 -0700463
Jan Voung08c3bcd2014-12-01 17:55:16 -0800464$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
Jim Stichnothe7e9b022015-04-21 15:05:22 -0700465 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800466 -lgtest -lgtest_main -ldl \
467 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Jan Voung08c3bcd2014-12-01 17:55:16 -0800468
John Porto70e3f1c2016-03-16 04:20:49 -0700469-include $(foreach dep,$(UNITTEST_SRCS:.cpp=.d),$(OBJDIR)/unittest/$(dep))
470$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp
Jan Voung08c3bcd2014-12-01 17:55:16 -0800471 $(CXX) -c $(CXXFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800472 -Isrc/ \
473 -Iunittest/ \
474 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
475 -I$(LLVM_SRC_PATH) \
476 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
Jim Stichnoth5526c172016-03-08 22:46:19 -0800477 -Wno-expansion-to-defined \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800478 $< -o $@
Jan Voung08c3bcd2014-12-01 17:55:16 -0800479
Jim Stichnothfddef242014-09-26 18:53:41 -0700480$(OBJS): | $(OBJDIR)
Jan Voung44c3a802015-03-27 16:29:08 -0700481$(SB_OBJS): | $(SB_OBJDIR)
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800482$(SBB_OBJS): | $(SBB_OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700483
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800484$(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 \
485 $(OBJDIR)/unittest/AssemblerX8664
Jan Voung08c3bcd2014-12-01 17:55:16 -0800486
Jim Stichnothfddef242014-09-26 18:53:41 -0700487$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700488 @mkdir -p $@
Jan Voung44c3a802015-03-27 16:29:08 -0700489$(SB_OBJDIR):
490 @mkdir -p $@
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800491$(SBB_OBJDIR):
492 @mkdir -p $@
Derek Schuffbc643132014-05-22 16:39:25 -0700493
Jan Voung08c3bcd2014-12-01 17:55:16 -0800494$(OBJDIR)/unittest: $(OBJDIR)
495 @mkdir -p $@
496
John Porto2fea26c2015-07-28 16:28:07 -0700497$(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest
498 @mkdir -p $@
499$(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest
500 @mkdir -p $@
501
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800502RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c \
503 runtime/szrt_asm_x8632.s runtime/szrt_asm_x8664.s \
Thomas Lively4e81fe02016-06-15 10:00:21 -0700504 runtime/szrt_asm_arm32.s runtime/szrt_asan.c
Jan Voung050deaa2015-06-12 15:12:05 -0700505RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800506 build/runtime/szrt_nonsfi_x8632.o \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800507 build/runtime/szrt_native_x8664.o build/runtime/szrt_sb_x8664.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800508 build/runtime/szrt_nonsfi_x8664.o \
509 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o \
Thomas Lively4e81fe02016-06-15 10:00:21 -0700510 build/runtime/szrt_nonsfi_arm32.o \
511 build/runtime/szrt_asan_x8632.o build/runtime/szrt_asan_x8664.o \
512 build/runtime/szrt_asan_arm32.o
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800513
514runtime: $(RT_OBJ)
515
516# Use runtime.is.built so that build-runtime.py is invoked only once
517# even in a parallel build.
518.INTERMEDIATE: runtime.is.built
519$(RT_OBJ): runtime.is.built
John Portof8b4cc82015-06-09 18:06:19 -0700520runtime.is.built: $(RT_SRC) pydir/build-runtime.py
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800521 @echo ================ Building Subzero runtime ================
Jan Voung68a06332015-03-05 14:33:38 -0800522 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800523
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800524check-lit: $(OBJDIR)/pnacl-sz make_symlink
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700525 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Reed Kotler2c3c82e2016-01-21 20:33:08 -0800526 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_LIT_TESTS) \
John Porto56958cb2016-01-14 09:18:18 -0800527 $(FORCEASM_LIT_TEST_EXCLUDES) $(FORCEASM_LIT_PARAM)
Jim Stichnothac9c9432014-08-26 14:07:13 -0700528
Karl Schimpfab06df32014-10-29 14:58:25 -0700529ifdef MINIMAL
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700530check-xtest check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothc9258222015-03-13 11:59:49 -0700531 @echo "Crosstests disabled, minimal build"
Karl Schimpfab06df32014-10-29 14:58:25 -0700532else
Jim Stichnoth96fac392016-03-11 14:58:23 -0800533check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime \
Jim Stichnoth7dbe8022016-05-31 12:21:51 -0700534 exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700535 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
536 # For (slow) sandboxed tests, limit to Om1/sse4.1.
John Porto94e97f62016-02-18 08:02:10 -0800537 # run.py (used to run the sandboxed xtests) does not support
538 # specifying -cpu cortex-a15 to qemu, hence we disable the
539 # hwdiv-arm tests.
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700540 ./pydir/crosstest_generator.py -v --lit \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800541 --toolchain-root $(TOOLCHAIN_ROOT) \
David Sehrb19d39c2016-01-13 14:17:37 -0800542 $(FORCEASM_FLAG) \
543 $(FORCEASM_XTEST_EXCLUDES) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800544 -i x8632,native,sse2 \
545 -i x8632,native,sse4.1,test_vector_ops \
546 -i x8632,sandbox,sse4.1,Om1 \
Jim Stichnoth57a8aab2016-01-06 09:34:36 -0800547 -i x8632,nonsfi,sse2,O2 \
John Porto008f4ce2015-12-24 13:22:18 -0800548 -i x8664,native,sse2 \
549 -i x8664,native,sse4.1,test_vector_ops \
John Porto56958cb2016-01-14 09:18:18 -0800550 -i x8664,sandbox,sse4.1,Om1 \
John Porto94e97f62016-02-18 08:02:10 -0800551 -i arm32 \
John Portoe82b5602016-02-24 15:58:55 -0800552 -e arm32,sandbox,hwdiv-arm
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700553 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Reed Kotler2c3c82e2016-01-21 20:33:08 -0800554 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700555check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \
Jim Stichnoth7dbe8022016-05-31 12:21:51 -0700556 exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700557 # Do all native/sse2/neon tests, which are relatively fast.
558 # Limit to test_global+mem_intrin for sandbox+nonsfi because sandbox and
559 # nonsfi builds are slow, and test_global and mem_intrin are the most
560 # common sources of problems.
561 ./pydir/crosstest_generator.py -v --lit \
562 --toolchain-root $(TOOLCHAIN_ROOT) \
563 $(FORCEASM_FLAG) \
564 $(FORCEASM_XTEST_EXCLUDES) \
565 -i x8632,native,sse2,O2 \
566 -i x8664,native,sse2,O2 \
567 -i arm32,native,neon,O2 \
568 -i x8632,sse2,O2,test_global \
569 -i x8632,sse2,O2,mem_intrin \
570 -i x8664,sse2,O2,test_global \
571 -i x8664,sse2,O2,mem_intrin \
572 -i arm32,neon,O2,test_global \
573 -i arm32,neon,O2,mem_intrin \
574 -e x8664,nonsfi
575 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
576 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS)
Jim Stichnoth7dbe8022016-05-31 12:21:51 -0700577crosstest/test_arith_ll.ll: pydir/gen_test_arith_ll.py
578 python $< > $@
Karl Schimpfab06df32014-10-29 14:58:25 -0700579endif
Derek Schuffbc643132014-05-22 16:39:25 -0700580
Jim Stichnothc9258222015-03-13 11:59:49 -0700581check-unit: $(OBJDIR)/run_unittests
582 $(OBJDIR)/run_unittests
583
Jim Stichnothc59288b2015-11-09 11:38:40 -0800584# List the spec2k components in roughly reverse order of runtime, to help with
585# parallel execution speed.
586ALLSPEC := 253.perlbmk 177.mesa 188.ammp 256.bzip2 164.gzip 179.art 183.equake \
587 175.vpr 176.gcc 181.mcf 186.crafty 197.parser 254.gap 255.vortex \
588 300.twolf 252.eon
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800589.PHONY: $(ALLSPEC)
590
591TARGET := x8632
592ifeq ($(TARGET),x8632)
593 TARGETFLAG=x8632
594 SETUP=SetupGccX8632Opt
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800595 SPEC := --filetype=obj
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800596endif
John Porto3c275ce2015-12-22 08:14:00 -0800597ifeq ($(TARGET),x8664)
598 TARGETFLAG=x8664
599 SETUP=SetupGccX8664Opt
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800600 SPEC := --filetype=obj
John Porto3c275ce2015-12-22 08:14:00 -0800601endif
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800602ifeq ($(TARGET),arm32)
603 TARGETFLAG=arm32
604 SETUP=SetupGccArmOpt
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800605 SPEC := --filetype=obj
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800606endif
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800607SPECFLAGS := -O2
Jim Stichnoth45f77002016-04-01 18:26:16 -0700608SPECRUN := --run
Jim Stichnothc59288b2015-11-09 11:38:40 -0800609%.spec2k: % $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothbc3bd502016-01-20 15:01:39 -0800610 ./pydir/szbuild_spec2k.py -v \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700611 $(SPECFLAGS) --target=$(TARGETFLAG) $(SPEC) $< $(SPECRUN)
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800612
Jim Stichnoth96fac392016-03-11 14:58:23 -0800613check-spec: exists-spec $(ALLSPEC:=.spec2k)
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800614
Jim Stichnothc9258222015-03-13 11:59:49 -0700615check: check-lit check-unit check-xtest
616
Jim Stichnoth96fac392016-03-11 14:58:23 -0800617NONSFI_LOADER_X8632 = \
618 $(NACL_ROOT)/scons-out/opt-linux-x86-32/obj/src/nonsfi/loader/nonsfi_loader
619NONSFI_LOADER_ARM32 = \
620 $(NACL_ROOT)/scons-out/opt-linux-arm/obj/src/nonsfi/loader/nonsfi_loader
621SBTC_LIBFILE = $(SB_LLVM_PATH)/lib/libLLVMSupport.a
622SPEC_SAMPLE_PEXE = $(NACL_ROOT)/tests/spec2k/176.gcc/gcc.opt.stripped.pexe
623
624exists-nonsfi-x8632:
625 @if [ ! -f $(NONSFI_LOADER_X8632) ] ; then \
626 echo "Missing file $(NONSFI_LOADER_X8632)"; \
Jim Stichnoth7146e992016-05-02 12:06:22 -0700627 echo "Consider running './scons nonsfi_loader'" \
Jim Stichnoth96fac392016-03-11 14:58:23 -0800628 "in the native_client directory."; \
629 exit 1 ; \
630 fi
631
632exists-nonsfi-arm32:
633 @if [ ! -f $(NONSFI_LOADER_ARM32) ] ; then \
634 echo "Missing file $(NONSFI_LOADER_ARM32)"; \
Jim Stichnoth7146e992016-05-02 12:06:22 -0700635 echo "Consider running './scons platform=arm nonsfi_loader'" \
Jim Stichnoth96fac392016-03-11 14:58:23 -0800636 "in the native_client directory."; \
637 exit 1 ; \
638 fi
639
640exists-sbtc:
641 @if [ ! -f $(SBTC_LIBFILE) ] ; then \
642 echo "Missing file $(SBTC_LIBFILE)"; \
643 echo "Consider running 'toolchain_build_pnacl.py --build-sbtc'."; \
644 exit 1 ; \
645 fi
646
647exists-spec:
648 @if [ ! -f $(SPEC_SAMPLE_PEXE) ] ; then \
649 echo "Missing file $(SPEC_SAMPLE_PEXE)"; \
650 echo "Consider running" \
Jim Stichnoth7146e992016-05-02 12:06:22 -0700651 "'./run_all.sh BuildBenchmarks 0 SetupPnaclX8632Opt'" \
Jim Stichnoth96fac392016-03-11 14:58:23 -0800652 "in the native_client/tests/spec2k directory."; \
653 exit 1 ; \
654 fi
655
656check-presubmit presubmit: exists-nonsfi-x8632 exists-nonsfi-arm32 \
657 exists-sbtc exists-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800658# Make sure clang-format gets run.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800659 +make -f Makefile.standalone format
Jim Stichnoth23bee882015-11-17 06:14:05 -0800660# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800661 +make -f Makefile.standalone \
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800662 MINIMAL=1 check
Jim Stichnothfc22f772015-11-22 06:06:34 -0800663# Check that there are no g++ build errors or warnings.
664 +make -f Makefile.standalone \
665 GPLUSPLUS=1 compile_only
Jim Stichnoth23bee882015-11-17 06:14:05 -0800666# Check the x86 assembler unit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800667 +make -f Makefile.standalone \
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800668 DEBUG=1 CHECK_X86_ASM=1 check-unit sb
David Sehrb19d39c2016-01-13 14:17:37 -0800669# Run lit tests, cross tests, unit tests, and spec2k/x86-32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800670 +make -f Makefile.standalone \
Jim Stichnoth98ba0062016-03-07 09:26:22 -0800671 check check-spec
John Porto4ab4fbe2016-01-20 13:44:30 -0800672# Run spec2k/x86-64.
673 +make -f Makefile.standalone \
674 TARGET=x8664 check-spec
Jim Stichnoth45f77002016-04-01 18:26:16 -0700675# Run spec2k/x86-64 with sandboxing.
676 +make -f Makefile.standalone \
677 SPECFLAGS='-O2 --sandbox' TARGET=x8664 check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800678# Build spec2k under -Om1/x86-32, to check for liveness errors.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800679 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700680 SPECFLAGS='-Om1' SPECRUN= check-spec
John Porto4ab4fbe2016-01-20 13:44:30 -0800681# Build spec2k under -Om1/x86-64, to check for liveness errors.
682 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700683 SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800684# Run spec2k for x86-32 without advanced phi lowering.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800685 +make -f Makefile.standalone \
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800686 SPECFLAGS='-O2 --sz=--phi-edge-split=0' check-spec
John Porto4ab4fbe2016-01-20 13:44:30 -0800687# Run spec2k for x86-64 without advanced phi lowering.
688 +make -f Makefile.standalone \
Jim Stichnothc8f56a32016-03-07 09:54:15 -0800689 SPECFLAGS='-O2 --sz=--phi-edge-split=0' TARGET=x8664 check-spec
David Sehrb19d39c2016-01-13 14:17:37 -0800690# Run cross tests and lit tests to validate filetype=asm output.
691 +make -f Makefile.standalone \
692 FORCEASM=1 check-xtest check-lit
Jim Stichnoth23bee882015-11-17 06:14:05 -0800693# Build spec2k for arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800694 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700695 TARGET=arm32 SPECRUN= check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800696# Build spec2k under -Om1/arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800697 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700698 TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec
John Portob8196652016-01-19 06:19:14 -0800699# Run a few spec2k tests for arm32 using qemu. Keep the list sorted in
700# roughly reverse order of runtime.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800701 +make -f Makefile.standalone \
John Portob8196652016-01-19 06:19:14 -0800702 TARGET=arm32 ALLSPEC='252.eon 254.gap 176.gcc 181.mcf' check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800703# Provide validation of user awesomeness!
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800704 echo Success
705
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700706presubmit-lite: exists-nonsfi-x8632 exists-nonsfi-arm32 \
707 exists-sbtc exists-spec
708# Make sure clang-format gets run.
709 +make -f Makefile.standalone format
710# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
711 +make -f Makefile.standalone \
Jim Stichnothabe7dd52016-03-21 14:53:03 -0700712 MINIMAL=1 check sb-lite
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700713# Check that there are no g++ build errors or warnings.
714 +make -f Makefile.standalone \
715 GPLUSPLUS=1 compile_only
716# Run lit tests, cross tests, unit tests, and spec2k/x86-32.
717 +make -f Makefile.standalone \
718 check-lit check-unit check-spec
719 +make -f Makefile.standalone \
720 check-xtest-lite
721# Run spec2k/x86-64.
722 +make -f Makefile.standalone \
723 TARGET=x8664 check-spec
724# Build spec2k under -Om1/x86-32, to check for liveness errors.
725 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700726 SPECFLAGS='-Om1' SPECRUN= check-spec
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700727# Build spec2k under -Om1/x86-64, to check for liveness errors.
728 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700729 SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700730# Run cross tests and lit tests to validate filetype=asm output.
731 +make -f Makefile.standalone \
732 FORCEASM=1 check-lit
733 +make -f Makefile.standalone \
734 FORCEASM=1 check-xtest-lite
735# Build spec2k under -Om1/arm32.
736 +make -f Makefile.standalone \
Jim Stichnoth45f77002016-04-01 18:26:16 -0700737 TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec
Jim Stichnothe13d1eb2016-03-21 12:49:33 -0700738# Run a few spec2k tests for arm32 using qemu. Keep the list sorted in
739# roughly reverse order of runtime.
740 +make -f Makefile.standalone \
741 TARGET=arm32 ALLSPEC='254.gap 176.gcc 181.mcf' check-spec
742# Provide validation of user awesomeness!
743 echo Success
744
Jim Stichnothdd842db2015-01-27 12:53:53 -0800745FORMAT_BLACKLIST =
746# Add one of the following lines for each source file to ignore.
747FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Karl Schimpf74cd8832015-06-23 11:05:01 -0700748FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
Karl Schimpf3e53dc92015-10-07 13:24:01 -0700749FORMAT_BLACKLIST += ! -name assembler_arm.h
750FORMAT_BLACKLIST += ! -name assembler_arm.cc
Eric Holk16f80612016-04-04 17:07:42 -0700751FORMAT_BLACKLIST += ! -path "./wasm-install/*"
Jim Stichnotha5b16ab2016-05-10 11:20:41 -0700752FORMAT_BLACKLIST += ! -path "./pnacl-llvm/*"
Derek Schuffbc643132014-05-22 16:39:25 -0700753format:
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700754 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800755 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700756
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700757format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700758 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800759 PATH=$(PNACL_BIN_PATH):$(PATH) \
760 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
761 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700762
Jim Stichnoth307e3262015-02-12 16:10:37 -0800763bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800764 nm -C -S -l pnacl-sz | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800765 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800766 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800767
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800768bloat-sb: sb_make_symlink
769 $(foreach nexe,$(NEXES),nm -C -S -l $(nexe) | bloat/bloat.py \
770 --nm-output=/dev/stdin syms > build/$(notdir $(nexe)).bloat.json;)
771 @echo "See Subzero size breakdown in:"
772 @$(foreach nexe,$(NEXES),echo " bloat/$(notdir $(nexe)).bloat.html";)
773
Andrew Sculla509e1d2015-06-29 11:07:08 -0700774docs:
Reed Kotler4cba1cb2016-01-07 08:45:13 -0800775 make -C docs -f Makefile.standalone
Andrew Sculla509e1d2015-06-29 11:07:08 -0700776
Reed Kotler2c3c82e2016-01-21 20:33:08 -0800777help:
778 @cat Makefile.standalone-help/help.txt
779
780help-check-lit:
781 @cat Makefile.standalone-help/check-lit.txt
782
783help-check-xtest:
784 @cat Makefile.standalone-help/check-xtest.txt
785
Derek Schuffbc643132014-05-22 16:39:25 -0700786clean:
Jim Stichnothc4ed5492016-02-29 09:16:00 -0800787 rm -rf pnacl-sz *.o $(foreach nexe,$(NEXES),$(notdir $(nexe))) \
788 $(OBJDIR) $(SB_OBJDIR) $(SBB_OBJDIR) build/*.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700789
790clean-all: clean
Jim Stichnoth96fac392016-03-11 14:58:23 -0800791 rm -rf build/ crosstest/Output/