]> granicus.if.org Git - clang/blob - runtime/Makefile
Runtime: Always build compiler-rt using the Clang we just built, instead of the
[clang] / runtime / Makefile
1 ##===- clang/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
16 CLANG_LEVEL := ..
17 include $(CLANG_LEVEL)/Makefile
18
19 CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \
20         $(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc))
21
22 ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
23 PROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION)
24
25 ResourceLibDir := $(ResourceDir)/lib
26 PROJ_resources_lib := $(PROJ_resources)/lib
27
28 # Expect compiler-rt to be in llvm/projects/compiler-rt
29 COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt
30
31 ifndef CLANG_NO_RUNTIME
32 ifeq ($(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.
39 RuntimeDirs :=
40 ifeq ($(OS),Darwin)
41 RuntimeDirs += darwin
42 RuntimeLibrary.darwin.Configs = 10.4 armv6 cc_kext
43 endif
44
45 # 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.
49 BuildRuntimeLibraries:
50         $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
51           ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
52           ProjObjRoot=$(PROJ_OBJ_DIR) \
53           CC="$(ToolDir)/clang -no-integrated-as" \
54           $(RuntimeDirs:%=clang_%)
55 .PHONY: BuildRuntimeLibraries
56 CleanRuntimeLibraries:
57         $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
58           ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
59           ProjObjRoot=$(PROJ_OBJ_DIR) \
60           clean
61 .PHONY: CleanRuntimeLibraries
62
63 $(PROJ_resources_lib):
64         $(Verb) $(MKDIR) $@
65
66 # Expand rules for copying/installing each individual library. We can't use
67 # implicit rules here because we need to match against multiple things.
68 define RuntimeLibraryTemplate
69 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
70         @true
71 .PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
72
73 # Rule to copy the libraries to their resource directory location.
74 $(ResourceLibDir)/$1/libclang_rt.%.a: \
75                 $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
76                 $(ResourceLibDir)/$1/.dir
77         $(Echo) Copying runtime library $1/$$* to build dir
78         $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
79 RuntimeLibrary.$1: \
80                 $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a)
81 .PHONY: RuntimeLibrary.$1
82
83 $(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
84         $(Verb) $(MKDIR) $$@
85
86 $(PROJ_resources_lib)/$1/libclang_rt.%.a: \
87                 $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
88         $(Echo) Installing compiler runtime library: $1/$$*
89         $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
90
91 # Rule to install runtime libraries.
92 RuntimeLibraryInstall.$1: \
93                 $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a)
94 .PHONY: RuntimeLibraryInstall.$1
95 endef
96 $(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
97
98 # Hook into the standard Makefile rules.
99 all-local:: $(RuntimeDirs:%=RuntimeLibrary.%)
100 install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%)
101 clean-local:: CleanRuntimeLibraries
102
103 endif
104 endif