]> git.lizzy.rs Git - rust.git/blob - mk/llvm.mk
Rollup merge of #34972 - oli-obk:cant_cast_str_to_const_ptr, r=eddyb
[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
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) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-auto-clean-stamp
40 LLVM_DONE_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-finished-building
41
42 $$(LLVM_CONFIG_$(1)): $$(LLVM_DONE_$(1))
43
44 $$(LLVM_DONE_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
45         @$$(call E, cmake: llvm)
46 ifneq ($$(CFG_NINJA),)
47         $$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1))
48 else ifeq ($$(findstring msvc,$(1)),msvc)
49         $$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
50                 --config $$(LLVM_BUILD_CONFIG_MODE)
51 else
52         $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1))
53 endif
54         $$(Q)touch $$@
55
56 ifneq ($$(CFG_NINJA),)
57 clean-llvm$(1):
58         @$$(call E, clean: llvm)
59         $$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1)) -t clean
60 else ifeq ($$(findstring msvc,$(1)),msvc)
61 clean-llvm$(1):
62         @$$(call E, clean: llvm)
63         $$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
64                 --config $$(LLVM_BUILD_CONFIG_MODE) \
65                 --target clean
66 else
67 clean-llvm$(1):
68         @$$(call E, clean: llvm)
69         $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
70 endif
71
72 else
73 clean-llvm$(1):
74 endif
75
76 $$(LLVM_AR_$(1)): $$(LLVM_CONFIG_$(1))
77
78 # This is used to independently force an LLVM clean rebuild
79 # when we changed something not otherwise captured by builtin
80 # dependencies. In these cases, commit a change that touches
81 # the stamp in the source dir.
82 $$(LLVM_STAMP_$(1)): $$(S)src/rustllvm/llvm-auto-clean-trigger
83         @$$(call E, make: cleaning llvm)
84         $$(Q)touch $$@.start_time
85         $$(Q)$$(MAKE) clean-llvm$(1)
86         @$$(call E, make: done cleaning llvm)
87         touch -r $$@.start_time $$@ && rm $$@.start_time
88
89 ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
90 LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
91                                         -print-file-name=lib$(CFG_STDCPP_NAME).a))"
92 else
93 LLVM_STDCPP_RUSTFLAGS_$(1) =
94 endif
95
96
97 # LLVM linkage:
98 # Note: Filter with llvm-config so that optional targets which aren't present
99 # don't cause errors (ie PNaCl's target is only present within PNaCl's LLVM
100 # fork).
101 LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
102 $$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
103         $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(filter $$(shell \
104                                 $$(LLVM_CONFIG_$(1)) --components), \
105                         $(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)" \
106                 "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" $$(LLVM_CONFIG_$(1)) \
107                 "$(CFG_STDCPP_NAME)" "$$(CFG_USING_LIBCPP)"
108 endef
109
110 $(foreach host,$(CFG_HOST), \
111  $(eval $(call DEF_LLVM_RULES,$(host))))
112
113 $(foreach host,$(CFG_HOST), \
114  $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
115
116 # This can't be done in target.mk because it's included before this file.
117 define LLVM_LINKAGE_DEPS
118 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
119 RUSTFLAGS$(1)_rustc_llvm_T_$(2) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(2)) | tr '-' '_' |\
120         sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg "llvm_component=\\"\1\\""/g')
121 endef
122
123 $(foreach source,$(CFG_HOST), \
124  $(foreach target,$(CFG_TARGET), \
125   $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
126   $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
127   $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
128   $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))