blob: 1f3a90d48783db0ad0d5fa23e20edacbe7554936 [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
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070036# Hack to auto-detect autoconf versus cmake build of LLVM. If the LLVM tools
Jim Stichnothe5b58fb2015-06-01 15:17:20 -070037# were dynamically linked with something like libLLVM-3.7svn.so, it is an
Jim Stichnoth0a9e1262015-04-21 09:59:21 -070038# autoconf build, otherwise it is a cmake build. AUTOCONF is set to 0 for
39# cmake, nonzero for autoconf.
40AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-)
41
Jan Voung68a06332015-03-05 14:33:38 -080042# CLANG_PATH is the location of the clang compiler to use for building
43# the host binaries.
Karl Schimpf8fcefc32014-09-15 12:56:50 -070044CLANG_PATH ?= $(shell readlink -e \
Jim Stichnoth2e7de232015-11-02 08:25:57 -080045 $(NACL_ROOT)/../third_party/llvm-build/Release+Asserts/bin)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070046
Jan Voung68a06332015-03-05 14:33:38 -080047# LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should
48# contain header files and corresponding libraries. This is used for
49# building the host binaries in conjuction with clang.
50LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT)
Karl Schimpf9d928542015-04-16 15:08:05 -070051STDLIB_FLAGS := -stdlib=libc++ -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
Jan Voung68a06332015-03-05 14:33:38 -080052
Jan Voung4c127ba2014-09-19 13:11:36 -070053HOST_ARCH ?= x86_64
Jan Voung839c4ce2014-07-28 15:19:43 -070054ifeq ($(HOST_ARCH),x86_64)
Jim Stichnoth6c6adf12015-04-07 14:22:25 -070055 HOST_FLAGS = -m64
Jan Voung839c4ce2014-07-28 15:19:43 -070056else
57 ifeq ($(HOST_ARCH),x86)
Jim Stichnoth6c6adf12015-04-07 14:22:25 -070058 HOST_FLAGS = -m32
Jan Voung839c4ce2014-07-28 15:19:43 -070059 endif
60endif
61
Jim Stichnothfddef242014-09-26 18:53:41 -070062ifdef DEBUG
63 OBJDIR = build/Debug
64 OPTLEVEL = -O0
Jan Voung44c3a802015-03-27 16:29:08 -070065 LINKOPTLEVEL = -O0
Jim Stichnothfddef242014-09-26 18:53:41 -070066else
67 OBJDIR = build/Release
Jim Stichnotha49e9d92014-12-07 14:25:34 -080068 OPTLEVEL = -O2 -ffunction-sections -fdata-sections
Jan Voung44c3a802015-03-27 16:29:08 -070069 LINKOPTLEVEL = -O2
Jim Stichnothfddef242014-09-26 18:53:41 -070070endif
71
Karl Schimpfb262c5e2014-10-27 14:41:57 -070072# The list of CXX defines that are dependent on build parameters.
Jan Voung44c3a802015-03-27 16:29:08 -070073BASE_CXX_DEFINES =
Jim Stichnothfa4efea2015-01-27 05:06:03 -080074CXX_EXTRA =
75LD_EXTRA =
Karl Schimpfb262c5e2014-10-27 14:41:57 -070076
77ifdef MINIMAL
Jim Stichnothe3c02c22014-12-05 14:16:07 -080078 NOASSERT = 1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070079 OBJDIR := $(OBJDIR)+Min
Jan Voung44c3a802015-03-27 16:29:08 -070080 BASE_CXX_DEFINES += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080081 -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_MINIMAL_BUILD=1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070082else
Jan Voung44c3a802015-03-27 16:29:08 -070083 BASE_CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
Jim Stichnoth0d4fc922015-12-13 21:36:33 -080084 -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_MINIMAL_BUILD=0
Karl Schimpfb262c5e2014-10-27 14:41:57 -070085endif
86
Jan Voung44c3a802015-03-27 16:29:08 -070087SB_CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=1
88CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
89
Jim Stichnoth9c234e22014-10-01 09:28:21 -070090ifdef NOASSERT
91 ASSERTIONS = -DNDEBUG
92else
93 ASSERTIONS =
94 OBJDIR := $(OBJDIR)+Asserts
95endif
96
Andrew Scull6ef79492015-09-09 15:50:42 -070097ifdef UBSAN
98 OBJDIR := $(OBJDIR)+UBSan
Jim Stichnoth2e7de232015-11-02 08:25:57 -080099 CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr \
100 -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700101 LD_EXTRA += -fsanitize=undefined
102endif
103
104ifdef UBSAN_TRAP
105 OBJDIR := $(OBJDIR)+UBSan_Trap
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800106 CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error \
107 -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700108 LD_EXTRA += -fsanitize=undefined-trap
109endif
110
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800111ifdef TSAN
112 OBJDIR := $(OBJDIR)+TSan
113 CXX_EXTRA += -fsanitize=thread
114 LD_EXTRA += -fsanitize=thread
115endif
116
Andrew Scull86df4e92015-07-30 13:54:44 -0700117ifdef ASAN
118 OBJDIR := $(OBJDIR)+ASan
119 CXX_EXTRA += -fsanitize=address
120 LD_EXTRA += -fsanitize=address
121endif
122
Andrew Scull6ef79492015-09-09 15:50:42 -0700123ifdef MSAN
Andrew Scull00741a02015-09-16 19:04:09 -0700124 # TODO(ascull): this has an as yet undiagnosed uninitialized memory access
Andrew Scull6ef79492015-09-09 15:50:42 -0700125 OBJDIR := $(OBJDIR)+MSan
126 CXX_EXTRA += -fsanitize=memory
127 LD_EXTRA += -fsanitize=memory
128endif
129
David Sehrb19d39c2016-01-13 14:17:37 -0800130ifdef FORCEASM
131 FORCEASM_FLAG = --filetype=asm
132 # With --filetype=asm and --sandbox, the llvm-mc assembler emits the lock and
133 # 16-bit prefixes in the "wrong" order, causing the validator to reject the
134 # resulting nexe. So we just disable those tests for now.
135 FORCEASM_XTEST_EXCLUDES = -e x8632,sandbox,test_sync_atomic
136 FORCEASM_LIT_PARAM = --param=FORCEASM
137else
138 FORCEASM_FLAG =
139 FORCEASM_XTEST_EXCLUDES =
140 FORCEASM_LIT_PARAM =
141endif
142
Jan Voung44c3a802015-03-27 16:29:08 -0700143SB_OBJDIR := $(OBJDIR)+Sandboxed
144
Derek Schuffbc643132014-05-22 16:39:25 -0700145$(info -----------------------------------------------)
146$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
Jan Voung44c3a802015-03-27 16:29:08 -0700147$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
148$(info Using NACL_ROOT = $(NACL_ROOT))
Jan Voung8e32fed2015-06-17 10:16:23 -0700149$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
Jan Voung68a06332015-03-05 14:33:38 -0800150$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
Jan Voung44c3a802015-03-27 16:29:08 -0700151$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700152$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung68a06332015-03-05 14:33:38 -0800153$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -0700154$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -0700155$(info -----------------------------------------------)
156
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700157LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
Jan Voung44c3a802015-03-27 16:29:08 -0700158SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
159
160# Listing specific libraries that are needed for pnacl-sz
161# and the unittests, since we build "tools-only" for the
162# sandboxed_translators (which doesn't include every library
163# listed by llvm-config).
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700164
165LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
166 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
167 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
168
169ifeq ($(AUTOCONF), 0)
170 # LLVM cmake build
Karl Schimpf28f3f732015-06-24 09:32:40 -0700171 LLVM_LIBS := $(LLVM_LIBS_LIST)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700172 # For the cmake build, the gtest libs end up in the same place as the LLVM
173 # libs, so no "-L..." arg is needed.
174 GTEST_LIB_PATH ?=
175 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
176else
177 # LLVM autoconf build
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700178 LLVM_LIBS := -lLLVM-3.7svn
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700179 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
180 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
181endif
182
Jan Voung44c3a802015-03-27 16:29:08 -0700183LLVM_LDFLAGS := $(LLVM_LIBS) \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700184 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
185 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
186SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
Jan Voung44c3a802015-03-27 16:29:08 -0700187 -L$(SB_LLVM_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -0700188
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -0700189CCACHE := `command -v ccache`
190CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung44c3a802015-03-27 16:29:08 -0700191SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
192SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
Jan Voung839c4ce2014-07-28 15:19:43 -0700193
Jan Voungc2648c22015-07-30 21:29:14 -0700194# Extra warnings that LLVM's build system adds in addition to -Wall.
195LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
196
Jim Stichnothcaeaa272016-01-10 12:53:44 -0800197# Use g++ to compile, to check for errors/warnings that clang++ might have
198# missed. It's unlikely to link, unless LLVM was also built with g++, so the
199# compile_only target should be used. Note: This ifdef section is deliberately
200# placed here instead of with the other ifdef sections, so that its redefinition
201# of CXX/STDLIB_FLAGS/LLVM_EXTRA_WARNINGS follows their normal definitions.
202ifdef GPLUSPLUS
203 CXX := CCACHE_CPP2=yes $(CCACHE) g++
204 STDLIB_FLAGS :=
Jim Stichnothb0051df2016-01-13 11:39:15 -0800205 LLVM_EXTRA_WARNINGS := \
206 -Wcast-qual \
207 -Wno-comment \
208 -Wno-long-long \
209 -Wno-maybe-uninitialized \
210 -Wno-missing-field-initializers \
211 -Wno-unused-parameter \
212 -Wwrite-strings
Jim Stichnothcaeaa272016-01-10 12:53:44 -0800213 OBJDIR := $(OBJDIR)+Gplusplus
214endif
215
Jan Voung44c3a802015-03-27 16:29:08 -0700216BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800217 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
218 $(LLVM_EXTRA_WARNINGS) $(CXX_EXTRA)
Jan Voung44c3a802015-03-27 16:29:08 -0700219
220CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800221 $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700222SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(SB_CXX_DEFINES)
223
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800224LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800225 $(LD_EXTRA) $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700226# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
227SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700228
Jim Stichnothc59288b2015-11-09 11:38:40 -0800229# List the target-specific source files first, which generally take longer to
230# compile, in the hope of improving parallel build time.
Karl Schimpfab06df32014-10-29 14:58:25 -0700231SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800232 IceAssemblerARM32.cpp \
Jim Stichnothc59288b2015-11-09 11:38:40 -0800233 IceInstARM32.cpp \
234 IceInstMIPS32.cpp \
235 IceInstX8632.cpp \
236 IceInstX8664.cpp \
237 IceTargetLowering.cpp \
238 IceTargetLoweringARM32.cpp \
239 IceTargetLoweringMIPS32.cpp \
240 IceTargetLoweringX8632.cpp \
241 IceTargetLoweringX8664.cpp \
242 IceAssembler.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800243 IceBrowserCompileServer.cpp \
244 IceCfg.cpp \
245 IceCfgNode.cpp \
246 IceClFlags.cpp \
247 IceCompiler.cpp \
248 IceCompileServer.cpp \
249 IceELFObjectWriter.cpp \
250 IceELFSection.cpp \
251 IceFixups.cpp \
252 IceGlobalContext.cpp \
253 IceGlobalInits.cpp \
254 IceInst.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800255 IceIntrinsics.cpp \
256 IceLiveness.cpp \
257 IceLoopAnalyzer.cpp \
258 IceOperand.cpp \
259 IceRegAlloc.cpp \
260 IceRNG.cpp \
261 IceSwitchLowering.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800262 IceThreading.cpp \
263 IceTimerTree.cpp \
264 IceTranslator.cpp \
265 IceTypes.cpp \
266 main.cpp \
267 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700268
Karl Schimpfab06df32014-10-29 14:58:25 -0700269ifndef MINIMAL
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800270 SRCS += \
271 IceConverter.cpp \
272 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700273endif
274
Jim Stichnothfddef242014-09-26 18:53:41 -0700275OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Jan Voung44c3a802015-03-27 16:29:08 -0700276SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700277
Jan Voung08c3bcd2014-12-01 17:55:16 -0800278UNITTEST_SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800279 BitcodeMunge.cpp \
280 IceELFSectionTest.cpp \
281 IceParseInstsTest.cpp
John Porto59f2d922015-07-31 13:45:48 -0700282
283# The X86 assembler tests take too long to compile. Given how infrequently the
284# assembler will change, we disable them.
285ifdef CHECK_X86_ASM
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800286 ifndef DEBUG
287 $(error Run check-unit with DEBUG=1 lest your machine perish)
288 endif
John Porto59f2d922015-07-31 13:45:48 -0700289 UNITTEST_SRCS += AssemblerX8632/LowLevel.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800290 AssemblerX8632/DataMov.cpp \
291 AssemblerX8632/Locked.cpp \
292 AssemblerX8632/GPRArith.cpp \
293 AssemblerX8632/XmmArith.cpp \
294 AssemblerX8632/ControlFlow.cpp \
295 AssemblerX8632/Other.cpp \
296 AssemblerX8632/X87.cpp \
297 AssemblerX8664/LowLevel.cpp \
298 AssemblerX8664/DataMov.cpp \
299 AssemblerX8664/Locked.cpp \
300 AssemblerX8664/GPRArith.cpp \
301 AssemblerX8664/XmmArith.cpp \
302 AssemblerX8664/ControlFlow.cpp \
303 AssemblerX8664/Other.cpp
John Porto59f2d922015-07-31 13:45:48 -0700304endif
Jan Voung08c3bcd2014-12-01 17:55:16 -0800305
306UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800307UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800308
Derek Schuffbc643132014-05-22 16:39:25 -0700309# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800310all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700311
Jan Voung44c3a802015-03-27 16:29:08 -0700312ifdef TSAN
313sb:
314 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
315else
316sb: $(SB_OBJDIR)/pnacl-sz.x86-32.nexe
317endif
318
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700319# SHOW_BUILD_ATTS is an executable that is run to show what build
320# attributes were used to build pnacl-sz.
Karl Schimpfcb6e95a2015-07-23 09:10:03 -0700321SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700322
Karl Schimpf6af63362014-10-29 14:55:00 -0700323# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800324# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700325# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800326make_symlink: $(OBJDIR)/pnacl-sz
327 rm -rf pnacl-sz
328 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700329 @echo "Build Attributes:"
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700330 @$(SHOW_BUILD_ATTS)
Derek Schuffbc643132014-05-22 16:39:25 -0700331
Jim Stichnoth23bee882015-11-17 06:14:05 -0800332.PHONY: all compile_only make_symlink runtime bloat sb docs
333
334compile_only: $(OBJS)
Jim Stichnothfddef242014-09-26 18:53:41 -0700335
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800336$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800337 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800338 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700339
Jan Voung44c3a802015-03-27 16:29:08 -0700340$(SB_OBJDIR)/pnacl-sz.x86-32.nexe: $(SB_OBJS)
341 $(eval PNACL_SZ_BASE := $(patsubst %.nexe, %, $@))
342 $(SB_CXX) $(SB_LDFLAGS) -o $(PNACL_SZ_BASE).nonfinal.pexe $^ \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800343 $(SB_LLVM_LDFLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700344 $(SB_TRANSLATE) -arch x86-32 $(PNACL_SZ_BASE).nonfinal.pexe -o $@ \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800345 --allow-llvm-bitcode-input
Jan Voung44c3a802015-03-27 16:29:08 -0700346
John Porto2187c842015-12-16 07:48:25 -0800347src/IceRegistersARM32.def: pydir/gen_arm32_reg_tables.py
348 python $< > $@
349
Jim Stichnothdd842db2015-01-27 12:53:53 -0800350# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700351$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700352 $(CXX) -c $(CXXFLAGS) $< -o $@
353
Jan Voung44c3a802015-03-27 16:29:08 -0700354$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
355 $(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
356
Jan Voung08c3bcd2014-12-01 17:55:16 -0800357$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
Jim Stichnothe7e9b022015-04-21 15:05:22 -0700358 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800359 -lgtest -lgtest_main -ldl \
360 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Jan Voung08c3bcd2014-12-01 17:55:16 -0800361
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800362$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp unittest/*.h \
363 src/*.h src/*.def
Jan Voung08c3bcd2014-12-01 17:55:16 -0800364 $(CXX) -c $(CXXFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800365 -Isrc/ \
366 -Iunittest/ \
367 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
368 -I$(LLVM_SRC_PATH) \
369 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
370 $< -o $@
Jan Voung08c3bcd2014-12-01 17:55:16 -0800371
Jim Stichnothfddef242014-09-26 18:53:41 -0700372$(OBJS): | $(OBJDIR)
Jan Voung44c3a802015-03-27 16:29:08 -0700373$(SB_OBJS): | $(SB_OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700374
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800375$(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 \
376 $(OBJDIR)/unittest/AssemblerX8664
Jan Voung08c3bcd2014-12-01 17:55:16 -0800377
Jim Stichnothfddef242014-09-26 18:53:41 -0700378$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700379 @mkdir -p $@
Jan Voung44c3a802015-03-27 16:29:08 -0700380$(SB_OBJDIR):
381 @mkdir -p $@
Derek Schuffbc643132014-05-22 16:39:25 -0700382
Jan Voung08c3bcd2014-12-01 17:55:16 -0800383$(OBJDIR)/unittest: $(OBJDIR)
384 @mkdir -p $@
385
John Porto2fea26c2015-07-28 16:28:07 -0700386$(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest
387 @mkdir -p $@
388$(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest
389 @mkdir -p $@
390
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800391RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c \
392 runtime/szrt_asm_x8632.s runtime/szrt_asm_x8664.s \
393 runtime/szrt_asm_arm32.s
Jan Voung050deaa2015-06-12 15:12:05 -0700394RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800395 build/runtime/szrt_nonsfi_x8632.o \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800396 build/runtime/szrt_native_x8664.o build/runtime/szrt_sb_x8664.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800397 build/runtime/szrt_nonsfi_x8664.o \
398 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o \
399 build/runtime/szrt_nonsfi_arm32.o
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800400
401runtime: $(RT_OBJ)
402
403# Use runtime.is.built so that build-runtime.py is invoked only once
404# even in a parallel build.
405.INTERMEDIATE: runtime.is.built
406$(RT_OBJ): runtime.is.built
John Portof8b4cc82015-06-09 18:06:19 -0700407runtime.is.built: $(RT_SRC) pydir/build-runtime.py
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800408 @echo ================ Building Subzero runtime ================
Jan Voung68a06332015-03-05 14:33:38 -0800409 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800410
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800411check-lit: $(OBJDIR)/pnacl-sz make_symlink
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700412 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
David Sehrb19d39c2016-01-13 14:17:37 -0800413 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit $(FORCEASM_LIT_PARAM)
Jim Stichnothac9c9432014-08-26 14:07:13 -0700414
Karl Schimpfab06df32014-10-29 14:58:25 -0700415ifdef MINIMAL
Jim Stichnothc9258222015-03-13 11:59:49 -0700416check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
417 @echo "Crosstests disabled, minimal build"
Karl Schimpfab06df32014-10-29 14:58:25 -0700418else
Jim Stichnothc9258222015-03-13 11:59:49 -0700419check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700420 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
421 # For (slow) sandboxed tests, limit to Om1/sse4.1.
John Porto1d235422015-08-12 12:37:53 -0700422 # TODO(jpp): implement x8664 sandbox, then enable xtests.
John Portoba6a67c2015-09-25 15:19:45 -0700423 # TODO(jpp): reenable the x86-64 tests.
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700424 ./pydir/crosstest_generator.py -v --lit \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800425 --toolchain-root $(TOOLCHAIN_ROOT) \
David Sehrb19d39c2016-01-13 14:17:37 -0800426 $(FORCEASM_FLAG) \
427 $(FORCEASM_XTEST_EXCLUDES) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800428 -i x8632,native,sse2 \
429 -i x8632,native,sse4.1,test_vector_ops \
430 -i x8632,sandbox,sse4.1,Om1 \
Jim Stichnoth57a8aab2016-01-06 09:34:36 -0800431 -i x8632,nonsfi,sse2,O2 \
John Porto008f4ce2015-12-24 13:22:18 -0800432 -i x8664,native,sse2 \
433 -i x8664,native,sse4.1,test_vector_ops \
John Porto3c275ce2015-12-22 08:14:00 -0800434 -e x8664,sandbox,sse4.1,Om1 \
John Porto52b51572015-12-05 14:16:25 -0800435 -i arm32,neon \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800436 -e arm32,nonsfi \
John Porto52b51572015-12-05 14:16:25 -0800437 -e arm32,neon,test_vector_ops \
438 -e arm32,neon,test_select
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700439 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700440 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
Karl Schimpfab06df32014-10-29 14:58:25 -0700441endif
Derek Schuffbc643132014-05-22 16:39:25 -0700442
Jim Stichnothc9258222015-03-13 11:59:49 -0700443check-unit: $(OBJDIR)/run_unittests
444 $(OBJDIR)/run_unittests
445
Jim Stichnothc59288b2015-11-09 11:38:40 -0800446# List the spec2k components in roughly reverse order of runtime, to help with
447# parallel execution speed.
448ALLSPEC := 253.perlbmk 177.mesa 188.ammp 256.bzip2 164.gzip 179.art 183.equake \
449 175.vpr 176.gcc 181.mcf 186.crafty 197.parser 254.gap 255.vortex \
450 300.twolf 252.eon
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800451.PHONY: $(ALLSPEC)
452
453TARGET := x8632
454ifeq ($(TARGET),x8632)
455 TARGETFLAG=x8632
456 SETUP=SetupGccX8632Opt
457 SPEC := -O2 --filetype=obj
458endif
John Porto3c275ce2015-12-22 08:14:00 -0800459ifeq ($(TARGET),x8664)
460 TARGETFLAG=x8664
461 SETUP=SetupGccX8664Opt
462 SPEC := -O2 --filetype=obj
463endif
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800464ifeq ($(TARGET),arm32)
465 TARGETFLAG=arm32
466 SETUP=SetupGccArmOpt
467 SPEC := -O2 --filetype=asm
468endif
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800469SPECFLAGS :=
470SPECBUILDONLY := false
Jim Stichnothc59288b2015-11-09 11:38:40 -0800471%.spec2k: % $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800472 ./pydir/szbuild_spec2k.py -v --force \
473 $(SPECFLAGS) --target=$(TARGETFLAG) $(SPEC) $<
474 $(SPECBUILDONLY) || ( cd ../../../tests/spec2k; \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800475 ./run_all.sh RunTimedBenchmarks $(SETUP) train $< )
476
Jim Stichnothc59288b2015-11-09 11:38:40 -0800477check-spec: $(ALLSPEC:=.spec2k)
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800478
Jim Stichnothc9258222015-03-13 11:59:49 -0700479check: check-lit check-unit check-xtest
480
Jim Stichnoth23bee882015-11-17 06:14:05 -0800481check-presubmit presubmit:
482# Make sure clang-format gets run.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800483 +make -f Makefile.standalone format
Jim Stichnoth23bee882015-11-17 06:14:05 -0800484# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800485 +make -f Makefile.standalone \
486 MINIMAL=1 check
Jim Stichnothfc22f772015-11-22 06:06:34 -0800487# Check that there are no g++ build errors or warnings.
488 +make -f Makefile.standalone \
489 GPLUSPLUS=1 compile_only
Jim Stichnoth23bee882015-11-17 06:14:05 -0800490# Check the x86 assembler unit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800491 +make -f Makefile.standalone \
492 DEBUG=1 CHECK_X86_ASM=1 check-unit
David Sehrb19d39c2016-01-13 14:17:37 -0800493# Run lit tests, cross tests, unit tests, and spec2k/x86-32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800494 +make -f Makefile.standalone \
495 check check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800496# Build spec2k under -Om1/x86-32, to check for liveness errors.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800497 +make -f Makefile.standalone \
498 SPECFLAGS='-Om1' SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800499# Run spec2k for x86-32 without advanced phi lowering.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800500 +make -f Makefile.standalone \
501 SPECFLAGS='--sz=--phi-edge-split=0' check-spec
David Sehrb19d39c2016-01-13 14:17:37 -0800502# Run cross tests and lit tests to validate filetype=asm output.
503 +make -f Makefile.standalone \
504 FORCEASM=1 check-xtest check-lit
Jim Stichnoth23bee882015-11-17 06:14:05 -0800505# Build spec2k for arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800506 +make -f Makefile.standalone \
507 TARGET=arm32 SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800508# Build spec2k under -Om1/arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800509 +make -f Makefile.standalone \
510 TARGET=arm32 SPECFLAGS='-Om1' SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800511# Run a few spec2k tests for arm32 using qemu.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800512 +make -f Makefile.standalone \
513 TARGET=arm32 ALLSPEC='176.gcc 181.mcf 254.gap' check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800514# Provide validation of user awesomeness!
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800515 echo Success
516
Jim Stichnothdd842db2015-01-27 12:53:53 -0800517FORMAT_BLACKLIST =
518# Add one of the following lines for each source file to ignore.
519FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Karl Schimpf74cd8832015-06-23 11:05:01 -0700520FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
Karl Schimpf3e53dc92015-10-07 13:24:01 -0700521FORMAT_BLACKLIST += ! -name assembler_arm.h
522FORMAT_BLACKLIST += ! -name assembler_arm.cc
Derek Schuffbc643132014-05-22 16:39:25 -0700523format:
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700524 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800525 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700526
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700527format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700528 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800529 PATH=$(PNACL_BIN_PATH):$(PATH) \
530 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
531 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700532
Jim Stichnoth307e3262015-02-12 16:10:37 -0800533bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800534 nm -C -S -l pnacl-sz | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800535 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800536 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800537
Andrew Sculla509e1d2015-06-29 11:07:08 -0700538docs:
Reed Kotler4cba1cb2016-01-07 08:45:13 -0800539 make -C docs -f Makefile.standalone
Andrew Sculla509e1d2015-06-29 11:07:08 -0700540
Derek Schuffbc643132014-05-22 16:39:25 -0700541clean:
Jan Voung44c3a802015-03-27 16:29:08 -0700542 rm -rf pnacl-sz *.o $(OBJDIR) $(SB_OBJDIR) build/pnacl-sz.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700543
544clean-all: clean
Reed Kotler4cba1cb2016-01-07 08:45:13 -0800545 rm -rf build/ crosstest/Output/