blob: ae39305f9ae164aa9af4aca330c236a78d44411b [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 \
83 IceInst.cpp \
84 IceInstX8632.cpp \
Jan Voung3bd9f1a2014-06-18 10:50:57 -070085 IceIntrinsics.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -070086 IceLiveness.cpp \
Jan Voung8acded02014-09-22 18:02:25 -070087 IceMemoryRegion.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070088 IceOperand.cpp \
Jim Stichnothd97c7df2014-06-04 11:57:08 -070089 IceRegAlloc.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -070090 IceRNG.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070091 IceTargetLowering.cpp \
92 IceTargetLoweringX8632.cpp \
Jim Stichnothc4554d72014-09-30 16:49:38 -070093 IceTimerTree.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -070094 IceTranslator.cpp \
Karl Schimpfd6064a12014-08-27 15:34:58 -070095 IceTypeConverter.cpp \
Derek Schuffbc643132014-05-22 16:39:25 -070096 IceTypes.cpp \
Karl Schimpf8d7abae2014-07-07 14:50:30 -070097 llvm2ice.cpp \
98 PNaClTranslator.cpp
Derek Schuffbc643132014-05-22 16:39:25 -070099
Jim Stichnothfddef242014-09-26 18:53:41 -0700100OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS))
Derek Schuffbc643132014-05-22 16:39:25 -0700101
102# Keep all the first target so it's the default.
Jim Stichnothfddef242014-09-26 18:53:41 -0700103all: $(OBJDIR)/llvm2ice make_symlink
Derek Schuffbc643132014-05-22 16:39:25 -0700104
Jim Stichnothfddef242014-09-26 18:53:41 -0700105make_symlink: $(OBJDIR)/llvm2ice
106 rm -f llvm2ice
107 ln -s $(OBJDIR)/llvm2ice
Derek Schuffbc643132014-05-22 16:39:25 -0700108
Jim Stichnothfddef242014-09-26 18:53:41 -0700109.PHONY: all make_symlink
110
111$(OBJDIR)/llvm2ice: $(OBJS)
Karl Schimpf8fcefc32014-09-15 12:56:50 -0700112 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -ldl \
113 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
Derek Schuffbc643132014-05-22 16:39:25 -0700114
115# TODO: Be more precise than "*.h" here and elsewhere.
Jim Stichnothfddef242014-09-26 18:53:41 -0700116$(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
Derek Schuffbc643132014-05-22 16:39:25 -0700117 $(CXX) -c $(CXXFLAGS) $< -o $@
118
Jim Stichnothfddef242014-09-26 18:53:41 -0700119$(OBJS): | $(OBJDIR)
Derek Schuffbc643132014-05-22 16:39:25 -0700120
Jim Stichnothfddef242014-09-26 18:53:41 -0700121$(OBJDIR):
Derek Schuffbc643132014-05-22 16:39:25 -0700122 @mkdir -p $@
123
Jim Stichnothc4554d72014-09-30 16:49:38 -0700124check-lit: llvm2ice make_symlink
Derek Schuffbc643132014-05-22 16:39:25 -0700125 LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
126 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
Jim Stichnothac9c9432014-08-26 14:07:13 -0700127
128check: check-lit
Jim Stichnoth16178a12014-09-02 14:11:57 -0700129 (cd crosstest; ./runtests.sh)
Derek Schuffbc643132014-05-22 16:39:25 -0700130
131# TODO: Fix the use of wildcards.
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700132# Assumes clang-format is within $PATH.
Derek Schuffbc643132014-05-22 16:39:25 -0700133format:
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700134 clang-format -style=LLVM -i src/*.h src/*.cpp
135
136# Assumes clang-format-diff.py is within $PATH, and that the
137# clang-format it calls is also within $PATH. This may require adding
138# a component to $PATH, or creating symlinks within some existing
139# $PATH component. Uses the one in /usr/lib/clang-format/ if it
140# exists.
141ifeq (,$(wildcard /usr/lib/clang-format/clang-format-diff.py))
142 CLANG_FORMAT_DIFF = clang-format-diff.py
143else
144 CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py
145endif
146format-diff:
Jim Stichnoth206833c2014-08-07 10:58:05 -0700147 git diff -U0 `git merge-base HEAD master` | \
Jim Stichnoth240e0f82014-07-09 16:53:40 -0700148 $(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i
Derek Schuffbc643132014-05-22 16:39:25 -0700149
150clean:
151 rm -rf llvm2ice *.o build/