Makefile revision 6bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89
1da79da2a8748e4d58eeedd1b7f39bf4fb8a86d10Bob Wilson##===- clang/runtime/compiler-rt/Makefile ------------------*- Makefile -*-===##
2562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
3253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar#                     The LLVM Compiler Infrastructure
4253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar#
5253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar# This file is distributed under the University of Illinois Open Source
6253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar# License. See LICENSE.TXT for details.
7562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
8562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson##===----------------------------------------------------------------------===##
9562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
10562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# This file defines support for building the Clang runtime libraries (which are
11562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# implemented by compiler-rt) and placing them in the proper locations in the
12562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Clang resources directory (i.e., where the driver expects them).
13562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
14253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar##===----------------------------------------------------------------------===##
15253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar
16484fc57c8d2d3ba645a03f9e294dcebc5aacaf44Nick LewyckyCLANG_LEVEL := ../..
17562627d782393c0d8045625a53a97f4fbad091bcOwen Andersoninclude $(CLANG_LEVEL)/Makefile
18253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar
19562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonCLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \
20562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc))
21bc817cffbca01c879f13e9290d94797f6caafc7aDaniel Dunbar
22562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
23562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonPROJ_resources := $(DESTDIR)$(PROJ_prefix)/lib/clang/$(CLANG_VERSION)
24562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
25562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonResourceLibDir := $(ResourceDir)/lib
260e7a1cf16c361cd247e31472c253663f6ae32febAlexander PotapenkoResourceIncludeDir := $(ResourceDir)/include
27562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonPROJ_resources_lib := $(PROJ_resources)/lib
280e7a1cf16c361cd247e31472c253663f6ae32febAlexander PotapenkoPROJ_resources_include := $(PROJ_resources)/include
29562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
308ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# Initialize a variable to use for extra flags to pass to the
318ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# compiler-rt make process.
328ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel DunbarCOMPILERRT_MAKE_FLAGS :=
338ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar
34562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Expect compiler-rt to be in llvm/projects/compiler-rt
35562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonCOMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT)/projects/compiler-rt
36562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
37e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# We don't currently support building runtime libraries when we are
38e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# cross-compiling. The issue is that we really want to be set up so that the
39e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# available compiler targets are independent of the current build.
40e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#
41e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# Since we have to build the runtime libraries for the target, it requires we
42e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# have a cross compiler from the build machine to the target. Although in the
43e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# case where for the current build (host == target), we do have such a cross
44e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# compiler, but not defined in a way that is easy for us to reuse. Regardless,
45e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# that also wouldn't help for other possible compiler configurations.
46e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#
47e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# Thus, the simple set up we currently use is to assume that we will be using
48e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# the just built Clang to compile the compiler-rt libraries. As we grow better
49e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# cross compilation support inside Clang and tool support in LLVM, this makes it
50e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# easier for us to achieve the goal of having the compiler targets be easily
51e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# selected at configure time. However, this design does currently preclude the
52e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# building of compiler-rt libraries when the Clang itself is being cross
53e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# compiled.
54e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#
55e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# There are three possible solutions:
56e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#  1. Require building a build-target version of Clang when cross compiling. This
57e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     is simplest, but als greatly increases the build time of cross builds.
58e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#
59e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#  2. Require cross builds have a build-target version of Clang available for
60e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     use. This is a reasonable compromise on #1, as the compiler-rt libraries
61e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     are simple enough that there is not a strong desire to ensure they are
62e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     built with the exact version of Clang being used. Similarly, as Clang
63e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     becomes a better cross compiler it is also increasingly more likely that
64e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     the cross compiler being used will already be a version of Clang.
65e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#
66e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#  3. Come up with an alternate mechanism to define all the toolchain
67e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     information that compiler-rt would need to build libraries for all the
68e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar#     requested targets. This might be a simple short term solution, but is
69651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#     likely to be unwieldy and irritating to maintain in the long term.
70e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbarifneq ($(LLVM_CROSS_COMPILING),1)
71562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonifneq ($(CLANG_NO_RUNTIME),1)
72562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK)
73562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
74562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Select the compiler-rt configuration to use, and install directory.
75562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
76562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# FIXME: Eventually, we want some kind of configure support for this. We want to
77562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# build/install runtime libraries for as many targets as clang was configured to
78562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# support.
79562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonRuntimeDirs :=
80562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonifeq ($(OS),Darwin)
81651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesRuntimeDirs += darwin macho_embedded
82f471487ff1e673531543576bc170898c2ab19f41Daniel DunbarRuntimeLibrary.darwin.Configs := \
837a0c064770355a4918df69f95de8dea6338a59a2Daniel Dunbar	eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \
84f8d4a6b80d3e0f19c9735fbe0be7bf5f8b21ec18Alexey Samsonov	asan_osx_dynamic.dylib \
8575fcb193aeeec5c4f10cc39df60a5ce7526b1b28Alexey Samsonov	profile_osx.a profile_ios.a \
8675fcb193aeeec5c4f10cc39df60a5ce7526b1b28Alexey Samsonov	ubsan_osx.a
87651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
88651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesRuntimeLibrary.macho_embedded.Configs := \
89651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines	hard_static.a hard_pic.a
90651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesifneq (,$(findstring ARM,$(TARGETS_TO_BUILD)))
91651f13cea278ec967336033dd032faef0e9fc2ecStephen HinesRuntimeLibrary.macho_embedded.Configs += \
92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines	soft_static.a soft_pic.a
93651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesendif
948ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar
958ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# Support building compiler-rt with relocatable SDKs.
968ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar#
978ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# This will cause make to put SDKROOT in the environment, and since we
988ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# are using the built Clang to build compiler-rt, it to pick up that
998ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar# location as the default value for the include system root.
1008ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel DunbarACTIVE_SDK_PATH := $(shell xcrun --show-sdk-path 2> /dev/null)
1018ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbarifneq ($(ACTIVE_SDK_PATH),)
1028ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel DunbarCOMPILERRT_MAKE_FLAGS := SDKROOT=$(ACTIVE_SDK_PATH)
1038ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbarendif
10471940883821bd55028f4c2773de10a532c1d8aeaAlexander PotapenkoIOSSIM_SDK_PATH := $(shell xcrun --show-sdk-path -sdk iphonesimulator 2> /dev/null)
10571940883821bd55028f4c2773de10a532c1d8aeaAlexander Potapenkoifneq ($(IOSSIM_SDK_PATH),)
10671940883821bd55028f4c2773de10a532c1d8aeaAlexander PotapenkoRuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib
10771940883821bd55028f4c2773de10a532c1d8aeaAlexander Potapenkoendif
1088ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar
109562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonendif
110ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbar
111ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbar# On Linux, include a library which has all the runtime functions.
112ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbarifeq ($(OS),Linux)
113ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel DunbarRuntimeDirs += linux
114ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel DunbarRuntimeLibrary.linux.Configs :=
115ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbar
116f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov# TryCompile compiler source flags
117f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov# Returns exit code of running a compiler invocation.
118f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey SamsonovTryCompile = \
119f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov  $(shell \
120f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov    cflags=""; \
121f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov    for flag in $(3); do \
122f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov      cflags="$$cflags $$flag"; \
123f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov    done; \
124f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov    $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \
125f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov    echo $$?)
126f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov
127230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler Carruth# We try to build 32-bit runtimes both on 32-bit hosts and 64-bit hosts.
128230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler CarruthRuntime32BitConfigs = \
1296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	builtins-i386.a profile-i386.a san-i386.a asan-i386.a asan_cxx-i386.a \
1306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	ubsan-i386.a ubsan_cxx-i386.a
131230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler Carruth
132230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler Carruth# We currently only try to generate runtime libraries on x86.
133230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler Carruthifeq ($(ARCH),x86)
134230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler CarruthRuntimeLibrary.linux.Configs += $(Runtime32BitConfigs)
135ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbarendif
136f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov
137ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbarifeq ($(ARCH),x86_64)
1387df67e6892d74a6653473089473166a30608f416Daniel DunbarRuntimeLibrary.linux.Configs += \
1396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	builtins-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \
1406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	asan_cxx-x86_64.a tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a \
1416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	ubsan_cxx-x86_64.a dfsan-x86_64.a lsan-x86_64.a
142e0d80f1852bff0bcf8f71b73773cdff71bc94f33Alexey Samsonov# We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and add them
143e0d80f1852bff0bcf8f71b73773cdff71bc94f33Alexey Samsonov# to the list of runtime libraries to make
144e0d80f1852bff0bcf8f71b73773cdff71bc94f33Alexey Samsonov# "clang -fsanitize=(address|undefined) -m32" work.
145f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov# We check that Clang can produce working 32-bit binaries by compiling a simple
146f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonov# executable.
147f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonovtest_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c
148f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonovifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0)
149230cdaaab58a2cc00012c5766e396a3eba2aa940Chandler CarruthRuntimeLibrary.linux.Configs += $(Runtime32BitConfigs)
150ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbarendif
15119baf068e8d113a242694003ba04508282804e8eEvgeniy Stepanovifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)
15219baf068e8d113a242694003ba04508282804e8eEvgeniy StepanovRuntimeLibrary.linux.Configs += asan-arm-android.so
15319baf068e8d113a242694003ba04508282804e8eEvgeniy Stepanovendif
154f288d223a44fb2fa0de69b225dcdbc5f7669defdAlexey Samsonovendif
155ff9865220ccd618cab2d8fbc63e58ac6cd7357f0Daniel Dunbar
156db0ab63998eb9aad0ead03d3f76f095f9b1eb036Daniel Dunbarendif
157253521bacfc70dcc8f8205f8b1192816458beb34Daniel Dunbar
158e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar####
159e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# The build rules below are designed to be generic and should only need to be
160e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar# modified based on changes in the compiler-rt layout or build system.
161e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar####
162e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbar
163562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Rule to build the compiler-rt libraries we need.
164562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson#
165562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# We build all the libraries in a single shot to avoid recursive make as much as
166562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# possible.
167562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonBuildRuntimeLibraries:
168562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
169562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
170562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  ProjObjRoot=$(PROJ_OBJ_DIR) \
1713518058dace8f4c9c3ed0b6a30b0bdf08a10d559Daniel Dunbar	  CC="$(ToolDir)/clang" \
1726bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	  VERBOSE=$(VERBOSE) \
17319baf068e8d113a242694003ba04508282804e8eEvgeniy Stepanov	  LLVM_ANDROID_TOOLCHAIN_DIR="$(LLVM_ANDROID_TOOLCHAIN_DIR)" \
1748ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar	  $(COMPILERRT_MAKE_FLAGS) \
175562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  $(RuntimeDirs:%=clang_%)
176562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson.PHONY: BuildRuntimeLibraries
177562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonCleanRuntimeLibraries:
178562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \
179562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \
180562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  ProjObjRoot=$(PROJ_OBJ_DIR) \
1816bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines	  VERBOSE=$(VERBOSE) \
1828ad46b79c3d39e1c7a1494c060e41234711b7d18Daniel Dunbar	  $(COMPILERRT_MAKE_FLAGS) \
183562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	  clean
184562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson.PHONY: CleanRuntimeLibraries
1850e7a1cf16c361cd247e31472c253663f6ae32febAlexander PotapenkoRuntimeHeader: $(ResourceIncludeDir)/sanitizer
186562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
187562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(PROJ_resources_lib):
188562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) $(MKDIR) $@
189562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
1900e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko$(ResourceIncludeDir):
1910e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) $(MKDIR) $@
1920e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko
1930e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko$(ResourceIncludeDir)/sanitizer: $(ResourceIncludeDir)
1940e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) $(MKDIR) $@
1950e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) cp $(COMPILERRT_SRC_ROOT)/include/sanitizer/*.h $@
1960e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko
197562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Expand rules for copying/installing each individual library. We can't use
198562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# implicit rules here because we need to match against multiple things.
199562627d782393c0d8045625a53a97f4fbad091bcOwen Andersondefine RuntimeLibraryTemplate
200562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries
201562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	@true
20212f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries
20312f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	@true
20412f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries
20512f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	@true
206562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson.PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a
207562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
208562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Rule to copy the libraries to their resource directory location.
209562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(ResourceLibDir)/$1/libclang_rt.%.a: \
210562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson		$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \
211562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson		$(ResourceLibDir)/$1/.dir
212562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Echo) Copying runtime library $1/$$* to build dir
213562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@
21412f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(ResourceLibDir)/$1/libclang_rt.%.so: \
21512f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \
21612f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(ResourceLibDir)/$1/.dir
21712f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Echo) Copying runtime library $1/$$* to build dir
21812f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@
21912f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(ResourceLibDir)/$1/libclang_rt.%.dylib: \
22012f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \
22112f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(ResourceLibDir)/$1/.dir
22212f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Echo) Copying runtime library $1/$$* to build dir
22312f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@
224b626280eb16a62e32a100f0082e9ea7e496a51d7Alexander Potapenko	$(Echo) Fixing LC_ID_DYLIB of $$@
225b626280eb16a62e32a100f0082e9ea7e496a51d7Alexander Potapenko	$(Verb) install_name_tool $$@ -id $$@
226562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonRuntimeLibrary.$1: \
22712f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%)
228562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson.PHONY: RuntimeLibrary.$1
22946bbbdd0111c386c2341919a62c5742f2519efa6Daniel Dunbar
230562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(PROJ_resources_lib)/$1: $(PROJ_resources_lib)
231562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) $(MKDIR) $$@
232562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
233562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(PROJ_resources_lib)/$1/libclang_rt.%.a: \
234562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson		$(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1
235562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Echo) Installing compiler runtime library: $1/$$*
236562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson	$(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
23712f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(PROJ_resources_lib)/$1/libclang_rt.%.so: \
23812f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1
23912f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Echo) Installing compiler runtime library: $1/$$*
24012f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
24112f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar$(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \
24212f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1
24312f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Echo) Installing compiler runtime library: $1/$$*
24412f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar	$(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1
245562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
246562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Rule to install runtime libraries.
247562627d782393c0d8045625a53a97f4fbad091bcOwen AndersonRuntimeLibraryInstall.$1: \
24812f5fe5f4ee9318a11e299f199f61eea05a2a450Daniel Dunbar		$(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%)
249562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson.PHONY: RuntimeLibraryInstall.$1
250562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonendef
251562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
252562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
2530e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko$(PROJ_resources_include):
2540e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) $(MKDIR) $@
2550e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko
2560e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko$(PROJ_resources_include)/sanitizer: $(ResourceIncludeDir)/sanitizer $(PROJ_resources_include)
2570e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) $(MKDIR) $@
2580e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Echo) Installing compiler runtime headers
2590e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko	$(Verb) $(DataInstall) $(ResourceIncludeDir)/sanitizer/* \
2600e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko                               $(PROJ_resources_include)/sanitizer
2610e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko
2620e7a1cf16c361cd247e31472c253663f6ae32febAlexander PotapenkoRuntimeHeaderInstall: $(PROJ_resources_include)/sanitizer
2630e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko.PHONY: RuntimeHeaderInstall
2640e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenko
265562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson# Hook into the standard Makefile rules.
2660e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenkoall-local:: $(RuntimeDirs:%=RuntimeLibrary.%) RuntimeHeader
2670e7a1cf16c361cd247e31472c253663f6ae32febAlexander Potapenkoinstall-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) RuntimeHeaderInstall
268562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonclean-local:: CleanRuntimeLibraries
269562627d782393c0d8045625a53a97f4fbad091bcOwen Anderson
270562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonendif
271562627d782393c0d8045625a53a97f4fbad091bcOwen Andersonendif
272e33218a3ceb3a36e4d8163cf04df0c0cae530b27Daniel Dunbarendif
273