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