blob: 580215acb62cbb12e9df7f54b5158a132eaa6db2 [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
Daniel Dunbar6e45cbc2010-04-28 23:36:26 +000029ifndef CLANG_NO_RUNTIME
Daniel Dunbar253521b2010-01-19 21:12:58 +000030ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK)
31
32# Select the compiler-rt configuration to use, and install directory.
33#
34# FIXME: Eventually, we want some kind of configure support for this. We want to
35# build/install runtime libraries for as many targets as clang was configured to
36# support.
37RuntimeDirs :=
38ifeq ($(OS),Darwin)
39RuntimeDirs += darwin
Daniel Dunbarc0e8f132010-03-26 19:37:38 +000040RuntimeLibrary.darwin.Configs = 10.4 armv6 cc_kext
Daniel Dunbar253521b2010-01-19 21:12:58 +000041endif
42
Daniel Dunbar253521b2010-01-19 21:12:58 +000043# Rule to build the compiler-rt libraries we need.
44#
45# We build all the libraries in a single shot to avoid recursive make as much as
46# possible.
47BuildRuntimeLibraries:
48 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
49 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
50 ProjObjRoot=$(PROJ_OBJ_DIR) \
51 $(RuntimeDirs:%=clang_%)
52.PHONY: BuildRuntimeLibraries
53CleanRuntimeLibraries:
54 $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
55 ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
56 ProjObjRoot=$(PROJ_OBJ_DIR) \
57 clean
58.PHONY: CleanRuntimeLibraries
59
60$(PROJ_resources_lib):
61 $(Verb) $(MKDIR) $@
62
63# Expand rules for copying/installing each individual library. We can't use
64# implicit rules here because we need to match against multiple things.
65define RuntimeLibraryTemplate
66$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
67 @true
68.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
69
70# Rule to copy the libraries to their resource directory location.
71$(ResourceLibDir)/$1/libclang_rt.%.a: \
72 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
73 $(ResourceLibDir)/$1/.dir
74 $(Echo) Copying runtime library $1/$$* to build dir
75 $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
76RuntimeLibrary.$1: \
77 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a)
78.PHONY: RuntimeLibrary.$1
79
80$(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
81 $(Verb) $(MKDIR) $$@
82
83$(PROJ_resources_lib)/$1/libclang_rt.%.a: \
84 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
85 $(Echo) Installing compiler runtime library: $1/$$*
86 $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
87
88# Rule to install runtime libraries.
89RuntimeLibraryInstall.$1: \
90 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a)
91.PHONY: RuntimeLibraryInstall.$1
92endef
93$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
94
95# Hook into the standard Makefile rules.
96all-local:: $(RuntimeDirs:%=RuntimeLibrary.%)
97install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%)
98clean-local:: CleanRuntimeLibraries
Daniel Dunbar46bbbdd2010-01-19 21:28:04 +000099
100endif
Daniel Dunbar6e45cbc2010-04-28 23:36:26 +0000101endif