blob: a8a64138903154371b4eec05b2f6401be2dc4f6b [file] [log] [blame]
Daniel Dunbar253521b2010-01-19 21:12:58 +00001##===- clang/lib/Runtime/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
16LEVEL = ../../../..
17include $(LEVEL)/Makefile.common
18
19CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER)
20ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
21PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION)
22
23ResourceLibDir := $(ResourceDir)/lib
24PROJ_resources_lib := $(PROJ_resources)/lib
25
26# Expect compiler-rt to be in llvm/projects/compiler-rt
27COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt
28
29ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK)
30
31# Select the compiler-rt configuration to use, and install directory.
32#
33# FIXME: Eventually, we want some kind of configure support for this. We want to
34# build/install runtime libraries for as many targets as clang was configured to
35# support.
36RuntimeDirs :=
37ifeq ($(OS),Darwin)
38RuntimeDirs += darwin
39RuntimeLibrary.darwin.Configs = x86_10.4 armv6
40endif
41
42endif
43
44# Rule to build the compiler-rt libraries we need.
45#
46# We build all the libraries in a single shot to avoid recursive make as much as
47# possible.
48BuildRuntimeLibraries:
49 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
50 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
51 ProjObjRoot=$(PROJ_OBJ_DIR) \
52 $(RuntimeDirs:%=clang_%)
53.PHONY: BuildRuntimeLibraries
54CleanRuntimeLibraries:
55 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
56 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
57 ProjObjRoot=$(PROJ_OBJ_DIR) \
58 clean
59.PHONY: CleanRuntimeLibraries
60
61$(PROJ_resources_lib):
62 $(Verb) $(MKDIR) $@
63
64# Expand rules for copying/installing each individual library. We can't use
65# implicit rules here because we need to match against multiple things.
66define RuntimeLibraryTemplate
67$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
68 @true
69.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
70
71# Rule to copy the libraries to their resource directory location.
72$(ResourceLibDir)/$1/libclang_rt.%.a: \
73 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
74 $(ResourceLibDir)/$1/.dir
75 $(Echo) Copying runtime library $1/$$* to build dir
76 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
77RuntimeLibrary.$1: \
78 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a)
79.PHONY: RuntimeLibrary.$1
80
81$(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
82 $(Verb) $(MKDIR) $$@
83
84$(PROJ_resources_lib)/$1/libclang_rt.%.a: \
85 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
86 $(Echo) Installing compiler runtime library: $1/$$*
87 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
88
89# Rule to install runtime libraries.
90RuntimeLibraryInstall.$1: \
91 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a)
92.PHONY: RuntimeLibraryInstall.$1
93endef
94$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
95
96# Hook into the standard Makefile rules.
97all-local:: $(RuntimeDirs:%=RuntimeLibrary.%)
98install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%)
99clean-local:: CleanRuntimeLibraries