]> git.proxmox.com Git - rustc.git/blob - mk/llvm.mk
New upstream version 1.14.0+dfsg1
[rustc.git] / mk / llvm.mk
1 # Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11
12 ifdef CFG_ENABLE_FAST_MAKE
13 LLVM_DEPS := $(S)/.gitmodules
14 else
15
16 # This is just a rough approximation of LLVM deps
17 LLVM_DEPS_SRC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)lib,*cpp *hpp)
18 LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)include,*cpp *hpp)
19 LLVM_DEPS=$(LLVM_DEPS_SRC) $(LLVM_DEPS_INC)
20 endif
21
22 ifdef CFG_DISABLE_OPTIMIZE_LLVM
23 LLVM_BUILD_CONFIG_MODE := Debug
24 else
25 LLVM_BUILD_CONFIG_MODE := Release
26 endif
27
28 define DEF_LLVM_RULES
29
30 ifeq ($(1),$$(CFG_BUILD))
31 LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS)
32 else
33 LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD))
34 endif
35
36 # If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
37 ifeq ($(CFG_LLVM_ROOT),)
38
39 LLVM_STAMP_$(1) = $(S)src/rustllvm/llvm-auto-clean-trigger
40 LLVM_DONE_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-finished-building
41
42 $$(LLVM_CONFIG_$(1)): $$(LLVM_DONE_$(1))
43
44 ifneq ($$(CFG_NINJA),)
45 BUILD_LLVM_$(1) := $$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1))
46 else ifeq ($$(findstring msvc,$(1)),msvc)
47 BUILD_LLVM_$(1) := $$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
48 --config $$(LLVM_BUILD_CONFIG_MODE)
49 else
50 BUILD_LLVM_$(1) := $$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1))
51 endif
52
53 $$(LLVM_DONE_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
54 @$$(call E, cmake: llvm)
55 $$(Q)if ! cmp $$(LLVM_STAMP_$(1)) $$(LLVM_DONE_$(1)); then \
56 $$(MAKE) clean-llvm$(1); \
57 $$(BUILD_LLVM_$(1)); \
58 fi
59 $$(Q)cp $$(LLVM_STAMP_$(1)) $$@
60
61 ifneq ($$(CFG_NINJA),)
62 clean-llvm$(1):
63 @$$(call E, clean: llvm)
64 $$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1)) -t clean
65 else ifeq ($$(findstring msvc,$(1)),msvc)
66 clean-llvm$(1):
67 @$$(call E, clean: llvm)
68 $$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
69 --config $$(LLVM_BUILD_CONFIG_MODE) \
70 --target clean
71 else
72 clean-llvm$(1):
73 @$$(call E, clean: llvm)
74 $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
75 endif
76
77 else
78 clean-llvm$(1):
79 endif
80
81 $$(LLVM_AR_$(1)): $$(LLVM_CONFIG_$(1))
82
83 ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
84 LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
85 -print-file-name=lib$(CFG_STDCPP_NAME).a))"
86 else
87 LLVM_STDCPP_RUSTFLAGS_$(1) =
88 endif
89
90
91 # LLVM linkage:
92 # Note: Filter with llvm-config so that optional targets which aren't present
93 # don't cause errors (ie PNaCl's target is only present within PNaCl's LLVM
94 # fork).
95 LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
96 $$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
97 $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(filter $$(shell \
98 $$(LLVM_CONFIG_$(1)) --components), \
99 $(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)" \
100 "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" $$(LLVM_CONFIG_$(1)) \
101 "$(CFG_STDCPP_NAME)" "$$(CFG_USING_LIBCPP)"
102 endef
103
104 $(foreach host,$(CFG_HOST), \
105 $(eval $(call DEF_LLVM_RULES,$(host))))
106
107 $(foreach host,$(CFG_HOST), \
108 $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
109
110 # This can't be done in target.mk because it's included before this file.
111 define LLVM_LINKAGE_DEPS
112 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
113 RUSTFLAGS$(1)_rustc_llvm_T_$(2) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(2)) | tr '-' '_' |\
114 sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg "llvm_component=\\"\1\\""/g')
115 endef
116
117 $(foreach source,$(CFG_HOST), \
118 $(foreach target,$(CFG_TARGET), \
119 $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
120 $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
121 $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
122 $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))