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