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 |
| 26 | PROJ_resources_lib := $(PROJ_resources)/lib |
| 27 | |
| 28 | # Expect compiler-rt to be in llvm/projects/compiler-rt |
| 29 | COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt |
| 30 | |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 31 | # We don't currently support building runtime libraries when we are |
| 32 | # cross-compiling. The issue is that we really want to be set up so that the |
| 33 | # available compiler targets are independent of the current build. |
| 34 | # |
| 35 | # Since we have to build the runtime libraries for the target, it requires we |
| 36 | # have a cross compiler from the build machine to the target. Although in the |
| 37 | # case where for the current build (host == target), we do have such a cross |
| 38 | # compiler, but not defined in a way that is easy for us to reuse. Regardless, |
| 39 | # that also wouldn't help for other possible compiler configurations. |
| 40 | # |
| 41 | # Thus, the simple set up we currently use is to assume that we will be using |
| 42 | # the just built Clang to compile the compiler-rt libraries. As we grow better |
| 43 | # cross compilation support inside Clang and tool support in LLVM, this makes it |
| 44 | # easier for us to achieve the goal of having the compiler targets be easily |
| 45 | # selected at configure time. However, this design does currently preclude the |
| 46 | # building of compiler-rt libraries when the Clang itself is being cross |
| 47 | # compiled. |
| 48 | # |
| 49 | # There are three possible solutions: |
| 50 | # 1. Require building a build-target version of Clang when cross compiling. This |
| 51 | # is simplest, but als greatly increases the build time of cross builds. |
| 52 | # |
| 53 | # 2. Require cross builds have a build-target version of Clang available for |
| 54 | # use. This is a reasonable compromise on #1, as the compiler-rt libraries |
| 55 | # are simple enough that there is not a strong desire to ensure they are |
| 56 | # built with the exact version of Clang being used. Similarly, as Clang |
| 57 | # becomes a better cross compiler it is also increasingly more likely that |
| 58 | # the cross compiler being used will already be a version of Clang. |
| 59 | # |
| 60 | # 3. Come up with an alternate mechanism to define all the toolchain |
| 61 | # information that compiler-rt would need to build libraries for all the |
| 62 | # requested targets. This might be a simple short term solution, but is |
| 63 | # likely to be unwieldly and irritating to maintain in the long term. |
| 64 | ifneq ($(LLVM_CROSS_COMPILING),1) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 65 | ifneq ($(CLANG_NO_RUNTIME),1) |
| 66 | ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK) |
| 67 | |
| 68 | # Select the compiler-rt configuration to use, and install directory. |
| 69 | # |
| 70 | # FIXME: Eventually, we want some kind of configure support for this. We want to |
| 71 | # build/install runtime libraries for as many targets as clang was configured to |
| 72 | # support. |
| 73 | RuntimeDirs := |
| 74 | ifeq ($(OS),Darwin) |
| 75 | RuntimeDirs += darwin |
Daniel Dunbar | f471487 | 2011-11-17 00:36:57 +0000 | [diff] [blame] | 76 | RuntimeLibrary.darwin.Configs := \ |
Daniel Dunbar | 7a0c064 | 2012-10-15 22:23:53 +0000 | [diff] [blame] | 77 | eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 78 | asan_osx.a asan_osx_dynamic.dylib \ |
Alexey Samsonov | 75fcb19 | 2012-11-16 12:53:14 +0000 | [diff] [blame] | 79 | profile_osx.a profile_ios.a \ |
| 80 | ubsan_osx.a |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 81 | endif |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 82 | |
| 83 | # On Linux, include a library which has all the runtime functions. |
| 84 | ifeq ($(OS),Linux) |
| 85 | RuntimeDirs += linux |
| 86 | RuntimeLibrary.linux.Configs := |
| 87 | |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 88 | # TryCompile compiler source flags |
| 89 | # Returns exit code of running a compiler invocation. |
| 90 | TryCompile = \ |
| 91 | $(shell \ |
| 92 | cflags=""; \ |
| 93 | for flag in $(3); do \ |
| 94 | cflags="$$cflags $$flag"; \ |
| 95 | done; \ |
| 96 | $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \ |
| 97 | echo $$?) |
| 98 | |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 99 | # We currently only try to generate runtime libraries on x86. |
| 100 | ifeq ($(ARCH),x86) |
Daniel Dunbar | 7df67e6 | 2011-12-07 19:35:10 +0000 | [diff] [blame] | 101 | RuntimeLibrary.linux.Configs += \ |
Alexey Samsonov | e0d80f1 | 2012-11-15 12:40:37 +0000 | [diff] [blame] | 102 | full-i386.a profile-i386.a asan-i386.a ubsan-i386.a |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 103 | endif |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 104 | |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 105 | ifeq ($(ARCH),x86_64) |
Daniel Dunbar | 7df67e6 | 2011-12-07 19:35:10 +0000 | [diff] [blame] | 106 | RuntimeLibrary.linux.Configs += \ |
Alexey Samsonov | e0d80f1 | 2012-11-15 12:40:37 +0000 | [diff] [blame] | 107 | full-x86_64.a profile-x86_64.a asan-x86_64.a tsan-x86_64.a ubsan-x86_64.a |
| 108 | # We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and add them |
| 109 | # to the list of runtime libraries to make |
| 110 | # "clang -fsanitize=(address|undefined) -m32" work. |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 111 | # We check that Clang can produce working 32-bit binaries by compiling a simple |
| 112 | # executable. |
| 113 | test_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c |
| 114 | ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0) |
Alexey Samsonov | e0d80f1 | 2012-11-15 12:40:37 +0000 | [diff] [blame] | 115 | RuntimeLibrary.linux.Configs += asan-i386.a ubsan-i386.a |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 116 | endif |
Evgeniy Stepanov | 19baf06 | 2012-10-24 14:05:29 +0000 | [diff] [blame] | 117 | ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) |
| 118 | RuntimeLibrary.linux.Configs += asan-arm-android.so |
| 119 | endif |
Alexey Samsonov | f288d22 | 2012-10-09 16:03:52 +0000 | [diff] [blame] | 120 | endif |
Daniel Dunbar | ff98652 | 2011-12-02 02:31:32 +0000 | [diff] [blame] | 121 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 122 | endif |
| 123 | |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 124 | #### |
| 125 | # The build rules below are designed to be generic and should only need to be |
| 126 | # modified based on changes in the compiler-rt layout or build system. |
| 127 | #### |
| 128 | |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 129 | # Rule to build the compiler-rt libraries we need. |
| 130 | # |
| 131 | # We build all the libraries in a single shot to avoid recursive make as much as |
| 132 | # possible. |
| 133 | BuildRuntimeLibraries: |
| 134 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 135 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 136 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
Daniel Dunbar | 3518058 | 2012-03-05 20:19:03 +0000 | [diff] [blame] | 137 | CC="$(ToolDir)/clang" \ |
Evgeniy Stepanov | 19baf06 | 2012-10-24 14:05:29 +0000 | [diff] [blame] | 138 | LLVM_ANDROID_TOOLCHAIN_DIR="$(LLVM_ANDROID_TOOLCHAIN_DIR)" \ |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 139 | $(RuntimeDirs:%=clang_%) |
| 140 | .PHONY: BuildRuntimeLibraries |
| 141 | CleanRuntimeLibraries: |
| 142 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 143 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 144 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
| 145 | clean |
| 146 | .PHONY: CleanRuntimeLibraries |
| 147 | |
| 148 | $(PROJ_resources_lib): |
| 149 | $(Verb) $(MKDIR) $@ |
| 150 | |
| 151 | # Expand rules for copying/installing each individual library. We can't use |
| 152 | # implicit rules here because we need to match against multiple things. |
| 153 | define RuntimeLibraryTemplate |
| 154 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries |
| 155 | @true |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 156 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries |
| 157 | @true |
| 158 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries |
| 159 | @true |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 160 | .PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a |
| 161 | |
| 162 | # Rule to copy the libraries to their resource directory location. |
| 163 | $(ResourceLibDir)/$1/libclang_rt.%.a: \ |
| 164 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \ |
| 165 | $(ResourceLibDir)/$1/.dir |
| 166 | $(Echo) Copying runtime library $1/$$* to build dir |
| 167 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 168 | $(ResourceLibDir)/$1/libclang_rt.%.so: \ |
| 169 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \ |
| 170 | $(ResourceLibDir)/$1/.dir |
| 171 | $(Echo) Copying runtime library $1/$$* to build dir |
| 172 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@ |
| 173 | $(ResourceLibDir)/$1/libclang_rt.%.dylib: \ |
| 174 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \ |
| 175 | $(ResourceLibDir)/$1/.dir |
| 176 | $(Echo) Copying runtime library $1/$$* to build dir |
| 177 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@ |
Alexander Potapenko | b626280 | 2012-09-17 14:18:41 +0000 | [diff] [blame] | 178 | $(Echo) Fixing LC_ID_DYLIB of $$@ |
| 179 | $(Verb) install_name_tool $$@ -id $$@ |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 180 | RuntimeLibrary.$1: \ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 181 | $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 182 | .PHONY: RuntimeLibrary.$1 |
| 183 | |
| 184 | $(PROJ_resources_lib)/$1: $(PROJ_resources_lib) |
| 185 | $(Verb) $(MKDIR) $$@ |
| 186 | |
| 187 | $(PROJ_resources_lib)/$1/libclang_rt.%.a: \ |
| 188 | $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 |
| 189 | $(Echo) Installing compiler runtime library: $1/$$* |
| 190 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 191 | $(PROJ_resources_lib)/$1/libclang_rt.%.so: \ |
| 192 | $(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1 |
| 193 | $(Echo) Installing compiler runtime library: $1/$$* |
| 194 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
| 195 | $(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \ |
| 196 | $(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1 |
| 197 | $(Echo) Installing compiler runtime library: $1/$$* |
| 198 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 199 | |
| 200 | # Rule to install runtime libraries. |
| 201 | RuntimeLibraryInstall.$1: \ |
Daniel Dunbar | 12f5fe5 | 2012-09-14 21:30:17 +0000 | [diff] [blame] | 202 | $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%) |
Owen Anderson | 562627d | 2011-04-15 17:35:58 +0000 | [diff] [blame] | 203 | .PHONY: RuntimeLibraryInstall.$1 |
| 204 | endef |
| 205 | $(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) |
| 206 | |
| 207 | # Hook into the standard Makefile rules. |
| 208 | all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) |
| 209 | install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) |
| 210 | clean-local:: CleanRuntimeLibraries |
| 211 | |
| 212 | endif |
| 213 | endif |
Daniel Dunbar | e33218a | 2011-11-16 23:22:07 +0000 | [diff] [blame] | 214 | endif |