]> git.lizzy.rs Git - rust.git/blob - mk/target.mk
auto merge of #13748 : hjr3/rust/guide-container-update, r=alexcrichton
[rust.git] / mk / target.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 # This is the compile-time target-triple for the compiler. For the compiler at
12 # runtime, this should be considered the host-triple. More explanation for why
13 # this exists can be found on issue #2400
14 export CFG_COMPILER_HOST_TRIPLE
15
16 # The standard libraries should be held up to a higher standard than any old
17 # code, make sure that these common warnings are denied by default. These can
18 # be overridden during development temporarily. For stage0, we allow warnings
19 # which may be bugs in stage0 (should be fixed in stage1+)
20 WFLAGS_ST0 = -W warnings
21 WFLAGS_ST1 = -D warnings
22 WFLAGS_ST2 = -D warnings
23
24 # Macro that generates the full list of dependencies for a crate at a particular
25 # stage/target/host tuple.
26 #
27 # $(1) - stage
28 # $(2) - target
29 # $(3) - host
30 # $(4) crate
31 define RUST_CRATE_FULLDEPS
32 CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4) :=                           \
33                 $$(CRATEFILE_$(4))                                  \
34                 $$(RSINPUTS_$(4))                                   \
35                 $$(foreach dep,$$(RUST_DEPS_$(4)),                  \
36                   $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))         \
37                 $$(foreach dep,$$(NATIVE_DEPS_$(4)),                \
38                   $$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),$$(dep)))
39 endef
40
41 $(foreach host,$(CFG_HOST),                                                 \
42  $(foreach target,$(CFG_TARGET),                                            \
43   $(foreach stage,$(STAGES),                                                \
44    $(foreach crate,$(CRATES),                                               \
45     $(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
46
47 # RUST_TARGET_STAGE_N template: This defines how target artifacts are built
48 # for all stage/target architecture combinations. This is one giant rule which
49 # works as follows:
50 #
51 #   1. The immediate dependencies are the rust source files
52 #   2. Each rust crate dependency is listed (based on their stamp files),
53 #      as well as all native dependencies (listed in RT_OUTPUT_DIR)
54 #   3. The stage (n-1) compiler is required through the TSREQ dependency, along
55 #      with the morestack library
56 #   4. When actually executing the rule, the first thing we do is to clean out
57 #      old libs and rlibs via the REMOVE_ALL_OLD_GLOB_MATCHES macro
58 #   5. Finally, we get around to building the actual crate. It's just one
59 #      "small" invocation of the previous stage rustc. We use -L to
60 #      RT_OUTPUT_DIR so all the native dependencies are picked up.
61 #      Additionally, we pass in the llvm dir so rustc can link against it.
62 #   6. Some cleanup is done (listing what was just built) if verbose is turned
63 #      on.
64 #
65 # $(1) is the stage
66 # $(2) is the target triple
67 # $(3) is the host triple
68 # $(4) is the crate name
69 define RUST_TARGET_STAGE_N
70
71 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2)
72 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4):                              \
73                 $$(CRATEFILE_$(4))                                  \
74                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))          \
75                 $$(TSREQ$(1)_T_$(2)_H_$(3))                         \
76                 | $$(TLIB$(1)_T_$(2)_H_$(3))/
77         @$$(call E, oxidize: $$(@D)/lib$(4))
78         $$(call REMOVE_ALL_OLD_GLOB_MATCHES,\
79             $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
80         $$(call REMOVE_ALL_OLD_GLOB_MATCHES,\
81             $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
82         $$(STAGE$(1)_T_$(2)_H_$(3)) \
83                 $$(WFLAGS_ST$(1)) \
84                 -L "$$(RT_OUTPUT_DIR_$(2))" \
85                 -L "$$(LLVM_LIBDIR_$(2))" \
86                 -L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
87                 --out-dir $$(@D) $$<
88         @touch $$@
89         $$(call LIST_ALL_OLD_GLOB_MATCHES,\
90             $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
91         $$(call LIST_ALL_OLD_GLOB_MATCHES,\
92             $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
93
94 endef
95
96 # Macro for building any tool as part of the rust compilation process. Each
97 # tool is defined in crates.mk with a list of library dependencies as well as
98 # the source file for the tool. Building each tool will also be passed '--cfg
99 # <tool>' for usage in driver.rs
100 #
101 # This build rule is similar to the one found above, just tweaked for
102 # locations and things.
103 #
104 # $(1) - stage
105 # $(2) - target triple
106 # $(3) - host triple
107 # $(4) - name of the tool being built
108 define TARGET_TOOL
109
110 $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)):                      \
111                 $$(TOOL_SOURCE_$(4))                            \
112                 $$(TOOL_INPUTS_$(4))                            \
113                 $$(foreach dep,$$(TOOL_DEPS_$(4)),              \
114                     $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))   \
115                 $$(TSREQ$(1)_T_$(2)_H_$(3))                     \
116                 | $$(TBIN$(1)_T_$(4)_H_$(3))/
117         @$$(call E, oxidize: $$@)
118         $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4)
119
120 endef
121
122 # Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
123 # a directory that can be cleaned out during the middle of a run of
124 # the get-snapshot.py script.  Therefore, every recipe needs to have
125 # an order-only dependency either on $(SNAPSHOT_RUSTC_POST_CLEANUP) or
126 # on $$(TSREQ$(1)_T_$(2)_H_$(3)), to ensure that no products will be
127 # put into the target area until after the get-snapshot.py script has
128 # had its chance to clean it out; otherwise the other products will be
129 # inadvertantly included in the clean out.
130 SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
131
132 define TARGET_HOST_RULES
133
134 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc: $(S)src/librustc/lib/llvmdeps.rs
135
136 $$(TBIN$(1)_T_$(2)_H_$(3))/:
137         mkdir -p $$@
138
139 $$(TLIB$(1)_T_$(2)_H_$(3))/:
140         mkdir -p $$@
141
142 $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a: \
143             $$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),compiler-rt) \
144             | $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
145         @$$(call E, cp: $$@)
146         $$(Q)cp $$< $$@
147
148 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \
149             $$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),morestack) \
150             | $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
151         @$$(call E, cp: $$@)
152         $$(Q)cp $$< $$@
153 endef
154
155 $(foreach source,$(CFG_HOST),                                               \
156  $(foreach target,$(CFG_TARGET),                                            \
157   $(eval $(call TARGET_HOST_RULES,0,$(target),$(source)))                   \
158   $(eval $(call TARGET_HOST_RULES,1,$(target),$(source)))                   \
159   $(eval $(call TARGET_HOST_RULES,2,$(target),$(source)))                   \
160   $(eval $(call TARGET_HOST_RULES,3,$(target),$(source)))))
161
162 # In principle, each host can build each target for both libs and tools
163 $(foreach crate,$(CRATES),                                                  \
164  $(foreach source,$(CFG_HOST),                                              \
165   $(foreach target,$(CFG_TARGET),                                           \
166    $(eval $(call RUST_TARGET_STAGE_N,0,$(target),$(source),$(crate)))       \
167    $(eval $(call RUST_TARGET_STAGE_N,1,$(target),$(source),$(crate)))       \
168    $(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate)))       \
169    $(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
170
171 $(foreach host,$(CFG_HOST),                                                 \
172  $(foreach target,$(CFG_TARGET),                                            \
173   $(foreach stage,$(STAGES),                                                \
174    $(foreach tool,$(TOOLS),                                                 \
175     $(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))