Bob Wilson | da79da2 | 2011-09-30 20:24:28 +0000 | [diff] [blame] | 1 | ##===- clang/runtime/compiler-rt/Makefile ------------------*- Makefile -*-===## |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 2 | # |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 3 | # The LLVM Compiler Infrastructure |
| 4 | # |
| 5 | # This file is distributed under the University of Illinois Open Source |
| 6 | # License. See LICENSE.TXT for details. |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 7 | # |
| 8 | ##===----------------------------------------------------------------------===## |
| 9 | # |
| 10 | # This file defines support for building the Clang runtime libraries (which are |
| 11 | # implemented by compiler-rt) and placing them in the proper locations in the |
| 12 | # Clang resources directory (i.e., where the driver expects them). |
| 13 | # |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 14 | ##===----------------------------------------------------------------------===## |
| 15 | |
Nick Lewycky | 484fc57 | 2011-04-15 18:33:24 +0000 | [diff] [blame] | 16 | CLANG_LEVEL := ../.. |
Daniel Dunbar | afed099 | 2010-06-08 20:34:18 +0000 | [diff] [blame] | 17 | include $(CLANG_LEVEL)/Makefile |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 18 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 19 | CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \ |
| 20 | $(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc)) |
| 21 | |
| 22 | ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION) |
| 23 | PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION) |
| 24 | |
| 25 | ResourceLibDir := $(ResourceDir)/lib |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 26 | ResourceIncludeDir := $(ResourceDir)/include |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 27 | PROJ_resources_lib := $(PROJ_resources)/lib |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 28 | PROJ_resources_include := $(PROJ_resources)/include |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 29 | |
| 30 | # Expect compiler-rt to be in llvm/projects/compiler-rt |
| 31 | COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt |
| 32 | |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 33 | # We don't currently support building runtime libraries when we are |
| 34 | # cross-compiling. The issue is that we really want to be set up so that the |
| 35 | # available compiler targets are independent of the current build. |
| 36 | # |
| 37 | # Since we have to build the runtime libraries for the target, it requires we |
| 38 | # have a cross compiler from the build machine to the target. Although in the |
| 39 | # case where for the current build (host == target), we do have such a cross |
| 40 | # compiler, but not defined in a way that is easy for us to reuse. Regardless, |
| 41 | # that also wouldn't help for other possible compiler configurations. |
| 42 | # |
| 43 | # Thus, the simple set up we currently use is to assume that we will be using |
| 44 | # the just built Clang to compile the compiler-rt libraries. As we grow better |
| 45 | # cross compilation support inside Clang and tool support in LLVM, this makes it |
| 46 | # easier for us to achieve the goal of having the compiler targets be easily |
| 47 | # selected at configure time. However, this design does currently preclude the |
| 48 | # building of compiler-rt libraries when the Clang itself is being cross |
| 49 | # compiled. |
| 50 | # |
| 51 | # There are three possible solutions: |
| 52 | # 1. Require building a build-target version of Clang when cross compiling. This |
| 53 | # is simplest, but als greatly increases the build time of cross builds. |
| 54 | # |
| 55 | # 2. Require cross builds have a build-target version of Clang available for |
| 56 | # use. This is a reasonable compromise on #1, as the compiler-rt libraries |
| 57 | # are simple enough that there is not a strong desire to ensure they are |
| 58 | # built with the exact version of Clang being used. Similarly, as Clang |
| 59 | # becomes a better cross compiler it is also increasingly more likely that |
| 60 | # the cross compiler being used will already be a version of Clang. |
| 61 | # |
| 62 | # 3. Come up with an alternate mechanism to define all the toolchain |
| 63 | # information that compiler-rt would need to build libraries for all the |
| 64 | # requested targets. This might be a simple short term solution, but is |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 65 | # likely to be unwieldy and irritating to maintain in the long term. |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 66 | ifneq ($(LLVM_CROSS_COMPILING),1) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 67 | ifneq ($(CLANG_NO_RUNTIME),1) |
| 68 | ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK) |
| 69 | |
| 70 | # Select the compiler-rt configuration to use, and install directory. |
| 71 | # |
| 72 | # FIXME: Eventually, we want some kind of configure support for this. We want to |
| 73 | # build/install runtime libraries for as many targets as clang was configured to |
| 74 | # support. |
| 75 | RuntimeDirs := |
| 76 | ifeq ($(OS),Darwin) |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 77 | RuntimeDirs += darwin macho_embedded |
Daniel Dunbar | f471487 | 2011-11-17 00:36:57 +0000 | [diff] [blame] | 78 | RuntimeLibrary.darwin.Configs := \ |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 79 | eprintf.a 10.4.a osx.a cc_kext.a \ |
Alexey Samsonov | f8d4a6b | 2013-05-20 14:33:20 +0000 | [diff] [blame] | 80 | asan_osx_dynamic.dylib \ |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 81 | profile_osx.a \ |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 82 | ubsan_osx_dynamic.dylib |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 83 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 84 | IOS_SDK := $(shell xcrun --show-sdk-path -sdk iphoneos 2> /dev/null) |
| 85 | IOSSIM_SDK := $(shell xcrun --show-sdk-path -sdk iphonesimulator 2> /dev/null) |
| 86 | |
| 87 | ifneq ($(IOS_SDK)$(IOSSIM_SDK),) |
| 88 | RuntimeLibrary.darwin.Configs += ios.a profile_ios.a |
| 89 | endif |
| 90 | |
| 91 | ifneq ($(IOS_SDK),) |
| 92 | RuntimeLibrary.darwin.Configs += cc_kext_ios5.a |
| 93 | endif |
| 94 | |
| 95 | ifneq ($(IOSSIM_SDK),) |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 96 | RuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib \ |
| 97 | ubsan_iossim_dynamic.dylib |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 98 | endif |
| 99 | |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 100 | RuntimeLibrary.macho_embedded.Configs := \ |
| 101 | hard_static.a hard_pic.a |
| 102 | ifneq (,$(findstring ARM,$(TARGETS_TO_BUILD))) |
| 103 | RuntimeLibrary.macho_embedded.Configs += \ |
| 104 | soft_static.a soft_pic.a |
| 105 | endif |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 106 | endif |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 107 | |
| 108 | # On Linux, include a library which has all the runtime functions. |
| 109 | ifeq ($(OS),Linux) |
| 110 | RuntimeDirs += linux |
| 111 | RuntimeLibrary.linux.Configs := |
| 112 | |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 113 | # TryCompile compiler source flags |
| 114 | # Returns exit code of running a compiler invocation. |
| 115 | TryCompile = \ |
| 116 | $(shell \ |
| 117 | cflags=""; \ |
| 118 | for flag in $(3); do \ |
| 119 | cflags="$$cflags $$flag"; \ |
| 120 | done; \ |
| 121 | $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \ |
| 122 | echo $$?) |
| 123 | |
Chandler Carruth | 230cdaa | 2013-06-23 10:10:25 +0000 | [diff] [blame] | 124 | # We try to build 32-bit runtimes both on 32-bit hosts and 64-bit hosts. |
| 125 | Runtime32BitConfigs = \ |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 126 | builtins-i386.a profile-i386.a |
Chandler Carruth | 230cdaa | 2013-06-23 10:10:25 +0000 | [diff] [blame] | 127 | |
| 128 | # We currently only try to generate runtime libraries on x86. |
| 129 | ifeq ($(ARCH),x86) |
| 130 | RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs) |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 131 | endif |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 132 | |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 133 | ifeq ($(ARCH),x86_64) |
Daniel Dunbar | 7df67e6 | 2011-12-07 19:35:10 +0000 | [diff] [blame] | 134 | RuntimeLibrary.linux.Configs += \ |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 135 | builtins-x86_64.a profile-x86_64.a |
| 136 | # We need to build 32-bit libraries on 64-bit platform, and add them |
| 137 | # to the list of runtime libraries to make "clang -m32" work. |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 138 | # We check that Clang can produce working 32-bit binaries by compiling a simple |
| 139 | # executable. |
| 140 | test_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c |
| 141 | ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0) |
Chandler Carruth | 230cdaa | 2013-06-23 10:10:25 +0000 | [diff] [blame] | 142 | RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs) |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 143 | endif |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 144 | endif |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 145 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 146 | endif |
| 147 | |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 148 | #### |
| 149 | # The build rules below are designed to be generic and should only need to be |
| 150 | # modified based on changes in the compiler-rt layout or build system. |
| 151 | #### |
| 152 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 153 | # Rule to build the compiler-rt libraries we need. |
| 154 | # |
| 155 | # We build all the libraries in a single shot to avoid recursive make as much as |
| 156 | # possible. |
| 157 | BuildRuntimeLibraries: |
| 158 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 159 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 160 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
Daniel Dunbar | 3518058 | 2012-03-05 20:19:03 +0000 | [diff] [blame] | 161 | CC="$(ToolDir)/clang" \ |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 162 | VERBOSE=$(VERBOSE) \ |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 163 | $(RuntimeDirs:%=clang_%) |
| 164 | .PHONY: BuildRuntimeLibraries |
| 165 | CleanRuntimeLibraries: |
| 166 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 167 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 168 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 169 | VERBOSE=$(VERBOSE) \ |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 170 | clean |
| 171 | .PHONY: CleanRuntimeLibraries |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 172 | RuntimeHeader: $(ResourceIncludeDir)/sanitizer |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 173 | |
| 174 | $(PROJ_resources_lib): |
| 175 | $(Verb) $(MKDIR) $@ |
| 176 | |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 177 | $(ResourceIncludeDir): |
| 178 | $(Verb) $(MKDIR) $@ |
| 179 | |
| 180 | $(ResourceIncludeDir)/sanitizer: $(ResourceIncludeDir) |
| 181 | $(Verb) $(MKDIR) $@ |
| 182 | $(Verb) cp $(COMPILERRT_SRC_ROOT)/include/sanitizer/*.h $@ |
| 183 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 184 | # Expand rules for copying/installing each individual library. We can't use |
| 185 | # implicit rules here because we need to match against multiple things. |
| 186 | define RuntimeLibraryTemplate |
| 187 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries |
| 188 | @true |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 189 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries |
| 190 | @true |
| 191 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries |
| 192 | @true |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 193 | .PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a |
| 194 | |
| 195 | # Rule to copy the libraries to their resource directory location. |
| 196 | $(ResourceLibDir)/$1/libclang_rt.%.a: \ |
| 197 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \ |
| 198 | $(ResourceLibDir)/$1/.dir |
| 199 | $(Echo) Copying runtime library $1/$$* to build dir |
| 200 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 201 | $(ResourceLibDir)/$1/libclang_rt.%.so: \ |
| 202 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \ |
| 203 | $(ResourceLibDir)/$1/.dir |
| 204 | $(Echo) Copying runtime library $1/$$* to build dir |
| 205 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@ |
| 206 | $(ResourceLibDir)/$1/libclang_rt.%.dylib: \ |
| 207 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \ |
| 208 | $(ResourceLibDir)/$1/.dir |
| 209 | $(Echo) Copying runtime library $1/$$* to build dir |
| 210 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@ |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 211 | RuntimeLibrary.$1: \ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 212 | $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 213 | .PHONY: RuntimeLibrary.$1 |
| 214 | |
| 215 | $(PROJ_resources_lib)/$1: $(PROJ_resources_lib) |
| 216 | $(Verb) $(MKDIR) $$@ |
| 217 | |
| 218 | $(PROJ_resources_lib)/$1/libclang_rt.%.a: \ |
| 219 | $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 |
| 220 | $(Echo) Installing compiler runtime library: $1/$$* |
| 221 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 222 | $(PROJ_resources_lib)/$1/libclang_rt.%.so: \ |
| 223 | $(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1 |
| 224 | $(Echo) Installing compiler runtime library: $1/$$* |
| 225 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
| 226 | $(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \ |
| 227 | $(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1 |
| 228 | $(Echo) Installing compiler runtime library: $1/$$* |
| 229 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 230 | |
| 231 | # Rule to install runtime libraries. |
| 232 | RuntimeLibraryInstall.$1: \ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 233 | $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 234 | .PHONY: RuntimeLibraryInstall.$1 |
| 235 | endef |
| 236 | $(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) |
| 237 | |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 238 | $(PROJ_resources_include): |
| 239 | $(Verb) $(MKDIR) $@ |
| 240 | |
| 241 | $(PROJ_resources_include)/sanitizer: $(ResourceIncludeDir)/sanitizer $(PROJ_resources_include) |
| 242 | $(Verb) $(MKDIR) $@ |
| 243 | $(Echo) Installing compiler runtime headers |
| 244 | $(Verb) $(DataInstall) $(ResourceIncludeDir)/sanitizer/* \ |
| 245 | $(PROJ_resources_include)/sanitizer |
| 246 | |
| 247 | RuntimeHeaderInstall: $(PROJ_resources_include)/sanitizer |
| 248 | .PHONY: RuntimeHeaderInstall |
| 249 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 250 | # Hook into the standard Makefile rules. |
Alexander Potapenko | 0e7a1cf | 2013-10-28 08:21:35 +0000 | [diff] [blame] | 251 | all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) RuntimeHeader |
| 252 | install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) RuntimeHeaderInstall |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 253 | clean-local:: CleanRuntimeLibraries |
| 254 | |
| 255 | endif |
| 256 | endif |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 257 | endif |