blob: c1dcd6489450129753f64b9f545afd9be221d215 [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
Daniel Dunbare33218a2011-11-16 23:22:07 +000031# 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.
64ifneq ($(LLVM_CROSS_COMPILING),1)
Owen Anderson562627d2011-04-15 17:35:58 +000065ifneq ($(CLANG_NO_RUNTIME),1)
66ifeq ($(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.
73RuntimeDirs :=
74ifeq ($(OS),Darwin)
75RuntimeDirs += darwin
Daniel Dunbarf4714872011-11-17 00:36:57 +000076RuntimeLibrary.darwin.Configs := \
Daniel Dunbar12f5fe52012-09-14 21:30:17 +000077 eprintf.a 10.4.a osx.a cc_kext.a \
78 asan_osx.a asan_osx_dynamic.dylib \
79 profile_osx.a
Owen Anderson562627d2011-04-15 17:35:58 +000080endif
Daniel Dunbarff986522011-12-02 02:31:32 +000081
82# On Linux, include a library which has all the runtime functions.
83ifeq ($(OS),Linux)
84RuntimeDirs += linux
85RuntimeLibrary.linux.Configs :=
86
87# We currently only try to generate runtime libraries on x86.
88ifeq ($(ARCH),x86)
Daniel Dunbar7df67e62011-12-07 19:35:10 +000089RuntimeLibrary.linux.Configs += \
Daniel Dunbar12f5fe52012-09-14 21:30:17 +000090 full-i386.a profile-i386.a asan-i386.a
Daniel Dunbarff986522011-12-02 02:31:32 +000091endif
92ifeq ($(ARCH),x86_64)
Daniel Dunbar7df67e62011-12-07 19:35:10 +000093RuntimeLibrary.linux.Configs += \
Daniel Dunbar12f5fe52012-09-14 21:30:17 +000094 full-x86_64.a profile-x86_64.a asan-x86_64.a tsan-x86_64.a
Daniel Dunbarff986522011-12-02 02:31:32 +000095endif
96
Owen Anderson562627d2011-04-15 17:35:58 +000097endif
98
Daniel Dunbare33218a2011-11-16 23:22:07 +000099####
100# The build rules below are designed to be generic and should only need to be
101# modified based on changes in the compiler-rt layout or build system.
102####
103
Owen Anderson562627d2011-04-15 17:35:58 +0000104# Rule to build the compiler-rt libraries we need.
105#
106# We build all the libraries in a single shot to avoid recursive make as much as
107# possible.
108BuildRuntimeLibraries:
109 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
110 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
111 ProjObjRoot=$(PROJ_OBJ_DIR) \
Daniel Dunbar35180582012-03-05 20:19:03 +0000112 CC="$(ToolDir)/clang" \
Owen Anderson562627d2011-04-15 17:35:58 +0000113 $(RuntimeDirs:%=clang_%)
114.PHONY: BuildRuntimeLibraries
115CleanRuntimeLibraries:
116 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
117 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
118 ProjObjRoot=$(PROJ_OBJ_DIR) \
119 clean
120.PHONY: CleanRuntimeLibraries
121
122$(PROJ_resources_lib):
123 $(Verb) $(MKDIR) $@
124
125# Expand rules for copying/installing each individual library. We can't use
126# implicit rules here because we need to match against multiple things.
127define RuntimeLibraryTemplate
128$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
129 @true
Daniel Dunbar12f5fe52012-09-14 21:30:17 +0000130$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries
131 @true
132$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries
133 @true
Owen Anderson562627d2011-04-15 17:35:58 +0000134.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
135
136# Rule to copy the libraries to their resource directory location.
137$(ResourceLibDir)/$1/libclang_rt.%.a: \
138 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
139 $(ResourceLibDir)/$1/.dir
140 $(Echo) Copying runtime library $1/$$* to build dir
141 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
Daniel Dunbar12f5fe52012-09-14 21:30:17 +0000142$(ResourceLibDir)/$1/libclang_rt.%.so: \
143 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \
144 $(ResourceLibDir)/$1/.dir
145 $(Echo) Copying runtime library $1/$$* to build dir
146 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@
147$(ResourceLibDir)/$1/libclang_rt.%.dylib: \
148 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \
149 $(ResourceLibDir)/$1/.dir
150 $(Echo) Copying runtime library $1/$$* to build dir
151 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@
Alexander Potapenkob6262802012-09-17 14:18:41 +0000152 $(Echo) Fixing LC_ID_DYLIB of $$@
153 $(Verb) install_name_tool $$@ -id $$@
Owen Anderson562627d2011-04-15 17:35:58 +0000154RuntimeLibrary.$1: \
Daniel Dunbar12f5fe52012-09-14 21:30:17 +0000155 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%)
Owen Anderson562627d2011-04-15 17:35:58 +0000156.PHONY: RuntimeLibrary.$1
157
158$(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
159 $(Verb) $(MKDIR) $$@
160
161$(PROJ_resources_lib)/$1/libclang_rt.%.a: \
162 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
163 $(Echo) Installing compiler runtime library: $1/$$*
164 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
Daniel Dunbar12f5fe52012-09-14 21:30:17 +0000165$(PROJ_resources_lib)/$1/libclang_rt.%.so: \
166 $(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1
167 $(Echo) Installing compiler runtime library: $1/$$*
168 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
169$(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \
170 $(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1
171 $(Echo) Installing compiler runtime library: $1/$$*
172 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
Owen Anderson562627d2011-04-15 17:35:58 +0000173
174# Rule to install runtime libraries.
175RuntimeLibraryInstall.$1: \
Daniel Dunbar12f5fe52012-09-14 21:30:17 +0000176 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%)
Owen Anderson562627d2011-04-15 17:35:58 +0000177.PHONY: RuntimeLibraryInstall.$1
178endef
179$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
180
181# Hook into the standard Makefile rules.
182all-local:: $(RuntimeDirs:%=RuntimeLibrary.%)
183install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%)
184clean-local:: CleanRuntimeLibraries
185
186endif
187endif
Daniel Dunbare33218a2011-11-16 23:22:07 +0000188endif