Makefile revision 176edba5311f6eff0cad2631449885ddf4fbc9ea
1##===- clang/runtime/compiler-rt/Makefile ------------------*- Makefile -*-===## 2# 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. 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# 14##===----------------------------------------------------------------------===## 15 16CLANG_LEVEL := ../.. 17include $(CLANG_LEVEL)/Makefile 18 19CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \ 20 $(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc)) 21 22ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION) 23PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION) 24 25ResourceLibDir := $(ResourceDir)/lib 26ResourceIncludeDir := $(ResourceDir)/include 27PROJ_resources_lib := $(PROJ_resources)/lib 28PROJ_resources_include := $(PROJ_resources)/include 29 30# Expect compiler-rt to be in llvm/projects/compiler-rt 31COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt 32 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 65# likely to be unwieldy and irritating to maintain in the long term. 66ifneq ($(LLVM_CROSS_COMPILING),1) 67ifneq ($(CLANG_NO_RUNTIME),1) 68ifeq ($(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. 75RuntimeDirs := 76ifeq ($(OS),Darwin) 77RuntimeDirs += darwin macho_embedded 78RuntimeLibrary.darwin.Configs := \ 79 eprintf.a 10.4.a osx.a cc_kext.a \ 80 asan_osx_dynamic.dylib \ 81 profile_osx.a \ 82 ubsan_osx.a 83 84IOS_SDK := $(shell xcrun --show-sdk-path -sdk iphoneos 2> /dev/null) 85IOSSIM_SDK := $(shell xcrun --show-sdk-path -sdk iphonesimulator 2> /dev/null) 86 87ifneq ($(IOS_SDK)$(IOSSIM_SDK),) 88RuntimeLibrary.darwin.Configs += ios.a profile_ios.a 89endif 90 91ifneq ($(IOS_SDK),) 92RuntimeLibrary.darwin.Configs += cc_kext_ios5.a 93endif 94 95ifneq ($(IOSSIM_SDK),) 96RuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib 97endif 98 99RuntimeLibrary.macho_embedded.Configs := \ 100 hard_static.a hard_pic.a 101ifneq (,$(findstring ARM,$(TARGETS_TO_BUILD))) 102RuntimeLibrary.macho_embedded.Configs += \ 103 soft_static.a soft_pic.a 104endif 105endif 106 107# On Linux, include a library which has all the runtime functions. 108ifeq ($(OS),Linux) 109RuntimeDirs += linux 110RuntimeLibrary.linux.Configs := 111 112# TryCompile compiler source flags 113# Returns exit code of running a compiler invocation. 114TryCompile = \ 115 $(shell \ 116 cflags=""; \ 117 for flag in $(3); do \ 118 cflags="$$cflags $$flag"; \ 119 done; \ 120 $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \ 121 echo $$?) 122 123# We try to build 32-bit runtimes both on 32-bit hosts and 64-bit hosts. 124Runtime32BitConfigs = \ 125 builtins-i386.a profile-i386.a san-i386.a asan-i386.a asan_cxx-i386.a \ 126 ubsan-i386.a ubsan_cxx-i386.a 127 128# We currently only try to generate runtime libraries on x86. 129ifeq ($(ARCH),x86) 130RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs) 131endif 132 133ifeq ($(ARCH),x86_64) 134RuntimeLibrary.linux.Configs += \ 135 builtins-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \ 136 asan_cxx-x86_64.a tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a \ 137 ubsan_cxx-x86_64.a dfsan-x86_64.a lsan-x86_64.a 138# We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and add them 139# to the list of runtime libraries to make 140# "clang -fsanitize=(address|undefined) -m32" work. 141# We check that Clang can produce working 32-bit binaries by compiling a simple 142# executable. 143test_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c 144ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0) 145RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs) 146endif 147ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) 148RuntimeLibrary.linux.Configs += asan-arm-android.so 149endif 150endif 151 152endif 153 154#### 155# The build rules below are designed to be generic and should only need to be 156# modified based on changes in the compiler-rt layout or build system. 157#### 158 159# Rule to build the compiler-rt libraries we need. 160# 161# We build all the libraries in a single shot to avoid recursive make as much as 162# possible. 163BuildRuntimeLibraries: 164 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ 165 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ 166 ProjObjRoot=$(PROJ_OBJ_DIR) \ 167 CC="$(ToolDir)/clang" \ 168 VERBOSE=$(VERBOSE) \ 169 LLVM_ANDROID_TOOLCHAIN_DIR="$(LLVM_ANDROID_TOOLCHAIN_DIR)" \ 170 $(RuntimeDirs:%=clang_%) 171.PHONY: BuildRuntimeLibraries 172CleanRuntimeLibraries: 173 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ 174 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ 175 ProjObjRoot=$(PROJ_OBJ_DIR) \ 176 VERBOSE=$(VERBOSE) \ 177 clean 178.PHONY: CleanRuntimeLibraries 179RuntimeHeader: $(ResourceIncludeDir)/sanitizer 180 181$(PROJ_resources_lib): 182 $(Verb) $(MKDIR) $@ 183 184$(ResourceIncludeDir): 185 $(Verb) $(MKDIR) $@ 186 187$(ResourceIncludeDir)/sanitizer: $(ResourceIncludeDir) 188 $(Verb) $(MKDIR) $@ 189 $(Verb) cp $(COMPILERRT_SRC_ROOT)/include/sanitizer/*.h $@ 190 191# Expand rules for copying/installing each individual library. We can't use 192# implicit rules here because we need to match against multiple things. 193define RuntimeLibraryTemplate 194$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries 195 @true 196$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries 197 @true 198$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries 199 @true 200.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a 201 202# Rule to copy the libraries to their resource directory location. 203$(ResourceLibDir)/$1/libclang_rt.%.a: \ 204 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \ 205 $(ResourceLibDir)/$1/.dir 206 $(Echo) Copying runtime library $1/$$* to build dir 207 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ 208$(ResourceLibDir)/$1/libclang_rt.%.so: \ 209 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \ 210 $(ResourceLibDir)/$1/.dir 211 $(Echo) Copying runtime library $1/$$* to build dir 212 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@ 213$(ResourceLibDir)/$1/libclang_rt.%.dylib: \ 214 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \ 215 $(ResourceLibDir)/$1/.dir 216 $(Echo) Copying runtime library $1/$$* to build dir 217 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@ 218RuntimeLibrary.$1: \ 219 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%) 220.PHONY: RuntimeLibrary.$1 221 222$(PROJ_resources_lib)/$1: $(PROJ_resources_lib) 223 $(Verb) $(MKDIR) $$@ 224 225$(PROJ_resources_lib)/$1/libclang_rt.%.a: \ 226 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 227 $(Echo) Installing compiler runtime library: $1/$$* 228 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 229$(PROJ_resources_lib)/$1/libclang_rt.%.so: \ 230 $(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1 231 $(Echo) Installing compiler runtime library: $1/$$* 232 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 233$(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \ 234 $(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1 235 $(Echo) Installing compiler runtime library: $1/$$* 236 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 237 238# Rule to install runtime libraries. 239RuntimeLibraryInstall.$1: \ 240 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%) 241.PHONY: RuntimeLibraryInstall.$1 242endef 243$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) 244 245$(PROJ_resources_include): 246 $(Verb) $(MKDIR) $@ 247 248$(PROJ_resources_include)/sanitizer: $(ResourceIncludeDir)/sanitizer $(PROJ_resources_include) 249 $(Verb) $(MKDIR) $@ 250 $(Echo) Installing compiler runtime headers 251 $(Verb) $(DataInstall) $(ResourceIncludeDir)/sanitizer/* \ 252 $(PROJ_resources_include)/sanitizer 253 254RuntimeHeaderInstall: $(PROJ_resources_include)/sanitizer 255.PHONY: RuntimeHeaderInstall 256 257# Hook into the standard Makefile rules. 258all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) RuntimeHeader 259install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) RuntimeHeaderInstall 260clean-local:: CleanRuntimeLibraries 261 262endif 263endif 264endif 265