blob: d84e928e91f4d5ce7bda5efab5555b82bf80a59c [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
Jim Stichnothfc22f772015-11-22 06:06:34 -080097# Use g++ to compile, to check for errors/warnings that clang++ might have
98# missed. It's unlikely to link, unless LLVM was also built with g++, so the
99# compile_only target should be used.
100ifdef GPLUSPLUS
101 CXX = CCACHE_CPP2=yes $(CCACHE) g++
102 STDLIB_FLAGS =
103 LLVM_EXTRA_WARNINGS="-Wno-unknown-pragmas -Wno-unused-parameter \
104 -Wno-comment -Wno-enum-compare -Wno-strict-aliasing"
105 OBJDIR := $(OBJDIR)+Gplusplus
106endif
107
Andrew Scull6ef79492015-09-09 15:50:42 -0700108ifdef UBSAN
109 OBJDIR := $(OBJDIR)+UBSan
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800110 CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr \
111 -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700112 LD_EXTRA += -fsanitize=undefined
113endif
114
115ifdef UBSAN_TRAP
116 OBJDIR := $(OBJDIR)+UBSan_Trap
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800117 CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error \
118 -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
Andrew Scull6ef79492015-09-09 15:50:42 -0700119 LD_EXTRA += -fsanitize=undefined-trap
120endif
121
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800122ifdef TSAN
123 OBJDIR := $(OBJDIR)+TSan
124 CXX_EXTRA += -fsanitize=thread
125 LD_EXTRA += -fsanitize=thread
126endif
127
Andrew Scull86df4e92015-07-30 13:54:44 -0700128ifdef ASAN
129 OBJDIR := $(OBJDIR)+ASan
130 CXX_EXTRA += -fsanitize=address
131 LD_EXTRA += -fsanitize=address
132endif
133
Andrew Scull6ef79492015-09-09 15:50:42 -0700134ifdef MSAN
Andrew Scull00741a02015-09-16 19:04:09 -0700135 # TODO(ascull): this has an as yet undiagnosed uninitialized memory access
Andrew Scull6ef79492015-09-09 15:50:42 -0700136 OBJDIR := $(OBJDIR)+MSan
137 CXX_EXTRA += -fsanitize=memory
138 LD_EXTRA += -fsanitize=memory
139endif
140
Jan Voung44c3a802015-03-27 16:29:08 -0700141SB_OBJDIR := $(OBJDIR)+Sandboxed
142
Derek Schuffbc643132014-05-22 16:39:25 -0700143$(info -----------------------------------------------)
144$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
Jan Voung44c3a802015-03-27 16:29:08 -0700145$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
146$(info Using NACL_ROOT = $(NACL_ROOT))
Jan Voung8e32fed2015-06-17 10:16:23 -0700147$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
Jan Voung68a06332015-03-05 14:33:38 -0800148$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
Jan Voung44c3a802015-03-27 16:29:08 -0700149$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700150$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung68a06332015-03-05 14:33:38 -0800151$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -0700152$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -0700153$(info -----------------------------------------------)
154
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700155LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
Jan Voung44c3a802015-03-27 16:29:08 -0700156SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
157
158# Listing specific libraries that are needed for pnacl-sz
159# and the unittests, since we build "tools-only" for the
160# sandboxed_translators (which doesn't include every library
161# listed by llvm-config).
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700162
163LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
164 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
165 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
166
167ifeq ($(AUTOCONF), 0)
168 # LLVM cmake build
Karl Schimpf28f3f732015-06-24 09:32:40 -0700169 LLVM_LIBS := $(LLVM_LIBS_LIST)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700170 # For the cmake build, the gtest libs end up in the same place as the LLVM
171 # libs, so no "-L..." arg is needed.
172 GTEST_LIB_PATH ?=
173 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
174else
175 # LLVM autoconf build
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700176 LLVM_LIBS := -lLLVM-3.7svn
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700177 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
178 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
179endif
180
Jan Voung44c3a802015-03-27 16:29:08 -0700181LLVM_LDFLAGS := $(LLVM_LIBS) \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700182 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
183 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
184SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
Jan Voung44c3a802015-03-27 16:29:08 -0700185 -L$(SB_LLVM_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -0700186
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -0700187CCACHE := `command -v ccache`
188CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung44c3a802015-03-27 16:29:08 -0700189SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
190SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
Jan Voung839c4ce2014-07-28 15:19:43 -0700191
Jan Voungc2648c22015-07-30 21:29:14 -0700192# Extra warnings that LLVM's build system adds in addition to -Wall.
193LLVM_EXTRA_WARNINGS := -Wcovered-switch-default
194
Jan Voung44c3a802015-03-27 16:29:08 -0700195BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800196 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
197 $(LLVM_EXTRA_WARNINGS) $(CXX_EXTRA)
Jan Voung44c3a802015-03-27 16:29:08 -0700198
199CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800200 $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700201SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(SB_CXX_DEFINES)
202
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800203LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800204 $(LD_EXTRA) $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700205# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
206SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700207
Jim Stichnothc59288b2015-11-09 11:38:40 -0800208# List the target-specific source files first, which generally take longer to
209# compile, in the hope of improving parallel build time.
Karl Schimpfab06df32014-10-29 14:58:25 -0700210SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800211 IceAssemblerARM32.cpp \
Jim Stichnothc59288b2015-11-09 11:38:40 -0800212 IceInstARM32.cpp \
213 IceInstMIPS32.cpp \
214 IceInstX8632.cpp \
215 IceInstX8664.cpp \
216 IceTargetLowering.cpp \
217 IceTargetLoweringARM32.cpp \
218 IceTargetLoweringMIPS32.cpp \
219 IceTargetLoweringX8632.cpp \
220 IceTargetLoweringX8664.cpp \
221 IceAssembler.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800222 IceBrowserCompileServer.cpp \
223 IceCfg.cpp \
224 IceCfgNode.cpp \
225 IceClFlags.cpp \
226 IceCompiler.cpp \
227 IceCompileServer.cpp \
228 IceELFObjectWriter.cpp \
229 IceELFSection.cpp \
230 IceFixups.cpp \
231 IceGlobalContext.cpp \
232 IceGlobalInits.cpp \
233 IceInst.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800234 IceIntrinsics.cpp \
235 IceLiveness.cpp \
236 IceLoopAnalyzer.cpp \
237 IceOperand.cpp \
238 IceRegAlloc.cpp \
239 IceRNG.cpp \
240 IceSwitchLowering.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800241 IceThreading.cpp \
242 IceTimerTree.cpp \
243 IceTranslator.cpp \
244 IceTypes.cpp \
245 main.cpp \
246 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700247
Karl Schimpfab06df32014-10-29 14:58:25 -0700248ifndef MINIMAL
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800249 SRCS += \
250 IceConverter.cpp \
251 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700252endif
253
Jim Stichnothfddef242014-09-26 18:53:41 -0700254OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Jan Voung44c3a802015-03-27 16:29:08 -0700255SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700256
Jan Voung08c3bcd2014-12-01 17:55:16 -0800257UNITTEST_SRCS = \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800258 BitcodeMunge.cpp \
259 IceELFSectionTest.cpp \
260 IceParseInstsTest.cpp
John Porto59f2d922015-07-31 13:45:48 -0700261
262# The X86 assembler tests take too long to compile. Given how infrequently the
263# assembler will change, we disable them.
264ifdef CHECK_X86_ASM
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800265 ifndef DEBUG
266 $(error Run check-unit with DEBUG=1 lest your machine perish)
267 endif
John Porto59f2d922015-07-31 13:45:48 -0700268 UNITTEST_SRCS += AssemblerX8632/LowLevel.cpp \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800269 AssemblerX8632/DataMov.cpp \
270 AssemblerX8632/Locked.cpp \
271 AssemblerX8632/GPRArith.cpp \
272 AssemblerX8632/XmmArith.cpp \
273 AssemblerX8632/ControlFlow.cpp \
274 AssemblerX8632/Other.cpp \
275 AssemblerX8632/X87.cpp \
276 AssemblerX8664/LowLevel.cpp \
277 AssemblerX8664/DataMov.cpp \
278 AssemblerX8664/Locked.cpp \
279 AssemblerX8664/GPRArith.cpp \
280 AssemblerX8664/XmmArith.cpp \
281 AssemblerX8664/ControlFlow.cpp \
282 AssemblerX8664/Other.cpp
John Porto59f2d922015-07-31 13:45:48 -0700283endif
Jan Voung08c3bcd2014-12-01 17:55:16 -0800284
285UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800286UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800287
Derek Schuffbc643132014-05-22 16:39:25 -0700288# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800289all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700290
Jan Voung44c3a802015-03-27 16:29:08 -0700291ifdef TSAN
292sb:
293 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
294else
295sb: $(SB_OBJDIR)/pnacl-sz.x86-32.nexe
296endif
297
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700298# SHOW_BUILD_ATTS is an executable that is run to show what build
299# attributes were used to build pnacl-sz.
Karl Schimpfcb6e95a2015-07-23 09:10:03 -0700300SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700301
Karl Schimpf6af63362014-10-29 14:55:00 -0700302# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800303# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700304# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800305make_symlink: $(OBJDIR)/pnacl-sz
306 rm -rf pnacl-sz
307 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700308 @echo "Build Attributes:"
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700309 @$(SHOW_BUILD_ATTS)
Derek Schuffbc643132014-05-22 16:39:25 -0700310
Jim Stichnoth23bee882015-11-17 06:14:05 -0800311.PHONY: all compile_only make_symlink runtime bloat sb docs
312
313compile_only: $(OBJS)
Jim Stichnothfddef242014-09-26 18:53:41 -0700314
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800315$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800316 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800317 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700318
Jan Voung44c3a802015-03-27 16:29:08 -0700319$(SB_OBJDIR)/pnacl-sz.x86-32.nexe: $(SB_OBJS)
320 $(eval PNACL_SZ_BASE := $(patsubst %.nexe, %, $@))
321 $(SB_CXX) $(SB_LDFLAGS) -o $(PNACL_SZ_BASE).nonfinal.pexe $^ \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800322 $(SB_LLVM_LDFLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700323 $(SB_TRANSLATE) -arch x86-32 $(PNACL_SZ_BASE).nonfinal.pexe -o $@ \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800324 --allow-llvm-bitcode-input
Jan Voung44c3a802015-03-27 16:29:08 -0700325
John Porto2187c842015-12-16 07:48:25 -0800326src/IceRegistersARM32.def: pydir/gen_arm32_reg_tables.py
327 python $< > $@
328
Jim Stichnothdd842db2015-01-27 12:53:53 -0800329# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700330$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700331 $(CXX) -c $(CXXFLAGS) $< -o $@
332
Jan Voung44c3a802015-03-27 16:29:08 -0700333$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
334 $(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
335
Jan Voung08c3bcd2014-12-01 17:55:16 -0800336$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
Jim Stichnothe7e9b022015-04-21 15:05:22 -0700337 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800338 -lgtest -lgtest_main -ldl \
339 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Jan Voung08c3bcd2014-12-01 17:55:16 -0800340
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800341$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp unittest/*.h \
342 src/*.h src/*.def
Jan Voung08c3bcd2014-12-01 17:55:16 -0800343 $(CXX) -c $(CXXFLAGS) \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800344 -Isrc/ \
345 -Iunittest/ \
346 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
347 -I$(LLVM_SRC_PATH) \
348 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
349 $< -o $@
Jan Voung08c3bcd2014-12-01 17:55:16 -0800350
Jim Stichnothfddef242014-09-26 18:53:41 -0700351$(OBJS): | $(OBJDIR)
Jan Voung44c3a802015-03-27 16:29:08 -0700352$(SB_OBJS): | $(SB_OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700353
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800354$(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 \
355 $(OBJDIR)/unittest/AssemblerX8664
Jan Voung08c3bcd2014-12-01 17:55:16 -0800356
Jim Stichnothfddef242014-09-26 18:53:41 -0700357$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700358 @mkdir -p $@
Jan Voung44c3a802015-03-27 16:29:08 -0700359$(SB_OBJDIR):
360 @mkdir -p $@
Derek Schuffbc643132014-05-22 16:39:25 -0700361
Jan Voung08c3bcd2014-12-01 17:55:16 -0800362$(OBJDIR)/unittest: $(OBJDIR)
363 @mkdir -p $@
364
John Porto2fea26c2015-07-28 16:28:07 -0700365$(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest
366 @mkdir -p $@
367$(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest
368 @mkdir -p $@
369
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800370RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c \
371 runtime/szrt_asm_x8632.s runtime/szrt_asm_x8664.s \
372 runtime/szrt_asm_arm32.s
Jan Voung050deaa2015-06-12 15:12:05 -0700373RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800374 build/runtime/szrt_nonsfi_x8632.o \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800375 build/runtime/szrt_native_x8664.o build/runtime/szrt_sb_x8664.o \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800376 build/runtime/szrt_nonsfi_x8664.o \
377 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o \
378 build/runtime/szrt_nonsfi_arm32.o
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800379
380runtime: $(RT_OBJ)
381
382# Use runtime.is.built so that build-runtime.py is invoked only once
383# even in a parallel build.
384.INTERMEDIATE: runtime.is.built
385$(RT_OBJ): runtime.is.built
John Portof8b4cc82015-06-09 18:06:19 -0700386runtime.is.built: $(RT_SRC) pydir/build-runtime.py
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800387 @echo ================ Building Subzero runtime ================
Jan Voung68a06332015-03-05 14:33:38 -0800388 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800389
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800390check-lit: $(OBJDIR)/pnacl-sz make_symlink
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700391 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Derek Schuffbc643132014-05-22 16:39:25 -0700392 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700393
Karl Schimpfab06df32014-10-29 14:58:25 -0700394ifdef MINIMAL
Jim Stichnothc9258222015-03-13 11:59:49 -0700395check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
396 @echo "Crosstests disabled, minimal build"
Karl Schimpfab06df32014-10-29 14:58:25 -0700397else
Jim Stichnothc9258222015-03-13 11:59:49 -0700398check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700399 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
400 # For (slow) sandboxed tests, limit to Om1/sse4.1.
John Porto1d235422015-08-12 12:37:53 -0700401 # TODO(jpp): implement x8664 sandbox, then enable xtests.
John Portoba6a67c2015-09-25 15:19:45 -0700402 # TODO(jpp): reenable the x86-64 tests.
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700403 ./pydir/crosstest_generator.py -v --lit \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800404 --toolchain-root $(TOOLCHAIN_ROOT) \
405 -i x8632,native,sse2 \
406 -i x8632,native,sse4.1,test_vector_ops \
407 -i x8632,sandbox,sse4.1,Om1 \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800408 -i x8632,nonsfi,sse2,O2 -e x8632,nonsfi,test_select \
John Porto008f4ce2015-12-24 13:22:18 -0800409 -i x8664,native,sse2 \
410 -i x8664,native,sse4.1,test_vector_ops \
John Porto3c275ce2015-12-22 08:14:00 -0800411 -e x8664,sandbox,sse4.1,Om1 \
John Porto52b51572015-12-05 14:16:25 -0800412 -i arm32,neon \
Jim Stichnoth8ff4b282016-01-04 15:39:06 -0800413 -e arm32,nonsfi \
John Porto52b51572015-12-05 14:16:25 -0800414 -e arm32,neon,test_vector_ops \
415 -e arm32,neon,test_select
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700416 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700417 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
Karl Schimpfab06df32014-10-29 14:58:25 -0700418endif
Derek Schuffbc643132014-05-22 16:39:25 -0700419
Jim Stichnothc9258222015-03-13 11:59:49 -0700420check-unit: $(OBJDIR)/run_unittests
421 $(OBJDIR)/run_unittests
422
Jim Stichnothc59288b2015-11-09 11:38:40 -0800423# List the spec2k components in roughly reverse order of runtime, to help with
424# parallel execution speed.
425ALLSPEC := 253.perlbmk 177.mesa 188.ammp 256.bzip2 164.gzip 179.art 183.equake \
426 175.vpr 176.gcc 181.mcf 186.crafty 197.parser 254.gap 255.vortex \
427 300.twolf 252.eon
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800428.PHONY: $(ALLSPEC)
429
430TARGET := x8632
431ifeq ($(TARGET),x8632)
432 TARGETFLAG=x8632
433 SETUP=SetupGccX8632Opt
434 SPEC := -O2 --filetype=obj
435endif
John Porto3c275ce2015-12-22 08:14:00 -0800436ifeq ($(TARGET),x8664)
437 TARGETFLAG=x8664
438 SETUP=SetupGccX8664Opt
439 SPEC := -O2 --filetype=obj
440endif
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800441ifeq ($(TARGET),arm32)
442 TARGETFLAG=arm32
443 SETUP=SetupGccArmOpt
444 SPEC := -O2 --filetype=asm
445endif
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800446SPECFLAGS :=
447SPECBUILDONLY := false
Jim Stichnothc59288b2015-11-09 11:38:40 -0800448%.spec2k: % $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800449 ./pydir/szbuild_spec2k.py -v --force \
450 $(SPECFLAGS) --target=$(TARGETFLAG) $(SPEC) $<
451 $(SPECBUILDONLY) || ( cd ../../../tests/spec2k; \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800452 ./run_all.sh RunTimedBenchmarks $(SETUP) train $< )
453
Jim Stichnothc59288b2015-11-09 11:38:40 -0800454check-spec: $(ALLSPEC:=.spec2k)
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800455
Jim Stichnothc9258222015-03-13 11:59:49 -0700456check: check-lit check-unit check-xtest
457
Jim Stichnoth23bee882015-11-17 06:14:05 -0800458check-presubmit presubmit:
459# Make sure clang-format gets run.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800460 +make -f Makefile.standalone format
Jim Stichnoth23bee882015-11-17 06:14:05 -0800461# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800462 +make -f Makefile.standalone \
463 MINIMAL=1 check
Jim Stichnothfc22f772015-11-22 06:06:34 -0800464# Check that there are no g++ build errors or warnings.
465 +make -f Makefile.standalone \
466 GPLUSPLUS=1 compile_only
Jim Stichnoth23bee882015-11-17 06:14:05 -0800467# Check the x86 assembler unit tests.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800468 +make -f Makefile.standalone \
469 DEBUG=1 CHECK_X86_ASM=1 check-unit
Jim Stichnoth23bee882015-11-17 06:14:05 -0800470# Run spec2k for x86-32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800471 +make -f Makefile.standalone \
472 check check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800473# Build spec2k under -Om1/x86-32, to check for liveness errors.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800474 +make -f Makefile.standalone \
475 SPECFLAGS='-Om1' SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800476# Run spec2k for x86-32 without advanced phi lowering.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800477 +make -f Makefile.standalone \
478 SPECFLAGS='--sz=--phi-edge-split=0' check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800479# Build spec2k for arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800480 +make -f Makefile.standalone \
481 TARGET=arm32 SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800482# Build spec2k under -Om1/arm32.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800483 +make -f Makefile.standalone \
484 TARGET=arm32 SPECFLAGS='-Om1' SPECBUILDONLY=true check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800485# Run a few spec2k tests for arm32 using qemu.
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800486 +make -f Makefile.standalone \
487 TARGET=arm32 ALLSPEC='176.gcc 181.mcf 254.gap' check-spec
Jim Stichnoth23bee882015-11-17 06:14:05 -0800488# Provide validation of user awesomeness!
Jim Stichnoth6c4ad842015-11-16 12:47:57 -0800489 echo Success
490
Jim Stichnothdd842db2015-01-27 12:53:53 -0800491FORMAT_BLACKLIST =
492# Add one of the following lines for each source file to ignore.
493FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Karl Schimpf74cd8832015-06-23 11:05:01 -0700494FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
Karl Schimpf3e53dc92015-10-07 13:24:01 -0700495FORMAT_BLACKLIST += ! -name assembler_arm.h
496FORMAT_BLACKLIST += ! -name assembler_arm.cc
Derek Schuffbc643132014-05-22 16:39:25 -0700497format:
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700498 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800499 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700500
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700501format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700502 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800503 PATH=$(PNACL_BIN_PATH):$(PATH) \
504 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
505 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700506
Jim Stichnoth307e3262015-02-12 16:10:37 -0800507bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800508 nm -C -S -l pnacl-sz | \
Jim Stichnoth2e7de232015-11-02 08:25:57 -0800509 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800510 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800511
Andrew Sculla509e1d2015-06-29 11:07:08 -0700512docs:
513 doxygen Doxyfile
514 @echo See file://`pwd`/docs/html/index.html
515
Derek Schuffbc643132014-05-22 16:39:25 -0700516clean:
Jan Voung44c3a802015-03-27 16:29:08 -0700517 rm -rf pnacl-sz *.o $(OBJDIR) $(SB_OBJDIR) build/pnacl-sz.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700518
519clean-all: clean
Andrew Sculla509e1d2015-06-29 11:07:08 -0700520 rm -rf build/ docs/