blob: c154057e96bb1e92f754202684d36547cdb695bf [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#
Karl Schimpf8fcefc32014-09-15 12:56:50 -07005# make LLVM_SRC_PATH=<path> LLVM_BIN_PATH=<path> \
6# LIBCXX_INSTALL_PATH=<path> CLANG_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
16# LLVM_BIN_PATH is the directory where binaries are placed by the LLVM build
17# process. It should contain the tools like opt, llc and clang. The default
18# reflects a debug build with autotools (configure & make).
19LLVM_BIN_PATH ?= $(shell readlink -e \
Jan Voung4c127ba2014-09-19 13:11:36 -070020 ../../out/llvm_x86_64_linux_work/Release+Asserts/bin)
Derek Schuffbc643132014-05-22 16:39:25 -070021
Karl Schimpf8fcefc32014-09-15 12:56:50 -070022# LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should
23# contain header files and corresponding libraries
24LIBCXX_INSTALL_PATH ?= $(shell readlink -e \
Jan Voung4c127ba2014-09-19 13:11:36 -070025 ../../../toolchain/linux_x86/pnacl_newlib)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070026
27# CLANG_PATH is the location of the clang compiler to use.
28CLANG_PATH ?= $(shell readlink -e \
29 ../../../../third_party/llvm-build/Release+Asserts/bin)
30
Jan Vounga2703ae2015-02-19 11:27:44 -080031# The location of binutils tools (e.g., objdump).
32BINUTILS_BIN_PATH ?= $(shell readlink -e \
33 ../../out/binutils_pnacl_x86_64_linux_work/binutils)
34
Jan Voung4c127ba2014-09-19 13:11:36 -070035HOST_ARCH ?= x86_64
Jan Voung839c4ce2014-07-28 15:19:43 -070036ifeq ($(HOST_ARCH),x86_64)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070037 HOST_FLAGS = -m64 -stdlib=libc++
Jan Voung839c4ce2014-07-28 15:19:43 -070038else
39 ifeq ($(HOST_ARCH),x86)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070040 HOST_FLAGS = -m32 -stdlib=libc++
Jan Voung839c4ce2014-07-28 15:19:43 -070041 endif
42endif
43
Jim Stichnothfddef242014-09-26 18:53:41 -070044ifdef DEBUG
45 OBJDIR = build/Debug
46 OPTLEVEL = -O0
47else
48 OBJDIR = build/Release
Jim Stichnotha49e9d92014-12-07 14:25:34 -080049 OPTLEVEL = -O2 -ffunction-sections -fdata-sections
Jim Stichnothfddef242014-09-26 18:53:41 -070050endif
51
Karl Schimpfb262c5e2014-10-27 14:41:57 -070052# The list of CXX defines that are dependent on build parameters.
53CXX_DEFINES =
Jim Stichnothfa4efea2015-01-27 05:06:03 -080054CXX_EXTRA =
55LD_EXTRA =
Karl Schimpfb262c5e2014-10-27 14:41:57 -070056
57ifdef MINIMAL
Jim Stichnothe3c02c22014-12-05 14:16:07 -080058 NOASSERT = 1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070059 OBJDIR := $(OBJDIR)+Min
Karl Schimpfb6c96af2014-11-17 10:58:39 -080060 CXX_DEFINES += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \
Karl Schimpfdf80eb82015-02-09 14:20:22 -080061 -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 \
62 -DALLOW_MINIMAL_BUILD=1
Karl Schimpfb262c5e2014-10-27 14:41:57 -070063else
Karl Schimpfb6c96af2014-11-17 10:58:39 -080064 CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \
Karl Schimpfdf80eb82015-02-09 14:20:22 -080065 -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 \
66 -DALLOW_MINIMAL_BUILD=0
Karl Schimpfb262c5e2014-10-27 14:41:57 -070067endif
68
Jim Stichnoth9c234e22014-10-01 09:28:21 -070069ifdef NOASSERT
70 ASSERTIONS = -DNDEBUG
71else
72 ASSERTIONS =
73 OBJDIR := $(OBJDIR)+Asserts
74endif
75
Jim Stichnothfa4efea2015-01-27 05:06:03 -080076ifdef TSAN
77 OBJDIR := $(OBJDIR)+TSan
78 CXX_EXTRA += -fsanitize=thread
79 LD_EXTRA += -fsanitize=thread
80endif
81
Derek Schuffbc643132014-05-22 16:39:25 -070082$(info -----------------------------------------------)
83$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
84$(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -070085$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
86$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Vounga2703ae2015-02-19 11:27:44 -080087$(info Using BINUTILS_BIN_PATH = $(BINUTILS_BIN_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -070088$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -070089$(info -----------------------------------------------)
90
91LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags`
Jim Stichnoth14c3f412014-08-27 11:02:50 -070092LLVM_LDFLAGS := `$(LLVM_BIN_PATH)/llvm-config --libs` \
Jim Stichnoth33246422014-11-24 14:36:23 -080093 `$(LLVM_BIN_PATH)/llvm-config --ldflags` \
94 `$(LLVM_BIN_PATH)/llvm-config --system-libs`
Derek Schuffbc643132014-05-22 16:39:25 -070095
96# It's recommended that CXX matches the compiler you used to build LLVM itself.
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -070097CCACHE := `command -v ccache`
98CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung839c4ce2014-07-28 15:19:43 -070099
Jan Vounge837e1a2015-03-02 14:21:54 -0800100CXXFLAGS := $(LLVM_CXXFLAGS) -std=gnu++11 -Wall -Wextra -Werror -fno-rtti \
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700101 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) $(CXX_DEFINES) -g \
Jim Stichnoth26f94332015-01-28 08:37:22 -0800102 $(HOST_FLAGS) -pedantic -Wno-error=unused-parameter \
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800103 -I$(LIBCXX_INSTALL_PATH)/include/c++/v1 $(CXX_EXTRA)
104LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \
105 $(LD_EXTRA)
Derek Schuffbc643132014-05-22 16:39:25 -0700106
Karl Schimpfab06df32014-10-29 14:58:25 -0700107SRCS = \
Jan Voung8acded02014-09-22 18:02:25 -0700108 assembler.cpp \
109 assembler_ia32.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700110 IceCfg.cpp \
111 IceCfgNode.cpp \
Jan Voung08c3bcd2014-12-01 17:55:16 -0800112 IceELFObjectWriter.cpp \
113 IceELFSection.cpp \
Jan Voungec270732015-01-12 17:00:22 -0800114 IceFixups.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700115 IceGlobalContext.cpp \
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700116 IceGlobalInits.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700117 IceInst.cpp \
118 IceInstX8632.cpp \
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700119 IceIntrinsics.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700120 IceLiveness.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700121 IceOperand.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700122 IceRegAlloc.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700123 IceRNG.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700124 IceTargetLowering.cpp \
125 IceTargetLoweringX8632.cpp \
Jim Stichnothbbca7542015-02-11 16:08:31 -0800126 IceThreading.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -0700127 IceTimerTree.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700128 IceTranslator.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -0700129 IceTypes.cpp \
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800130 main.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -0700131 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700132
Karl Schimpfab06df32014-10-29 14:58:25 -0700133ifndef MINIMAL
Karl Schimpf4019f082014-12-15 13:45:00 -0800134 SRCS += IceConverter.cpp \
135 IceTypeConverter.cpp
Karl Schimpfab06df32014-10-29 14:58:25 -0700136endif
137
Jim Stichnothfddef242014-09-26 18:53:41 -0700138OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700139
Jan Voung08c3bcd2014-12-01 17:55:16 -0800140UNITTEST_SRCS = \
Karl Schimpf2e7daef2015-01-09 13:04:13 -0800141 BitcodeMunge.cpp \
142 IceELFSectionTest.cpp \
143 IceParseInstsTest.cpp
Jan Voung08c3bcd2014-12-01 17:55:16 -0800144
145UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS))
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800146UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS))
Jan Voung08c3bcd2014-12-01 17:55:16 -0800147
Derek Schuffbc643132014-05-22 16:39:25 -0700148# Keep all the first target so it's the default.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800149all: $(OBJDIR)/pnacl-sz make_symlink runtime
Derek Schuffbc643132014-05-22 16:39:25 -0700150
Karl Schimpf6af63362014-10-29 14:55:00 -0700151# Creates symbolic link so that testing is easier. Also runs
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800152# pnacl-sz to verify that the defines flags have valid values,
Karl Schimpf6af63362014-10-29 14:55:00 -0700153# as well as describe the corresponding build attributes.
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800154make_symlink: $(OBJDIR)/pnacl-sz
155 rm -rf pnacl-sz
156 ln -s $(OBJDIR)/pnacl-sz
Karl Schimpf6af63362014-10-29 14:55:00 -0700157 @echo "Build Attributes:"
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800158 @$(OBJDIR)/pnacl-sz --build-atts
Derek Schuffbc643132014-05-22 16:39:25 -0700159
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800160.PHONY: all make_symlink runtime bloat
Jim Stichnothfddef242014-09-26 18:53:41 -0700161
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800162$(OBJDIR)/pnacl-sz: $(OBJS)
Jim Stichnoth33246422014-11-24 14:36:23 -0800163 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700164 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700165
Jim Stichnothdd842db2015-01-27 12:53:53 -0800166# TODO(stichnot): Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700167$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700168 $(CXX) -c $(CXXFLAGS) $< -o $@
169
Jan Voung08c3bcd2014-12-01 17:55:16 -0800170$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
171 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -lgtest -lgtest_main -ldl \
172 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
173
Jim Stichnoth6e861d52015-02-03 14:35:51 -0800174$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
175 unittest/*.h src/*.h src/*.def
Jan Voung08c3bcd2014-12-01 17:55:16 -0800176 $(CXX) -c $(CXXFLAGS) \
177 -Isrc/ \
178 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \
179 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \
180 $< -o $@
181
Jim Stichnothfddef242014-09-26 18:53:41 -0700182$(OBJS): | $(OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700183
Jan Voung08c3bcd2014-12-01 17:55:16 -0800184$(UNITTEST_OBJS): | $(OBJDIR)/unittest
185
Jim Stichnothfddef242014-09-26 18:53:41 -0700186$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700187 @mkdir -p $@
188
Jan Voung08c3bcd2014-12-01 17:55:16 -0800189$(OBJDIR)/unittest: $(OBJDIR)
190 @mkdir -p $@
191
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800192RT_SRC := runtime/szrt.c runtime/szrt_ll.ll
193RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o
194
195runtime: $(RT_OBJ)
196
197# Use runtime.is.built so that build-runtime.py is invoked only once
198# even in a parallel build.
199.INTERMEDIATE: runtime.is.built
200$(RT_OBJ): runtime.is.built
201runtime.is.built: $(RT_SRC)
202 @echo ================ Building Subzero runtime ================
203 ./pydir/build-runtime.py -v
204
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800205check-lit: $(OBJDIR)/pnacl-sz make_symlink
Derek Schuffbc643132014-05-22 16:39:25 -0700206 LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
Jan Vounga2703ae2015-02-19 11:27:44 -0800207 BINUTILS_BIN_PATH=$(BINUTILS_BIN_PATH) \
Derek Schuffbc643132014-05-22 16:39:25 -0700208 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700209
Jan Voung08c3bcd2014-12-01 17:55:16 -0800210check-unit: $(OBJDIR)/run_unittests
211 $(OBJDIR)/run_unittests
212
Karl Schimpfab06df32014-10-29 14:58:25 -0700213ifdef MINIMAL
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800214check: check-lit check-unit runtime
Karl Schimpfab06df32014-10-29 14:58:25 -0700215 @echo "Crosstests ignored, minimal build"
216else
Jim Stichnoth9738a9e2015-02-23 16:39:06 -0800217check: check-lit check-unit runtime
Jim Stichnoth16178a12014-09-02 14:11:57 -0700218 (cd crosstest; ./runtests.sh)
Karl Schimpfab06df32014-10-29 14:58:25 -0700219endif
Derek Schuffbc643132014-05-22 16:39:25 -0700220
Jim Stichnothdd842db2015-01-27 12:53:53 -0800221FORMAT_BLACKLIST =
222# Add one of the following lines for each source file to ignore.
223FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700224format:
Jim Stichnothdd842db2015-01-27 12:53:53 -0800225 $(LLVM_BIN_PATH)/clang-format -style=LLVM -i \
226 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700227
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700228format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700229 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnothdd842db2015-01-27 12:53:53 -0800230 PATH=$(LLVM_BIN_PATH):$(PATH) \
231 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
232 -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700233
Jim Stichnoth307e3262015-02-12 16:10:37 -0800234bloat: make_symlink
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800235 nm -C -S -l pnacl-sz | \
236 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json
237 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html
Jim Stichnoth307e3262015-02-12 16:10:37 -0800238
Derek Schuffbc643132014-05-22 16:39:25 -0700239clean:
Jim Stichnothfa0cfa52015-02-26 09:42:36 -0800240 rm -rf pnacl-sz *.o $(OBJDIR) build/pnacl-sz.bloat.json
Karl Schimpfb262c5e2014-10-27 14:41:57 -0700241
242clean-all: clean
243 rm -rf build/