Makefile revision a0889a8c3299b1950e0a2dfa1d1656e5aa60f193
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 26PROJ_resources_lib := $(PROJ_resources)/lib 27 28# Expect compiler-rt to be in llvm/projects/compiler-rt 29COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt 30 31# Additional flags to pass to Clang. 32CLANG_CCFLAGS := 33ifeq ($(ARCH), arm) 34CLANG_CCFLAGS += -no-integrated-as 35endif 36 37# We don't currently support building runtime libraries when we are 38# cross-compiling. The issue is that we really want to be set up so that the 39# available compiler targets are independent of the current build. 40# 41# Since we have to build the runtime libraries for the target, it requires we 42# have a cross compiler from the build machine to the target. Although in the 43# case where for the current build (host == target), we do have such a cross 44# compiler, but not defined in a way that is easy for us to reuse. Regardless, 45# that also wouldn't help for other possible compiler configurations. 46# 47# Thus, the simple set up we currently use is to assume that we will be using 48# the just built Clang to compile the compiler-rt libraries. As we grow better 49# cross compilation support inside Clang and tool support in LLVM, this makes it 50# easier for us to achieve the goal of having the compiler targets be easily 51# selected at configure time. However, this design does currently preclude the 52# building of compiler-rt libraries when the Clang itself is being cross 53# compiled. 54# 55# There are three possible solutions: 56# 1. Require building a build-target version of Clang when cross compiling. This 57# is simplest, but als greatly increases the build time of cross builds. 58# 59# 2. Require cross builds have a build-target version of Clang available for 60# use. This is a reasonable compromise on #1, as the compiler-rt libraries 61# are simple enough that there is not a strong desire to ensure they are 62# built with the exact version of Clang being used. Similarly, as Clang 63# becomes a better cross compiler it is also increasingly more likely that 64# the cross compiler being used will already be a version of Clang. 65# 66# 3. Come up with an alternate mechanism to define all the toolchain 67# information that compiler-rt would need to build libraries for all the 68# requested targets. This might be a simple short term solution, but is 69# likely to be unwieldly and irritating to maintain in the long term. 70ifneq ($(LLVM_CROSS_COMPILING),1) 71ifneq ($(CLANG_NO_RUNTIME),1) 72ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK) 73 74# Select the compiler-rt configuration to use, and install directory. 75# 76# FIXME: Eventually, we want some kind of configure support for this. We want to 77# build/install runtime libraries for as many targets as clang was configured to 78# support. 79RuntimeDirs := 80ifeq ($(OS),Darwin) 81RuntimeDirs += darwin 82RuntimeLibrary.darwin.Configs := \ 83 eprintf 10.4 osx ios cc_kext \ 84 asan_osx profile_osx profile_ios 85 86# On Darwin, fake Clang into using the iOS assembler (since compiler-rt wants to 87# build ARM bits). 88CLANG_CCFLAGS += -ccc-install-dir \ 89 /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ 90endif 91 92# On Linux, include a library which has all the runtime functions. 93ifeq ($(OS),Linux) 94RuntimeDirs += linux 95RuntimeLibrary.linux.Configs := 96 97# We currently only try to generate runtime libraries on x86. 98ifeq ($(ARCH),x86) 99RuntimeLibrary.linux.Configs += \ 100 full-i386 profile-i386 asan-i386 101endif 102ifeq ($(ARCH),x86_64) 103RuntimeLibrary.linux.Configs += \ 104 full-x86_64 profile-x86_64 asan-x86_64 105endif 106 107endif 108 109#### 110# The build rules below are designed to be generic and should only need to be 111# modified based on changes in the compiler-rt layout or build system. 112#### 113 114# Rule to build the compiler-rt libraries we need. 115# 116# We build all the libraries in a single shot to avoid recursive make as much as 117# possible. 118BuildRuntimeLibraries: 119 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ 120 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ 121 ProjObjRoot=$(PROJ_OBJ_DIR) \ 122 CC="$(ToolDir)/clang $(CLANG_CCFLAGS)" \ 123 $(RuntimeDirs:%=clang_%) 124.PHONY: BuildRuntimeLibraries 125CleanRuntimeLibraries: 126 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ 127 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ 128 ProjObjRoot=$(PROJ_OBJ_DIR) \ 129 clean 130.PHONY: CleanRuntimeLibraries 131 132$(PROJ_resources_lib): 133 $(Verb) $(MKDIR) $@ 134 135# Expand rules for copying/installing each individual library. We can't use 136# implicit rules here because we need to match against multiple things. 137define RuntimeLibraryTemplate 138$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries 139 @true 140.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a 141 142# Rule to copy the libraries to their resource directory location. 143$(ResourceLibDir)/$1/libclang_rt.%.a: \ 144 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \ 145 $(ResourceLibDir)/$1/.dir 146 $(Echo) Copying runtime library $1/$$* to build dir 147 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ 148RuntimeLibrary.$1: \ 149 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a) 150.PHONY: RuntimeLibrary.$1 151 152$(PROJ_resources_lib)/$1: $(PROJ_resources_lib) 153 $(Verb) $(MKDIR) $$@ 154 155$(PROJ_resources_lib)/$1/libclang_rt.%.a: \ 156 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 157 $(Echo) Installing compiler runtime library: $1/$$* 158 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 159 160# Rule to install runtime libraries. 161RuntimeLibraryInstall.$1: \ 162 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a) 163.PHONY: RuntimeLibraryInstall.$1 164endef 165$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) 166 167# Hook into the standard Makefile rules. 168all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) 169install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) 170clean-local:: CleanRuntimeLibraries 171 172endif 173endif 174endif 175