Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 1 | # 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 Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 5 | # make LLVM_SRC_PATH=<path> LLVM_BIN_PATH=<path> \ |
| 6 | # LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> ... |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 7 | # |
| 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. |
| 14 | LLVM_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). |
| 19 | LLVM_BIN_PATH ?= $(shell readlink -e \ |
Jan Voung | 4c127ba | 2014-09-19 13:11:36 -0700 | [diff] [blame] | 20 | ../../out/llvm_x86_64_linux_work/Release+Asserts/bin) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 21 | |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 22 | # LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should |
| 23 | # contain header files and corresponding libraries |
| 24 | LIBCXX_INSTALL_PATH ?= $(shell readlink -e \ |
Jan Voung | 4c127ba | 2014-09-19 13:11:36 -0700 | [diff] [blame] | 25 | ../../../toolchain/linux_x86/pnacl_newlib) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 26 | |
| 27 | # CLANG_PATH is the location of the clang compiler to use. |
| 28 | CLANG_PATH ?= $(shell readlink -e \ |
| 29 | ../../../../third_party/llvm-build/Release+Asserts/bin) |
| 30 | |
Jan Voung | 4c127ba | 2014-09-19 13:11:36 -0700 | [diff] [blame] | 31 | HOST_ARCH ?= x86_64 |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 32 | ifeq ($(HOST_ARCH),x86_64) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 33 | HOST_FLAGS = -m64 -stdlib=libc++ |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 34 | else |
| 35 | ifeq ($(HOST_ARCH),x86) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 36 | HOST_FLAGS = -m32 -stdlib=libc++ |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 37 | endif |
| 38 | endif |
| 39 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 40 | ifdef DEBUG |
| 41 | OBJDIR = build/Debug |
| 42 | OPTLEVEL = -O0 |
| 43 | else |
| 44 | OBJDIR = build/Release |
| 45 | OPTLEVEL = -O2 |
| 46 | endif |
| 47 | |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 48 | ifdef NOASSERT |
| 49 | ASSERTIONS = -DNDEBUG |
| 50 | else |
| 51 | ASSERTIONS = |
| 52 | OBJDIR := $(OBJDIR)+Asserts |
| 53 | endif |
| 54 | |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 55 | $(info -----------------------------------------------) |
| 56 | $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH)) |
| 57 | $(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH)) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 58 | $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH)) |
| 59 | $(info Using CLANG_PATH = $(CLANG_PATH)) |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 60 | $(info Using HOST_ARCH = $(HOST_ARCH)) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 61 | $(info -----------------------------------------------) |
| 62 | |
| 63 | LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags` |
Jim Stichnoth | 14c3f41 | 2014-08-27 11:02:50 -0700 | [diff] [blame] | 64 | LLVM_LDFLAGS := `$(LLVM_BIN_PATH)/llvm-config --libs` \ |
| 65 | `$(LLVM_BIN_PATH)/llvm-config --ldflags` |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 66 | |
| 67 | # It's recommended that CXX matches the compiler you used to build LLVM itself. |
Jim Stichnoth | 5e06f9f | 2014-09-17 08:41:21 -0700 | [diff] [blame] | 68 | CCACHE := `command -v ccache` |
| 69 | CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++ |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 70 | |
Jim Stichnoth | 8e8042c | 2014-09-25 17:51:47 -0700 | [diff] [blame] | 71 | CXXFLAGS := $(LLVM_CXXFLAGS) -std=c++11 -Wall -Wextra -Werror -fno-rtti \ |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 72 | -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g $(HOST_FLAGS) \ |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 73 | -Wno-error=unused-parameter -I$(LIBCXX_INSTALL_PATH)/include/c++/v1 |
| 74 | LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 75 | |
| 76 | SRCS= \ |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 77 | assembler.cpp \ |
| 78 | assembler_ia32.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 79 | IceCfg.cpp \ |
| 80 | IceCfgNode.cpp \ |
Karl Schimpf | e1e013c | 2014-06-27 09:15:29 -0700 | [diff] [blame] | 81 | IceConverter.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 82 | IceGlobalContext.cpp \ |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 83 | IceGlobalInits.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 84 | IceInst.cpp \ |
| 85 | IceInstX8632.cpp \ |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 86 | IceIntrinsics.cpp \ |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 87 | IceLiveness.cpp \ |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 88 | IceMemoryRegion.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 89 | IceOperand.cpp \ |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 90 | IceRegAlloc.cpp \ |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 91 | IceRNG.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 92 | IceTargetLowering.cpp \ |
| 93 | IceTargetLoweringX8632.cpp \ |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 94 | IceTimerTree.cpp \ |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 95 | IceTranslator.cpp \ |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 96 | IceTypeConverter.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 97 | IceTypes.cpp \ |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 98 | llvm2ice.cpp \ |
| 99 | PNaClTranslator.cpp |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 100 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 101 | OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS)) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 102 | |
| 103 | # Keep all the first target so it's the default. |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 104 | all: $(OBJDIR)/llvm2ice make_symlink |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 105 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 106 | make_symlink: $(OBJDIR)/llvm2ice |
| 107 | rm -f llvm2ice |
| 108 | ln -s $(OBJDIR)/llvm2ice |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 109 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 110 | .PHONY: all make_symlink |
| 111 | |
| 112 | $(OBJDIR)/llvm2ice: $(OBJS) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 113 | $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -ldl \ |
| 114 | -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 115 | |
| 116 | # TODO: Be more precise than "*.h" here and elsewhere. |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 117 | $(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 118 | $(CXX) -c $(CXXFLAGS) $< -o $@ |
| 119 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 120 | $(OBJS): | $(OBJDIR) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 121 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 122 | $(OBJDIR): |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 123 | @mkdir -p $@ |
| 124 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 125 | check-lit: llvm2ice make_symlink |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 126 | LLVM_BIN_PATH=$(LLVM_BIN_PATH) \ |
| 127 | $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit |
Jim Stichnoth | ac9c943 | 2014-08-26 14:07:13 -0700 | [diff] [blame] | 128 | |
| 129 | check: check-lit |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 130 | (cd crosstest; ./runtests.sh) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 131 | |
| 132 | # TODO: Fix the use of wildcards. |
Jim Stichnoth | 240e0f8 | 2014-07-09 16:53:40 -0700 | [diff] [blame] | 133 | # Assumes clang-format is within $PATH. |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 134 | format: |
Jim Stichnoth | 240e0f8 | 2014-07-09 16:53:40 -0700 | [diff] [blame] | 135 | 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. |
| 142 | ifeq (,$(wildcard /usr/lib/clang-format/clang-format-diff.py)) |
| 143 | CLANG_FORMAT_DIFF = clang-format-diff.py |
| 144 | else |
| 145 | CLANG_FORMAT_DIFF = /usr/lib/clang-format/clang-format-diff.py |
| 146 | endif |
| 147 | format-diff: |
Jim Stichnoth | 206833c | 2014-08-07 10:58:05 -0700 | [diff] [blame] | 148 | git diff -U0 `git merge-base HEAD master` | \ |
Jim Stichnoth | 240e0f8 | 2014-07-09 16:53:40 -0700 | [diff] [blame] | 149 | $(CLANG_FORMAT_DIFF) -p1 -style=LLVM -i |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 150 | |
| 151 | clean: |
| 152 | rm -rf llvm2ice *.o build/ |