blob: 9a3c34719cfb755217652adb2cec8c0706f3cae2 [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
Daniel Dunbarc0e8f132010-03-26 19:37:38 +000039RuntimeLibrary.darwin.Configs = 10.4 armv6 cc_kext
Daniel Dunbar253521b2010-01-19 21:12:58 +000040endif
41
Daniel Dunbar253521b2010-01-19 21:12:58 +000042# Rule to build the compiler-rt libraries we need.
43#
44# We build all the libraries in a single shot to avoid recursive make as much as
45# possible.
46BuildRuntimeLibraries:
47 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
48 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
49 ProjObjRoot=$(PROJ_OBJ_DIR) \
50 $(RuntimeDirs:%=clang_%)
51.PHONY: BuildRuntimeLibraries
52CleanRuntimeLibraries:
53 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
54 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
55 ProjObjRoot=$(PROJ_OBJ_DIR) \
56 clean
57.PHONY: CleanRuntimeLibraries
58
59$(PROJ_resources_lib):
60 $(Verb) $(MKDIR) $@
61
62# Expand rules for copying/installing each individual library. We can't use
63# implicit rules here because we need to match against multiple things.
64define RuntimeLibraryTemplate
65$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
66 @true
67.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
68
69# Rule to copy the libraries to their resource directory location.
70$(ResourceLibDir)/$1/libclang_rt.%.a: \
71 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
72 $(ResourceLibDir)/$1/.dir
73 $(Echo) Copying runtime library $1/$$* to build dir
74 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
75RuntimeLibrary.$1: \
76 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a)
77.PHONY: RuntimeLibrary.$1
78
79$(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
80 $(Verb) $(MKDIR) $$@
81
82$(PROJ_resources_lib)/$1/libclang_rt.%.a: \
83 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
84 $(Echo) Installing compiler runtime library: $1/$$*
85 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
86
87# Rule to install runtime libraries.
88RuntimeLibraryInstall.$1: \
89 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a)
90.PHONY: RuntimeLibraryInstall.$1
91endef
92$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
93
94# Hook into the standard Makefile rules.
95all-local:: $(RuntimeDirs:%=RuntimeLibrary.%)
96install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%)
97clean-local:: CleanRuntimeLibraries
Daniel Dunbar46bbbdd2010-01-19 21:28:04 +000098
99endif