]> git.lizzy.rs Git - rust.git/blob - mk/llvm.mk
mk: Fix native LLVM deps for cross-host builds
[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 define DEF_LLVM_RULES
23
24 # If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
25 ifeq ($(CFG_LLVM_ROOT),)
26
27 LLVM_STAMP_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-auto-clean-stamp
28
29 $$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
30         @$$(call E, make: llvm)
31         $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) $$(CFG_LLVM_BUILD_ENV_$(1)) ONLY_TOOLS="$$(LLVM_TOOLS)"
32         $$(Q)touch $$(LLVM_CONFIG_$(1))
33 endif
34
35 # This is used to independently force an LLVM clean rebuild
36 # when we changed something not otherwise captured by builtin
37 # dependencies. In these cases, commit a change that touches
38 # the stamp in the source dir.
39 $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
40         @$$(call E, make: cleaning llvm)
41         $(Q)touch $$@.start_time
42         $(Q)$(MAKE) clean-llvm$(1)
43         @$$(call E, make: done cleaning llvm)
44         touch -r $$@.start_time $$@ && rm $$@.start_time
45
46 ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
47 LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
48                                         -print-file-name=libstdc++.a))"
49 else
50 LLVM_STDCPP_RUSTFLAGS_$(1) =
51 endif
52
53
54 # LLVM linkage:
55 LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
56 $$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
57         $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
58                 $$(LLVM_CONFIG_$(1))
59 endef
60
61 $(foreach host,$(CFG_HOST), \
62  $(eval $(call DEF_LLVM_RULES,$(host))))
63
64 $(foreach host,$(CFG_HOST), \
65  $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
66
67 # This can't be done in target.mk because it's included before this file.
68 define LLVM_LINKAGE_DEPS
69 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
70 endef
71
72 $(foreach source,$(CFG_HOST), \
73  $(foreach target,$(CFG_TARGET), \
74   $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
75   $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
76   $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
77   $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))