]> git.proxmox.com Git - rustc.git/blob - mk/llvm.mk
Imported Upstream version 1.2.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 # If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
31 ifeq ($(CFG_LLVM_ROOT),)
32
33 LLVM_STAMP_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-auto-clean-stamp
34
35 ifeq ($$(findstring msvc,$(1)),msvc)
36
37 $$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
38 @$$(call E, cmake: llvm)
39 $$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
40 --config $$(LLVM_BUILD_CONFIG_MODE)
41 $$(Q)touch $$(LLVM_CONFIG_$(1))
42
43 clean-llvm$(1):
44
45 else
46
47 $$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
48 @$$(call E, make: llvm)
49 $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) $$(CFG_LLVM_BUILD_ENV_$(1)) ONLY_TOOLS="$$(LLVM_TOOLS)"
50 $$(Q)touch $$(LLVM_CONFIG_$(1))
51
52 clean-llvm$(1):
53 $$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
54
55 endif
56
57 else
58 clean-llvm$(1):
59 endif
60
61 $$(LLVM_AR_$(1)): $$(LLVM_CONFIG_$(1))
62
63 # This is used to independently force an LLVM clean rebuild
64 # when we changed something not otherwise captured by builtin
65 # dependencies. In these cases, commit a change that touches
66 # the stamp in the source dir.
67 $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
68 @$$(call E, make: cleaning llvm)
69 $(Q)touch $$@.start_time
70 $(Q)$(MAKE) clean-llvm$(1)
71 @$$(call E, make: done cleaning llvm)
72 touch -r $$@.start_time $$@ && rm $$@.start_time
73
74 ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
75 LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
76 -print-file-name=libstdc++.a))"
77 else
78 LLVM_STDCPP_RUSTFLAGS_$(1) =
79 endif
80
81
82 # LLVM linkage:
83 LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs)
84 $$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1))
85 $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
86 $$(LLVM_CONFIG_$(1))
87 endef
88
89 $(foreach host,$(CFG_HOST), \
90 $(eval $(call DEF_LLVM_RULES,$(host))))
91
92 $(foreach host,$(CFG_HOST), \
93 $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
94
95 # This can't be done in target.mk because it's included before this file.
96 define LLVM_LINKAGE_DEPS
97 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
98 endef
99
100 $(foreach source,$(CFG_HOST), \
101 $(foreach target,$(CFG_TARGET), \
102 $(eval $(call LLVM_LINKAGE_DEPS,0,$(target),$(source))) \
103 $(eval $(call LLVM_LINKAGE_DEPS,1,$(target),$(source))) \
104 $(eval $(call LLVM_LINKAGE_DEPS,2,$(target),$(source))) \
105 $(eval $(call LLVM_LINKAGE_DEPS,3,$(target),$(source)))))