blob: 746d216208d0b2a44bd29ab67c931e4cf2ddba99 [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 \
19 ../../out/sandboxed_translators_work/translator-i686/llvm-sb/Release)
20
21# NACL_ROOT is the root of the native client repository.
22NACL_ROOT ?= $(shell python -c "import sys; sys.path.insert(0, 'pydir'); \
23 import utils; print utils.FindBaseNaCl()")
24
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 \
Jan Voung44c3a802015-03-27 16:29:08 -070045 $(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 \
Karl Schimpfdf80eb82015-02-09 14:20:22 -080081 -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 \
Jan Voung44c3a802015-03-27 16:29:08 -070082 -DALLOW_MINIMAL_BUILD=1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070083else
Jan Voung44c3a802015-03-27 16:29:08 -070084 BASE_CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
Karl Schimpfdf80eb82015-02-09 14:20:22 -080085 -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 \
Jan Voung44c3a802015-03-27 16:29:08 -070086 -DALLOW_MINIMAL_BUILD=0
Karl Schimpfb262c5e2014-10-27 14:41:57 -070087endif
88
Jan Voung44c3a802015-03-27 16:29:08 -070089SB_CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=1
90CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
91
Jim Stichnoth9c234e22014-10-01 09:28:21 -070092ifdef NOASSERT
93 ASSERTIONS = -DNDEBUG
94else
95 ASSERTIONS =
96 OBJDIR := $(OBJDIR)+Asserts
97endif
98
Jim Stichnothfa4efea2015-01-27 05:06:03 -080099ifdef TSAN
100 OBJDIR := $(OBJDIR)+TSan
101 CXX_EXTRA += -fsanitize=thread
102 LD_EXTRA += -fsanitize=thread
103endif
104
Jan Voung44c3a802015-03-27 16:29:08 -0700105SB_OBJDIR := $(OBJDIR)+Sandboxed
106
Derek Schuffbc643132014-05-22 16:39:25 -0700107$(info -----------------------------------------------)
108$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
Jan Voung44c3a802015-03-27 16:29:08 -0700109$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
110$(info Using NACL_ROOT = $(NACL_ROOT))
Jan Voung8e32fed2015-06-17 10:16:23 -0700111$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
Jan Voung68a06332015-03-05 14:33:38 -0800112$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
Jan Voung44c3a802015-03-27 16:29:08 -0700113$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700114$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung68a06332015-03-05 14:33:38 -0800115$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -0700116$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -0700117$(info -----------------------------------------------)
118
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700119LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
Jan Voung44c3a802015-03-27 16:29:08 -0700120SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
121
122# Listing specific libraries that are needed for pnacl-sz
123# and the unittests, since we build "tools-only" for the
124# sandboxed_translators (which doesn't include every library
125# listed by llvm-config).
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700126
127LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
128 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
129 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
130
131ifeq ($(AUTOCONF), 0)
132 # LLVM cmake build
Karl Schimpf28f3f732015-06-24 09:32:40 -0700133 LLVM_LIBS := $(LLVM_LIBS_LIST)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700134 # For the cmake build, the gtest libs end up in the same place as the LLVM
135 # libs, so no "-L..." arg is needed.
136 GTEST_LIB_PATH ?=
137 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
138else
139 # LLVM autoconf build
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700140 LLVM_LIBS := -lLLVM-3.7svn
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700141 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
142 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
143endif
144
Jan Voung44c3a802015-03-27 16:29:08 -0700145LLVM_LDFLAGS := $(LLVM_LIBS) \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700146 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
147 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
148SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
Jan Voung44c3a802015-03-27 16:29:08 -0700149 -L$(SB_LLVM_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -0700150
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -0700151CCACHE := `command -v ccache`
152CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung44c3a802015-03-27 16:29:08 -0700153SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
154SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
Jan Voung839c4ce2014-07-28 15:19:43 -0700155
Jan Voung44c3a802015-03-27 16:29:08 -0700156BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
157 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
Jim Stichnoth98da9662015-06-27 06:38:08 -0700158 $(CXX_EXTRA)
Jan Voung44c3a802015-03-27 16:29:08 -0700159
160CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
Jim Stichnoth6c6adf12015-04-07 14:22:25 -0700161 $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700162SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(SB_CXX_DEFINES)
163
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800164LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
Jim Stichnoth6c6adf12015-04-07 14:22:25 -0700165 $(LD_EXTRA) $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700166# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
167SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700168
Karl Schimpfab06df32014-10-29 14:58:25 -0700169SRCS = \
John Portoaff4ccf2015-06-10 16:35:06 -0700170 IceAssembler.cpp \
Jan Voung44c3a802015-03-27 16:29:08 -0700171 IceBrowserCompileServer.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700172 IceCfg.cpp \
173 IceCfgNode.cpp \
Jan Voung44c3a802015-03-27 16:29:08 -0700174 IceClFlags.cpp \
175 IceCompiler.cpp \
176 IceCompileServer.cpp \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800177 IceELFObjectWriter.cpp \
178 IceELFSection.cpp \
Jan Voungec270732015-01-12 17:00:22 -0800179 IceFixups.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700180 IceGlobalContext.cpp \
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700181 IceGlobalInits.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700182 IceInst.cpp \
Jan Voungb2d50842015-05-12 09:53:50 -0700183 IceInstARM32.cpp \
Reed Kotlerd00d48d2015-07-08 09:49:07 -0700184 IceInstMIPS32.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700185 IceInstX8632.cpp \
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700186 IceIntrinsics.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700187 IceLiveness.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700188 IceOperand.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700189 IceRegAlloc.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700190 IceRNG.cpp \
Andrew Scull87f80c12015-07-20 10:19:16 -0700191 IceSwitchLowering.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700192 IceTargetLowering.cpp \
Jan Voungb36ad9b2015-04-21 17:01:49 -0700193 IceTargetLoweringARM32.cpp \
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700194 IceTargetLoweringMIPS32.cpp \
John Porto7e93c622015-06-23 10:58:57 -0700195 IceTargetLoweringX8632.cpp \
John Portod58f01c2015-06-23 15:55:17 -0700196 IceTargetLoweringX8664.cpp \
Jim Stichnothbbca7542015-02-11 16:08:31 -0800197 IceThreading.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700198 IceTimerTree.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700199 IceTranslator.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700200 IceTypes.cpp \
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800201 main.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700202 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700203
Karl Schimpfab06df32014-10-29 14:58:25 -0700204ifndef MINIMAL
Karl Schimpf4019f082014-12-15 13:45:00 -0800205 SRCS += IceConverter.cpp \
206 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700207endif
208
Jim Stichnothfddef242014-09-26 18:53:41 -0700209OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Jan Voung44c3a802015-03-27 16:29:08 -0700210SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700211
Jan Voung08c3bcd2014-12-01 17:55:16 -0800212UNITTEST_SRCS = \
Karl Schimpf2e7daef2015-01-09 13:04:13 -0800213 BitcodeMunge.cpp \
214 IceELFSectionTest.cpp \
John Porto2fea26c2015-07-28 16:28:07 -0700215 IceParseInstsTest.cpp \
216 AssemblerX8632/LowLevel.cpp \
217 AssemblerX8632/DataMov.cpp \
218 AssemblerX8632/Locked.cpp \
219 AssemblerX8632/GPRArith.cpp \
220 AssemblerX8632/XmmArith.cpp \
221 AssemblerX8632/ControlFlow.cpp \
222 AssemblerX8632/Other.cpp \
223 AssemblerX8632/X87.cpp \
224 AssemblerX8664/LowLevel.cpp \
225 AssemblerX8664/DataMov.cpp \
226 AssemblerX8664/Locked.cpp \
227 AssemblerX8664/GPRArith.cpp \
228 AssemblerX8664/XmmArith.cpp \
229 AssemblerX8664/ControlFlow.cpp \
230 AssemblerX8664/Other.cpp
231
Jan Voung08c3bcd2014-12-01 17:55:16 -0800232
233UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800234UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800235
Derek Schuffbc643132014-05-22 16:39:25 -0700236# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800237all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700238
Jan Voung44c3a802015-03-27 16:29:08 -0700239ifdef TSAN
240sb:
241 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
242else
243sb: $(SB_OBJDIR)/pnacl-sz.x86-32.nexe
244endif
245
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700246# SHOW_BUILD_ATTS is an executable that is run to show what build
247# attributes were used to build pnacl-sz.
Karl Schimpfcb6e95a2015-07-23 09:10:03 -0700248SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700249
Karl Schimpf6af63362014-10-29 14:55:00 -0700250# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800251# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700252# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800253make_symlink: $(OBJDIR)/pnacl-sz
254 rm -rf pnacl-sz
255 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700256 @echo "Build Attributes:"
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700257 @$(SHOW_BUILD_ATTS)
Derek Schuffbc643132014-05-22 16:39:25 -0700258
Andrew Sculla509e1d2015-06-29 11:07:08 -0700259.PHONY: all make_symlink runtime bloat sb docs
Jim Stichnothfddef242014-09-26 18:53:41 -0700260
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800261$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800262 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700263 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700264
Jan Voung44c3a802015-03-27 16:29:08 -0700265$(SB_OBJDIR)/pnacl-sz.x86-32.nexe: $(SB_OBJS)
266 $(eval PNACL_SZ_BASE := $(patsubst %.nexe, %, $@))
267 $(SB_CXX) $(SB_LDFLAGS) -o $(PNACL_SZ_BASE).nonfinal.pexe $^ \
268 $(SB_LLVM_LDFLAGS)
269 $(SB_TRANSLATE) -arch x86-32 $(PNACL_SZ_BASE).nonfinal.pexe -o $@ \
270 --allow-llvm-bitcode-input
271
Jim Stichnothdd842db2015-01-27 12:53:53 -0800272# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700273$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700274 $(CXX) -c $(CXXFLAGS) $< -o $@
275
Jan Voung44c3a802015-03-27 16:29:08 -0700276$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
277 $(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
278
Jan Voung08c3bcd2014-12-01 17:55:16 -0800279$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
Jim Stichnothe7e9b022015-04-21 15:05:22 -0700280 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
281 -lgtest -lgtest_main -ldl \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800282 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
283
Jim Stichnoth6e861d52015-02-03 14:35:51 -0800284$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
285 unittest/*.h src/*.h src/*.def
Jan Voung08c3bcd2014-12-01 17:55:16 -0800286 $(CXX) -c $(CXXFLAGS) \
287 -Isrc/ \
John Porto2fea26c2015-07-28 16:28:07 -0700288 -Iunittest/ \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800289 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -0700290 -I$(LLVM_SRC_PATH) \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800291 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
292 $< -o $@
293
Jim Stichnothfddef242014-09-26 18:53:41 -0700294$(OBJS): | $(OBJDIR)
Jan Voung44c3a802015-03-27 16:29:08 -0700295$(SB_OBJS): | $(SB_OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700296
John Porto2fea26c2015-07-28 16:28:07 -0700297$(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 $(OBJDIR)/unittest/AssemblerX8664
Jan Voung08c3bcd2014-12-01 17:55:16 -0800298
Jim Stichnothfddef242014-09-26 18:53:41 -0700299$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700300 @mkdir -p $@
Jan Voung44c3a802015-03-27 16:29:08 -0700301$(SB_OBJDIR):
302 @mkdir -p $@
Derek Schuffbc643132014-05-22 16:39:25 -0700303
Jan Voung08c3bcd2014-12-01 17:55:16 -0800304$(OBJDIR)/unittest: $(OBJDIR)
305 @mkdir -p $@
306
John Porto2fea26c2015-07-28 16:28:07 -0700307$(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest
308 @mkdir -p $@
309$(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest
310 @mkdir -p $@
311
John Portof8b4cc82015-06-09 18:06:19 -0700312RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c
Jan Voung050deaa2015-06-12 15:12:05 -0700313RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
314 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800315
316runtime: $(RT_OBJ)
317
318# Use runtime.is.built so that build-runtime.py is invoked only once
319# even in a parallel build.
320.INTERMEDIATE: runtime.is.built
321$(RT_OBJ): runtime.is.built
John Portof8b4cc82015-06-09 18:06:19 -0700322runtime.is.built: $(RT_SRC) pydir/build-runtime.py
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800323 @echo ================ Building Subzero runtime ================
Jan Voung68a06332015-03-05 14:33:38 -0800324 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800325
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800326check-lit: $(OBJDIR)/pnacl-sz make_symlink
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700327 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Derek Schuffbc643132014-05-22 16:39:25 -0700328 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700329
Karl Schimpfab06df32014-10-29 14:58:25 -0700330ifdef MINIMAL
Jim Stichnothc9258222015-03-13 11:59:49 -0700331check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
332 @echo "Crosstests disabled, minimal build"
Karl Schimpfab06df32014-10-29 14:58:25 -0700333else
Jim Stichnothc9258222015-03-13 11:59:49 -0700334check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700335 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
336 # For (slow) sandboxed tests, limit to Om1/sse4.1.
337 ./pydir/crosstest_generator.py -v --lit \
Jan Voung8e32fed2015-06-17 10:16:23 -0700338 --toolchain-root $(TOOLCHAIN_ROOT) \
339 -i x8632,native,sse2 -i x8632,native,sse4.1,test_vector_ops \
340 -i x8632,sandbox,sse4.1,Om1 \
Jan Voung53483692015-07-16 10:47:46 -0700341 -i arm32,native,neon,simple_loop \
342 -i arm32,native,neon,mem_intrin \
343 -i arm32,native,neon,test_stacksave \
344 -i arm32,native,neon,test_strengthreduce
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700345 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700346 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
Karl Schimpfab06df32014-10-29 14:58:25 -0700347endif
Derek Schuffbc643132014-05-22 16:39:25 -0700348
Jim Stichnothc9258222015-03-13 11:59:49 -0700349check-unit: $(OBJDIR)/run_unittests
350 $(OBJDIR)/run_unittests
351
352check: check-lit check-unit check-xtest
353
Jim Stichnothdd842db2015-01-27 12:53:53 -0800354FORMAT_BLACKLIST =
355# Add one of the following lines for each source file to ignore.
356FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Karl Schimpf74cd8832015-06-23 11:05:01 -0700357FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700358format:
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700359 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
Jim Stichnothdd842db2015-01-27 12:53:53 -0800360 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700361
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700362format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700363 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700364 PATH=$(PNACL_BIN_PATH):$(PATH) \
Jim Stichnothdd842db2015-01-27 12:53:53 -0800365 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
366 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700367
Jim Stichnoth307e3262015-02-12 16:10:37 -0800368bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800369 nm -C -S -l pnacl-sz | \
370 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
371 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800372
Andrew Sculla509e1d2015-06-29 11:07:08 -0700373docs:
374 doxygen Doxyfile
375 @echo See file://`pwd`/docs/html/index.html
376
Derek Schuffbc643132014-05-22 16:39:25 -0700377clean:
Jan Voung44c3a802015-03-27 16:29:08 -0700378 rm -rf pnacl-sz *.o $(OBJDIR) $(SB_OBJDIR) build/pnacl-sz.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700379
380clean-all: clean
Andrew Sculla509e1d2015-06-29 11:07:08 -0700381 rm -rf build/ docs/