blob: 0d0bad26311e633a704daaf6a39a293c70e25cb5 [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
Karl Schimpf6f9ba112015-06-22 13:20:23 -070089ifdef TEXTUAL_BITCODE
90 BASE_CXX_DEFINES += -DINPUT_IS_TEXTUAL_BITCODE=1
91 OBJDIR := $(OBJDIR)+Tbc
Karl Schimpf6f9ba112015-06-22 13:20:23 -070092else
93 BASE_CXX_DEFINES += -DINPUT_IS_TEXTUAL_BITCODE=0
Karl Schimpf6f9ba112015-06-22 13:20:23 -070094endif
95
Jan Voung44c3a802015-03-27 16:29:08 -070096SB_CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=1
97CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0
98
Jim Stichnoth9c234e22014-10-01 09:28:21 -070099ifdef NOASSERT
100 ASSERTIONS = -DNDEBUG
101else
102 ASSERTIONS =
103 OBJDIR := $(OBJDIR)+Asserts
104endif
105
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800106ifdef TSAN
107 OBJDIR := $(OBJDIR)+TSan
108 CXX_EXTRA += -fsanitize=thread
109 LD_EXTRA += -fsanitize=thread
110endif
111
Jan Voung44c3a802015-03-27 16:29:08 -0700112SB_OBJDIR := $(OBJDIR)+Sandboxed
113
Derek Schuffbc643132014-05-22 16:39:25 -0700114$(info -----------------------------------------------)
115$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
Jan Voung44c3a802015-03-27 16:29:08 -0700116$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
117$(info Using NACL_ROOT = $(NACL_ROOT))
Jan Voung8e32fed2015-06-17 10:16:23 -0700118$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT))
Jan Voung68a06332015-03-05 14:33:38 -0800119$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
Jan Voung44c3a802015-03-27 16:29:08 -0700120$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700121$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung68a06332015-03-05 14:33:38 -0800122$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -0700123$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -0700124$(info -----------------------------------------------)
125
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700126LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
Jan Voung44c3a802015-03-27 16:29:08 -0700127SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
128
129# Listing specific libraries that are needed for pnacl-sz
130# and the unittests, since we build "tools-only" for the
131# sandboxed_translators (which doesn't include every library
132# listed by llvm-config).
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700133
134LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
135 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
136 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
137
138ifeq ($(AUTOCONF), 0)
139 # LLVM cmake build
Karl Schimpf28f3f732015-06-24 09:32:40 -0700140 LLVM_LIBS := $(LLVM_LIBS_LIST)
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700141 # For the cmake build, the gtest libs end up in the same place as the LLVM
142 # libs, so no "-L..." arg is needed.
143 GTEST_LIB_PATH ?=
144 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
145else
146 # LLVM autoconf build
Jim Stichnothe5b58fb2015-06-01 15:17:20 -0700147 LLVM_LIBS := -lLLVM-3.7svn
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700148 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
149 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
150endif
151
Jan Voung44c3a802015-03-27 16:29:08 -0700152LLVM_LDFLAGS := $(LLVM_LIBS) \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700153 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \
154 `$(PNACL_BIN_PATH)/llvm-config --system-libs`
155SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
Jan Voung44c3a802015-03-27 16:29:08 -0700156 -L$(SB_LLVM_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -0700157
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -0700158CCACHE := `command -v ccache`
159CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung44c3a802015-03-27 16:29:08 -0700160SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++
161SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate
Jan Voung839c4ce2014-07-28 15:19:43 -0700162
Jan Voung44c3a802015-03-27 16:29:08 -0700163BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
164 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \
Jim Stichnoth98da9662015-06-27 06:38:08 -0700165 $(CXX_EXTRA)
Jan Voung44c3a802015-03-27 16:29:08 -0700166
167CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \
Jim Stichnoth6c6adf12015-04-07 14:22:25 -0700168 $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700169SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(SB_CXX_DEFINES)
170
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800171LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
Jim Stichnoth6c6adf12015-04-07 14:22:25 -0700172 $(LD_EXTRA) $(STDLIB_FLAGS)
Jan Voung44c3a802015-03-27 16:29:08 -0700173# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO.
174SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700175
Karl Schimpfab06df32014-10-29 14:58:25 -0700176SRCS = \
John Portoaff4ccf2015-06-10 16:35:06 -0700177 IceAssembler.cpp \
John Portod58f01c2015-06-23 15:55:17 -0700178 IceAssemblerX8664.cpp \
Jan Voung44c3a802015-03-27 16:29:08 -0700179 IceBrowserCompileServer.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700180 IceCfg.cpp \
181 IceCfgNode.cpp \
Jan Voung44c3a802015-03-27 16:29:08 -0700182 IceClFlags.cpp \
183 IceCompiler.cpp \
184 IceCompileServer.cpp \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800185 IceELFObjectWriter.cpp \
186 IceELFSection.cpp \
Jan Voungec270732015-01-12 17:00:22 -0800187 IceFixups.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700188 IceGlobalContext.cpp \
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700189 IceGlobalInits.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700190 IceInst.cpp \
Jan Voungb2d50842015-05-12 09:53:50 -0700191 IceInstARM32.cpp \
Reed Kotlerd00d48d2015-07-08 09:49:07 -0700192 IceInstMIPS32.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700193 IceInstX8632.cpp \
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700194 IceIntrinsics.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700195 IceLiveness.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700196 IceOperand.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700197 IceRegAlloc.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700198 IceRNG.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700199 IceTargetLowering.cpp \
Jan Voungb36ad9b2015-04-21 17:01:49 -0700200 IceTargetLoweringARM32.cpp \
Jim Stichnoth6da4cef2015-06-11 13:26:33 -0700201 IceTargetLoweringMIPS32.cpp \
John Porto7e93c622015-06-23 10:58:57 -0700202 IceTargetLoweringX8632.cpp \
John Portod58f01c2015-06-23 15:55:17 -0700203 IceTargetLoweringX8664.cpp \
Jim Stichnothbbca7542015-02-11 16:08:31 -0800204 IceThreading.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700205 IceTimerTree.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700206 IceTranslator.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700207 IceTypes.cpp \
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800208 main.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700209 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700210
Karl Schimpfab06df32014-10-29 14:58:25 -0700211ifndef MINIMAL
Karl Schimpf4019f082014-12-15 13:45:00 -0800212 SRCS += IceConverter.cpp \
213 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700214endif
215
Jim Stichnothfddef242014-09-26 18:53:41 -0700216OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Jan Voung44c3a802015-03-27 16:29:08 -0700217SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700218
Jan Voung08c3bcd2014-12-01 17:55:16 -0800219UNITTEST_SRCS = \
Karl Schimpf2e7daef2015-01-09 13:04:13 -0800220 BitcodeMunge.cpp \
John Portof746f3d2015-07-11 08:29:20 -0700221 IceAssemblerX8632Test.cpp \
Karl Schimpf2e7daef2015-01-09 13:04:13 -0800222 IceELFSectionTest.cpp \
223 IceParseInstsTest.cpp
Jan Voung08c3bcd2014-12-01 17:55:16 -0800224
225UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800226UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800227
Derek Schuffbc643132014-05-22 16:39:25 -0700228# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800229all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700230
Jan Voung44c3a802015-03-27 16:29:08 -0700231ifdef TSAN
232sb:
233 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl."
234else
235sb: $(SB_OBJDIR)/pnacl-sz.x86-32.nexe
236endif
237
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700238# SHOW_BUILD_ATTS is an executable that is run to show what build
239# attributes were used to build pnacl-sz.
240ifdef TEXTUAL_BITCODE
241 SHOW_BUILD_ATTS = echo "Can't show build attributes when TEXTUAL_BITCODE=1"
242else
243 SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts
244endif
245
Karl Schimpf6af63362014-10-29 14:55:00 -0700246# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800247# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700248# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800249make_symlink: $(OBJDIR)/pnacl-sz
250 rm -rf pnacl-sz
251 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700252 @echo "Build Attributes:"
Karl Schimpf6f9ba112015-06-22 13:20:23 -0700253 @$(SHOW_BUILD_ATTS)
Derek Schuffbc643132014-05-22 16:39:25 -0700254
Andrew Sculla509e1d2015-06-29 11:07:08 -0700255.PHONY: all make_symlink runtime bloat sb docs
Jim Stichnothfddef242014-09-26 18:53:41 -0700256
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800257$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800258 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700259 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700260
Jan Voung44c3a802015-03-27 16:29:08 -0700261$(SB_OBJDIR)/pnacl-sz.x86-32.nexe: $(SB_OBJS)
262 $(eval PNACL_SZ_BASE := $(patsubst %.nexe, %, $@))
263 $(SB_CXX) $(SB_LDFLAGS) -o $(PNACL_SZ_BASE).nonfinal.pexe $^ \
264 $(SB_LLVM_LDFLAGS)
265 $(SB_TRANSLATE) -arch x86-32 $(PNACL_SZ_BASE).nonfinal.pexe -o $@ \
266 --allow-llvm-bitcode-input
267
Jim Stichnothdd842db2015-01-27 12:53:53 -0800268# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700269$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700270 $(CXX) -c $(CXXFLAGS) $< -o $@
271
Jan Voung44c3a802015-03-27 16:29:08 -0700272$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
273 $(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
274
Jan Voung08c3bcd2014-12-01 17:55:16 -0800275$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
Jim Stichnothe7e9b022015-04-21 15:05:22 -0700276 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
277 -lgtest -lgtest_main -ldl \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800278 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
279
Jim Stichnoth6e861d52015-02-03 14:35:51 -0800280$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
281 unittest/*.h src/*.h src/*.def
Jan Voung08c3bcd2014-12-01 17:55:16 -0800282 $(CXX) -c $(CXXFLAGS) \
283 -Isrc/ \
284 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
Karl Schimpfcbb1d3d2015-06-08 09:25:15 -0700285 -I$(LLVM_SRC_PATH) \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800286 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
287 $< -o $@
288
Jim Stichnothfddef242014-09-26 18:53:41 -0700289$(OBJS): | $(OBJDIR)
Jan Voung44c3a802015-03-27 16:29:08 -0700290$(SB_OBJS): | $(SB_OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700291
Jan Voung08c3bcd2014-12-01 17:55:16 -0800292$(UNITTEST_OBJS): | $(OBJDIR)/unittest
293
Jim Stichnothfddef242014-09-26 18:53:41 -0700294$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700295 @mkdir -p $@
Jan Voung44c3a802015-03-27 16:29:08 -0700296$(SB_OBJDIR):
297 @mkdir -p $@
Derek Schuffbc643132014-05-22 16:39:25 -0700298
Jan Voung08c3bcd2014-12-01 17:55:16 -0800299$(OBJDIR)/unittest: $(OBJDIR)
300 @mkdir -p $@
301
John Portof8b4cc82015-06-09 18:06:19 -0700302RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c
Jan Voung050deaa2015-06-12 15:12:05 -0700303RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
304 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800305
306runtime: $(RT_OBJ)
307
308# Use runtime.is.built so that build-runtime.py is invoked only once
309# even in a parallel build.
310.INTERMEDIATE: runtime.is.built
311$(RT_OBJ): runtime.is.built
John Portof8b4cc82015-06-09 18:06:19 -0700312runtime.is.built: $(RT_SRC) pydir/build-runtime.py
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800313 @echo ================ Building Subzero runtime ================
Jan Voung68a06332015-03-05 14:33:38 -0800314 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800315
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800316check-lit: $(OBJDIR)/pnacl-sz make_symlink
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700317 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Derek Schuffbc643132014-05-22 16:39:25 -0700318 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700319
Karl Schimpfab06df32014-10-29 14:58:25 -0700320ifdef MINIMAL
Jim Stichnothc9258222015-03-13 11:59:49 -0700321check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
322 @echo "Crosstests disabled, minimal build"
Karl Schimpfab06df32014-10-29 14:58:25 -0700323else
Jim Stichnothc9258222015-03-13 11:59:49 -0700324check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700325 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1.
326 # For (slow) sandboxed tests, limit to Om1/sse4.1.
327 ./pydir/crosstest_generator.py -v --lit \
Jan Voung8e32fed2015-06-17 10:16:23 -0700328 --toolchain-root $(TOOLCHAIN_ROOT) \
329 -i x8632,native,sse2 -i x8632,native,sse4.1,test_vector_ops \
330 -i x8632,sandbox,sse4.1,Om1 \
Jan Voungf645d852015-07-09 10:35:09 -0700331 -i arm32,native,neon,Om1,simple_loop \
Jan Voung112b6e82015-07-13 11:36:53 -0700332 -i arm32,native,neon,Om1,mem_intrin \
333 -i arm32,native,neon,Om1,test_stacksave \
334 -i arm32,native,neon,Om1,test_strengthreduce
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700335 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
Jim Stichnothdc7c5972015-03-10 11:17:15 -0700336 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
Karl Schimpfab06df32014-10-29 14:58:25 -0700337endif
Derek Schuffbc643132014-05-22 16:39:25 -0700338
Jim Stichnothc9258222015-03-13 11:59:49 -0700339check-unit: $(OBJDIR)/run_unittests
340 $(OBJDIR)/run_unittests
341
342check: check-lit check-unit check-xtest
343
Jim Stichnothdd842db2015-01-27 12:53:53 -0800344FORMAT_BLACKLIST =
345# Add one of the following lines for each source file to ignore.
346FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Karl Schimpf74cd8832015-06-23 11:05:01 -0700347FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700348format:
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700349 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
Jim Stichnothdd842db2015-01-27 12:53:53 -0800350 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700351
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700352format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700353 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth0a9e1262015-04-21 09:59:21 -0700354 PATH=$(PNACL_BIN_PATH):$(PATH) \
Jim Stichnothdd842db2015-01-27 12:53:53 -0800355 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
356 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700357
Jim Stichnoth307e3262015-02-12 16:10:37 -0800358bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800359 nm -C -S -l pnacl-sz | \
360 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
361 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800362
Andrew Sculla509e1d2015-06-29 11:07:08 -0700363docs:
364 doxygen Doxyfile
365 @echo See file://`pwd`/docs/html/index.html
366
Derek Schuffbc643132014-05-22 16:39:25 -0700367clean:
Jan Voung44c3a802015-03-27 16:29:08 -0700368 rm -rf pnacl-sz *.o $(OBJDIR) $(SB_OBJDIR) build/pnacl-sz.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700369
370clean-all: clean
Andrew Sculla509e1d2015-06-29 11:07:08 -0700371 rm -rf build/ docs/