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 |
Jim Stichnoth | a49e9d9 | 2014-12-07 14:25:34 -0800 | [diff] [blame] | 45 | OPTLEVEL = -O2 -ffunction-sections -fdata-sections |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 46 | endif |
| 47 | |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 48 | # The list of CXX defines that are dependent on build parameters. |
| 49 | CXX_DEFINES = |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 50 | CXX_EXTRA = |
| 51 | LD_EXTRA = |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 52 | |
| 53 | ifdef MINIMAL |
Jim Stichnoth | e3c02c2 | 2014-12-05 14:16:07 -0800 | [diff] [blame] | 54 | NOASSERT = 1 |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 55 | OBJDIR := $(OBJDIR)+Min |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 56 | CXX_DEFINES += -DALLOW_DUMP=0 -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \ |
| 57 | -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_DISABLE_IR_GEN=0 |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 58 | else |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 59 | CXX_DEFINES += -DALLOW_DUMP=1 -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \ |
| 60 | -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_DISABLE_IR_GEN=1 |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 61 | endif |
| 62 | |
Jim Stichnoth | 9c234e2 | 2014-10-01 09:28:21 -0700 | [diff] [blame] | 63 | ifdef NOASSERT |
| 64 | ASSERTIONS = -DNDEBUG |
| 65 | else |
| 66 | ASSERTIONS = |
| 67 | OBJDIR := $(OBJDIR)+Asserts |
| 68 | endif |
| 69 | |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 70 | ifdef TSAN |
| 71 | OBJDIR := $(OBJDIR)+TSan |
| 72 | CXX_EXTRA += -fsanitize=thread |
| 73 | LD_EXTRA += -fsanitize=thread |
| 74 | endif |
| 75 | |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 76 | $(info -----------------------------------------------) |
| 77 | $(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH)) |
| 78 | $(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH)) |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 79 | $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH)) |
| 80 | $(info Using CLANG_PATH = $(CLANG_PATH)) |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 81 | $(info Using HOST_ARCH = $(HOST_ARCH)) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 82 | $(info -----------------------------------------------) |
| 83 | |
| 84 | LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags` |
Jim Stichnoth | 14c3f41 | 2014-08-27 11:02:50 -0700 | [diff] [blame] | 85 | LLVM_LDFLAGS := `$(LLVM_BIN_PATH)/llvm-config --libs` \ |
Jim Stichnoth | 3324642 | 2014-11-24 14:36:23 -0800 | [diff] [blame] | 86 | `$(LLVM_BIN_PATH)/llvm-config --ldflags` \ |
| 87 | `$(LLVM_BIN_PATH)/llvm-config --system-libs` |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 88 | |
| 89 | # 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] | 90 | CCACHE := `command -v ccache` |
| 91 | CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++ |
Jan Voung | 839c4ce | 2014-07-28 15:19:43 -0700 | [diff] [blame] | 92 | |
Jim Stichnoth | 8e8042c | 2014-09-25 17:51:47 -0700 | [diff] [blame] | 93 | CXXFLAGS := $(LLVM_CXXFLAGS) -std=c++11 -Wall -Wextra -Werror -fno-rtti \ |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 94 | -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) $(CXX_DEFINES) -g \ |
Jim Stichnoth | 26f9433 | 2015-01-28 08:37:22 -0800 | [diff] [blame^] | 95 | $(HOST_FLAGS) -pedantic -Wno-error=unused-parameter \ |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 96 | -I$(LIBCXX_INSTALL_PATH)/include/c++/v1 $(CXX_EXTRA) |
| 97 | LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \ |
| 98 | $(LD_EXTRA) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 99 | |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 100 | SRCS = \ |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 101 | assembler.cpp \ |
| 102 | assembler_ia32.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 103 | IceCfg.cpp \ |
| 104 | IceCfgNode.cpp \ |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 105 | IceELFObjectWriter.cpp \ |
| 106 | IceELFSection.cpp \ |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 107 | IceFixups.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 108 | IceGlobalContext.cpp \ |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 109 | IceGlobalInits.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 110 | IceInst.cpp \ |
| 111 | IceInstX8632.cpp \ |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 112 | IceIntrinsics.cpp \ |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 113 | IceLiveness.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 114 | IceOperand.cpp \ |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 115 | IceRegAlloc.cpp \ |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 116 | IceRNG.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 117 | IceTargetLowering.cpp \ |
| 118 | IceTargetLoweringX8632.cpp \ |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 119 | IceTimerTree.cpp \ |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 120 | IceTranslator.cpp \ |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 121 | IceTypes.cpp \ |
Karl Schimpf | 8d7abae | 2014-07-07 14:50:30 -0700 | [diff] [blame] | 122 | llvm2ice.cpp \ |
| 123 | PNaClTranslator.cpp |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 124 | |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 125 | ifndef MINIMAL |
Karl Schimpf | 4019f08 | 2014-12-15 13:45:00 -0800 | [diff] [blame] | 126 | SRCS += IceConverter.cpp \ |
| 127 | IceTypeConverter.cpp |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 128 | endif |
| 129 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 130 | OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS)) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 131 | |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 132 | UNITTEST_SRCS = \ |
Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 133 | BitcodeMunge.cpp \ |
| 134 | IceELFSectionTest.cpp \ |
| 135 | IceParseInstsTest.cpp |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 136 | |
| 137 | UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS)) |
| 138 | UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/llvm2ice.o,$(OBJS)) |
| 139 | |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 140 | # Keep all the first target so it's the default. |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 141 | all: $(OBJDIR)/llvm2ice make_symlink |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 142 | |
Karl Schimpf | 6af6336 | 2014-10-29 14:55:00 -0700 | [diff] [blame] | 143 | # Creates symbolic link so that testing is easier. Also runs |
| 144 | # llvm2ice to verify that the defines flags have valid values, |
| 145 | # as well as describe the corresponding build attributes. |
| 146 | make_symlink: $(OBJDIR)/llvm2ice |
| 147 | rm -rf llvm2ice |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 148 | ln -s $(OBJDIR)/llvm2ice |
Karl Schimpf | 6af6336 | 2014-10-29 14:55:00 -0700 | [diff] [blame] | 149 | @echo "Build Attributes:" |
| 150 | @$(OBJDIR)/llvm2ice --build-atts |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 151 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 152 | .PHONY: all make_symlink |
| 153 | |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 154 | # TODO(kschimpf): Fix python scripts to directly get build attributes |
| 155 | # rather than generating $(OBJDIR)/llvm2ice.build_atts. |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 156 | $(OBJDIR)/llvm2ice: $(OBJS) |
Jim Stichnoth | 3324642 | 2014-11-24 14:36:23 -0800 | [diff] [blame] | 157 | $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \ |
Karl Schimpf | 8fcefc3 | 2014-09-15 12:56:50 -0700 | [diff] [blame] | 158 | -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 159 | |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 160 | # TODO(stichnot): Be more precise than "*.h" here and elsewhere. |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 161 | $(OBJS): $(OBJDIR)/%.o: src/%.cpp src/*.h src/*.def |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 162 | $(CXX) -c $(CXXFLAGS) $< -o $@ |
| 163 | |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 164 | $(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS) |
| 165 | $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -lgtest -lgtest_main -ldl \ |
| 166 | -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) |
| 167 | |
| 168 | $(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp |
| 169 | $(CXX) -c $(CXXFLAGS) \ |
| 170 | -Isrc/ \ |
| 171 | -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \ |
| 172 | -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \ |
| 173 | $< -o $@ |
| 174 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 175 | $(OBJS): | $(OBJDIR) |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 176 | |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 177 | $(UNITTEST_OBJS): | $(OBJDIR)/unittest |
| 178 | |
Jim Stichnoth | fddef24 | 2014-09-26 18:53:41 -0700 | [diff] [blame] | 179 | $(OBJDIR): |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 180 | @mkdir -p $@ |
| 181 | |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 182 | $(OBJDIR)/unittest: $(OBJDIR) |
| 183 | @mkdir -p $@ |
| 184 | |
Jim Stichnoth | c4554d7 | 2014-09-30 16:49:38 -0700 | [diff] [blame] | 185 | check-lit: llvm2ice make_symlink |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 186 | LLVM_BIN_PATH=$(LLVM_BIN_PATH) \ |
| 187 | $(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit |
Jim Stichnoth | ac9c943 | 2014-08-26 14:07:13 -0700 | [diff] [blame] | 188 | |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 189 | check-unit: $(OBJDIR)/run_unittests |
| 190 | $(OBJDIR)/run_unittests |
| 191 | |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 192 | ifdef MINIMAL |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 193 | check: check-lit check-unit |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 194 | @echo "Crosstests ignored, minimal build" |
| 195 | else |
Jan Voung | 08c3bcd | 2014-12-01 17:55:16 -0800 | [diff] [blame] | 196 | check: check-lit check-unit |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 197 | (cd crosstest; ./runtests.sh) |
Karl Schimpf | ab06df3 | 2014-10-29 14:58:25 -0700 | [diff] [blame] | 198 | endif |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 199 | |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 200 | FORMAT_BLACKLIST = |
| 201 | # Add one of the following lines for each source file to ignore. |
| 202 | FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 203 | format: |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 204 | $(LLVM_BIN_PATH)/clang-format -style=LLVM -i \ |
| 205 | `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)` |
Jim Stichnoth | 240e0f8 | 2014-07-09 16:53:40 -0700 | [diff] [blame] | 206 | |
Jim Stichnoth | 240e0f8 | 2014-07-09 16:53:40 -0700 | [diff] [blame] | 207 | format-diff: |
Jim Stichnoth | 206833c | 2014-08-07 10:58:05 -0700 | [diff] [blame] | 208 | git diff -U0 `git merge-base HEAD master` | \ |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 209 | PATH=$(LLVM_BIN_PATH):$(PATH) \ |
| 210 | $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \ |
| 211 | -p1 -style=LLVM -i |
Derek Schuff | bc64313 | 2014-05-22 16:39:25 -0700 | [diff] [blame] | 212 | |
| 213 | clean: |
Karl Schimpf | 6af6336 | 2014-10-29 14:55:00 -0700 | [diff] [blame] | 214 | rm -rf llvm2ice *.o $(OBJDIR) |
Karl Schimpf | b262c5e | 2014-10-27 14:41:57 -0700 | [diff] [blame] | 215 | |
| 216 | clean-all: clean |
| 217 | rm -rf build/ |