Daniel Dunbar | ac141e6 | 2010-06-30 22:10:38 +0000 | [diff] [blame] | 1 | ##===- clang/runtime/Makefile ------------------------------*- Makefile -*-===## |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 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 Dunbar | ac141e6 | 2010-06-30 22:10:38 +0000 | [diff] [blame] | 16 | CLANG_LEVEL := .. |
Daniel Dunbar | afed099 | 2010-06-08 20:34:18 +0000 | [diff] [blame] | 17 | include $(CLANG_LEVEL)/Makefile |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 18 | |
Daniel Dunbar | bc817cf | 2010-06-25 17:33:49 +0000 | [diff] [blame] | 19 | CLANG_VERSION := $(word 3,$(shell grep "CLANG_VERSION " \ |
| 20 | $(PROJ_OBJ_DIR)/$(CLANG_LEVEL)/include/clang/Basic/Version.inc)) |
| 21 | |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | db0ab63 | 2011-02-11 01:29:49 +0000 | [diff] [blame] | 31 | # Additional flags to pass to Clang. |
| 32 | CLANG_CCFLAGS := -no-integrated-as |
| 33 | |
Daniel Dunbar | 880efcb | 2010-12-22 22:23:39 +0000 | [diff] [blame] | 34 | ifneq ($(CLANG_NO_RUNTIME),1) |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 35 | ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK) |
| 36 | |
| 37 | # Select the compiler-rt configuration to use, and install directory. |
| 38 | # |
| 39 | # FIXME: Eventually, we want some kind of configure support for this. We want to |
| 40 | # build/install runtime libraries for as many targets as clang was configured to |
| 41 | # support. |
| 42 | RuntimeDirs := |
| 43 | ifeq ($(OS),Darwin) |
| 44 | RuntimeDirs += darwin |
Daniel Dunbar | 885b1db | 2010-09-22 00:03:52 +0000 | [diff] [blame] | 45 | RuntimeLibrary.darwin.Configs = eprintf 10.4 armv6 cc_kext |
Daniel Dunbar | db0ab63 | 2011-02-11 01:29:49 +0000 | [diff] [blame] | 46 | |
| 47 | # On Darwin, fake Clang into using the iOS assembler (since compiler-rt wants to |
| 48 | # build ARM bits). |
| 49 | ifeq ($(OS),Darwin) |
| 50 | CLANG_CCFLAGS += -ccc-install-dir \ |
| 51 | /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ |
| 52 | endif |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 53 | endif |
| 54 | |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 55 | # Rule to build the compiler-rt libraries we need. |
| 56 | # |
| 57 | # We build all the libraries in a single shot to avoid recursive make as much as |
| 58 | # possible. |
| 59 | BuildRuntimeLibraries: |
| 60 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 61 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 62 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
Daniel Dunbar | db0ab63 | 2011-02-11 01:29:49 +0000 | [diff] [blame] | 63 | CC="$(ToolDir)/clang $(CLANG_CCFLAGS)" \ |
Daniel Dunbar | 253521b | 2010-01-19 21:12:58 +0000 | [diff] [blame] | 64 | $(RuntimeDirs:%=clang_%) |
| 65 | .PHONY: BuildRuntimeLibraries |
| 66 | CleanRuntimeLibraries: |
| 67 | $(Verb) $(MAKE) -C $(COMPILERRT_SRC_ROOT) \ |
| 68 | ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ |
| 69 | ProjObjRoot=$(PROJ_OBJ_DIR) \ |
| 70 | clean |
| 71 | .PHONY: CleanRuntimeLibraries |
| 72 | |
| 73 | $(PROJ_resources_lib): |
| 74 | $(Verb) $(MKDIR) $@ |
| 75 | |
| 76 | # Expand rules for copying/installing each individual library. We can't use |
| 77 | # implicit rules here because we need to match against multiple things. |
| 78 | define RuntimeLibraryTemplate |
| 79 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries |
| 80 | @true |
| 81 | .PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a |
| 82 | |
| 83 | # Rule to copy the libraries to their resource directory location. |
| 84 | $(ResourceLibDir)/$1/libclang_rt.%.a: \ |
| 85 | $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a \ |
| 86 | $(ResourceLibDir)/$1/.dir |
| 87 | $(Echo) Copying runtime library $1/$$* to build dir |
| 88 | $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ |
| 89 | RuntimeLibrary.$1: \ |
| 90 | $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a) |
| 91 | .PHONY: RuntimeLibrary.$1 |
| 92 | |
| 93 | $(PROJ_resources_lib)/$1: $(PROJ_resources_lib) |
| 94 | $(Verb) $(MKDIR) $$@ |
| 95 | |
| 96 | $(PROJ_resources_lib)/$1/libclang_rt.%.a: \ |
| 97 | $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 |
| 98 | $(Echo) Installing compiler runtime library: $1/$$* |
| 99 | $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 |
| 100 | |
| 101 | # Rule to install runtime libraries. |
| 102 | RuntimeLibraryInstall.$1: \ |
| 103 | $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a) |
| 104 | .PHONY: RuntimeLibraryInstall.$1 |
| 105 | endef |
| 106 | $(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) |
| 107 | |
| 108 | # Hook into the standard Makefile rules. |
| 109 | all-local:: $(RuntimeDirs:%=RuntimeLibrary.%) |
| 110 | install-local:: $(RuntimeDirs:%=RuntimeLibraryInstall.%) |
| 111 | clean-local:: CleanRuntimeLibraries |
Daniel Dunbar | 46bbbdd | 2010-01-19 21:28:04 +0000 | [diff] [blame] | 112 | |
| 113 | endif |
Daniel Dunbar | 6e45cbc | 2010-04-28 23:36:26 +0000 | [diff] [blame] | 114 | endif |