]> git.lizzy.rs Git - rust.git/blob - mk/llvm.mk
Rollup merge of #38299 - achanda:ctrl-c, r=brson
[rust.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 ifdef CFG_ENABLE_LLVM_RELEASE_DEBUGINFO
25 LLVM_BUILD_CONFIG_MODE := RelWithDebInfo
26 else
27 LLVM_BUILD_CONFIG_MODE := Release
28 endif
29
30 define DEF_LLVM_RULES
31
32 ifeq ($(1),$$(CFG_BUILD))
33 LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS)
34 else
35 LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD))
36 endif
37
38 # If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
39 ifeq ($(CFG_LLVM_ROOT),)
40
41 LLVM_STAMP_$(1) = $(S)src/rustllvm/llvm-auto-clean-trigger
42 LLVM_DONE_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-finished-building
43
44 $$(LLVM_CONFIG_$(1)): $$(LLVM_DONE_$(1))
45
46 ifneq ($$(CFG_NINJA),)
47 BUILD_LLVM_$(1) := $$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1))
48 else ifeq ($$(findstring msvc,$(1)),msvc)
49 BUILD_LLVM_$(1) := $$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
50                         --config $$(LLVM_BUILD_CONFIG_MODE)
51 else
52 BUILD_LLVM_$(1) := $$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1))
53 endif
54
55 $$(LLVM_DONE_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
56         @$$(call E, cmake: llvm)
57         $$(Q)if ! cmp $$(LLVM_STAMP_$(1)) $$(LLVM_DONE_$(1)); then \
58                 $$(MAKE) clean-llvm$(1); \
59                 $$(BUILD_LLVM_$(1)); \
60         fi
61         $$(Q)cp $$(LLVM_STAMP_$(1)) $$@
62
63 ifneq ($$(CFG_NINJA),)
64 clean-llvm$(1):
65         @$$(call E, clean: llvm)
66         $$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1)) -t clean
67 else ifeq ($$(findstring msvc,$(1)),msvc)
68 clean-llvm$(1):
69         @$$(call E, clean: llvm)
70         $$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
71                 --config $$(LLVM_BUILD_CONFIG_MODE) \
72                 --target clean
73 else
74 clean-llvm$(1):
75         @$$(call E, clean: llvm)
76         $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
77 endif
78
79 else
80 clean-llvm$(1):
81 endif
82
83 $$(LLVM_AR_$(1)): $$(LLVM_CONFIG_$(1))
84
85 ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
86 LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
87                                         -print-file-name=lib$(CFG_STDCPP_NAME).a))"
88 else
89 LLVM_STDCPP_RUSTFLAGS_$(1) =
90 endif
91
92
93 # LLVM linkage:
94 # Note: Filter with llvm-config so that optional targets which aren't present
95 # don't cause errors (ie PNaCl's target is only present within PNaCl's LLVM
96 # fork).
97 LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
98 $$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
99         $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(filter $$(shell \
100                                 $$(LLVM_CONFIG_$(1)) --components), \
101                         $(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)" \
102                 "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" $$(LLVM_CONFIG_$(1)) \
103                 "$(CFG_STDCPP_NAME)" "$$(CFG_USING_LIBCPP)"
104 endef
105
106 $(foreach host,$(CFG_HOST), \
107  $(eval $(call DEF_LLVM_RULES,$(host))))
108
109 $(foreach host,$(CFG_HOST), \
110  $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
111
112 # This can't be done in target.mk because it's included before this file.
113 define LLVM_LINKAGE_DEPS
114 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
115 RUSTFLAGS$(1)_rustc_llvm_T_$(2) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(2)) | tr '-' '_' |\
116         sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg "llvm_component=\\"\1\\""/g')
117 endef
118
119 $(foreach source,$(CFG_HOST), \
120  $(foreach target,$(CFG_TARGET), \
121   $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
122   $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
123   $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
124   $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))