blob: cb0082cee3a5914a7151e50d27f8346a3bd03d80 [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 Voung4c127ba2014-09-19 13:11:36 -070031HOST_ARCH ?= x86_64
Jan Voung839c4ce2014-07-28 15:19:43 -070032ifeq ($(HOST_ARCH),x86_64)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070033 HOST_FLAGS = -m64 -stdlib=libc++
Jan Voung839c4ce2014-07-28 15:19:43 -070034else
35 ifeq ($(HOST_ARCH),x86)
Karl Schimpf8fcefc32014-09-15 12:56:50 -070036 HOST_FLAGS = -m32 -stdlib=libc++
Jan Voung839c4ce2014-07-28 15:19:43 -070037 endif
38endif
39
Jim Stichnothfddef242014-09-26 18:53:41 -070040ifdef DEBUG
41 OBJDIR = build/Debug
42 OPTLEVEL = -O0
43else
44 OBJDIR = build/Release
45 OPTLEVEL = -O2
46endif
47
Jim Stichnoth9c234e22014-10-01 09:28:21 -070048ifdef NOASSERT
49 ASSERTIONS = -DNDEBUG
50else
51 ASSERTIONS =
52 OBJDIR := $(OBJDIR)+Asserts
53endif
54
Derek Schuffbc643132014-05-22 16:39:25 -070055$(info -----------------------------------------------)
56$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
57$(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH))
Karl Schimpf8fcefc32014-09-15 12:56:50 -070058$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
59$(info Using CLANG_PATH = $(CLANG_PATH))
Jan Voung839c4ce2014-07-28 15:19:43 -070060$(info Using HOST_ARCH = $(HOST_ARCH))
Derek Schuffbc643132014-05-22 16:39:25 -070061$(info -----------------------------------------------)
62
63LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags`
Jim Stichnoth14c3f412014-08-27 11:02:50 -070064LLVM_LDFLAGS := `$(LLVM_BIN_PATH)/llvm-config --libs` \
65 `$(LLVM_BIN_PATH)/llvm-config --ldflags`
Derek Schuffbc643132014-05-22 16:39:25 -070066
67# It's recommended that CXX matches the compiler you used to build LLVM itself.
Jim Stichnoth5e06f9f2014-09-17 08:41:21 -070068CCACHE := `command -v ccache`
69CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++
Jan Voung839c4ce2014-07-28 15:19:43 -070070
Jim Stichnoth8e8042c2014-09-25 17:51:47 -070071CXXFLAGS := $(LLVM_CXXFLAGS) -std=c++11 -Wall -Wextra -Werror -fno-rtti \
Jim Stichnoth9c234e22014-10-01 09:28:21 -070072 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g $(HOST_FLAGS) \
Karl Schimpf8fcefc32014-09-15 12:56:50 -070073 -Wno-error=unused-parameter -I$(LIBCXX_INSTALL_PATH)/include/c++/v1
74LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib
Derek Schuffbc643132014-05-22 16:39:25 -070075
76SRCS= \
Jan Voung8acded02014-09-22 18:02:25 -070077 assembler.cpp \
78 assembler_ia32.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070079 IceCfg.cpp \
80 IceCfgNode.cpp \
Karl Schimpfe1e013c2014-06-27 09:15:29 -070081 IceConverter.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070082 IceGlobalContext.cpp \
Karl Schimpfe3f64d02014-10-07 10:38:22 -070083 IceGlobalInits.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070084 IceInst.cpp \
85 IceInstX8632.cpp \
Jan Voung3bd9f1a2014-06-18 10:50:57 -070086 IceIntrinsics.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -070087 IceLiveness.cpp \
Jan Voung8acded02014-09-22 18:02:25 -070088 IceMemoryRegion.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070089 IceOperand.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -070090 IceRegAlloc.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -070091 IceRNG.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070092 IceTargetLowering.cpp \
93 IceTargetLoweringX8632.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -070094 IceTimerTree.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -070095 IceTranslator.cpp \
Karl Schimpfd6064a12014-08-27 15:34:58 -070096 IceTypeConverter.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070097 IceTypes.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -070098 llvm2ice.cpp \
99 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -0700100
Jim Stichnothfddef242014-09-26 18:53:41 -0700101OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700102
103# Keep all the first target so it's the default.
Jim Stichnothfddef242014-09-26 18:53:41 -0700104all: $(OBJDIR)/llvm2ice make_symlink
Derek Schuffbc643132014-05-22 16:39:25 -0700105
Jim Stichnothfddef242014-09-26 18:53:41 -0700106make_symlink: $(OBJDIR)/llvm2ice
107 rm -f llvm2ice
108 ln -s $(OBJDIR)/llvm2ice
Derek Schuffbc643132014-05-22 16:39:25 -0700109
Jim Stichnothfddef242014-09-26 18:53:41 -0700110.PHONY: all make_symlink
111
112$(OBJDIR)/llvm2ice: $(OBJS)
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700113 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -ldl \
114 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700115
116# TODO: Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700117$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700118 $(CXX) -c $(CXXFLAGS) $< -o $@
119
Jim Stichnothfddef242014-09-26 18:53:41 -0700120$(OBJS): | $(OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700121
Jim Stichnothfddef242014-09-26 18:53:41 -0700122$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700123 @mkdir -p $@
124
Jim Stichnothc4554d72014-09-30 16:49:38 -0700125check-lit: llvm2ice make_symlink
Derek Schuffbc643132014-05-22 16:39:25 -0700126 LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
127 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700128
129check: check-lit
Jim Stichnoth16178a12014-09-02 14:11:57 -0700130 (cd crosstest; ./runtests.sh)
Derek Schuffbc643132014-05-22 16:39:25 -0700131
132# TODO: Fix the use of wildcards.
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700133# Assumes clang-format is within $PATH.
Derek Schuffbc643132014-05-22 16:39:25 -0700134format:
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700135 clang-format -style=LLVM -i src/*.h src/*.cpp
136
137# Assumes clang-format-diff.py is within $PATH, and that the
138# clang-format it calls is also within $PATH. This may require adding
139# a component to $PATH, or creating symlinks within some existing
140# $PATH component. Uses the one in /usr/lib/clang-format/ if it
141# exists.
142ifeq (,$(wildcard /usr/lib/clang-format/clang-format-diff.py))
143 CLANG_FORMAT_DIFF = clang-format-diff.py
144else
145 CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py
146endif
147format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700148 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700149 $(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700150
151clean:
152 rm -rf llvm2ice *.o build/