]> git.lizzy.rs Git - rust.git/blob - mk/target.mk
fix spacing issue in trpl/documentation doc
[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 RUST_LIB_FLAGS_ST0 += -W warnings
21 RUST_LIB_FLAGS_ST1 += -D warnings
22 RUST_LIB_FLAGS_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                 $$(foreach dep,$$(NATIVE_DEPS_$(4)_T_$(2)), \
40                   $$(RT_OUTPUT_DIR_$(2))/$$(dep))
41 endef
42
43 $(foreach host,$(CFG_HOST), \
44  $(foreach target,$(CFG_TARGET), \
45   $(foreach stage,$(STAGES), \
46    $(foreach crate,$(CRATES), \
47     $(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
48
49 # RUST_TARGET_STAGE_N template: This defines how target artifacts are built
50 # for all stage/target architecture combinations. This is one giant rule which
51 # works as follows:
52 #
53 #   1. The immediate dependencies are the rust source files
54 #   2. Each rust crate dependency is listed (based on their stamp files),
55 #      as well as all native dependencies (listed in RT_OUTPUT_DIR)
56 #   3. The stage (n-1) compiler is required through the TSREQ dependency
57 #   4. When actually executing the rule, the first thing we do is to clean out
58 #      old libs and rlibs via the REMOVE_ALL_OLD_GLOB_MATCHES macro
59 #   5. Finally, we get around to building the actual crate. It's just one
60 #      "small" invocation of the previous stage rustc. We use -L to
61 #      RT_OUTPUT_DIR so all the native dependencies are picked up.
62 #      Additionally, we pass in the llvm dir so rustc can link against it.
63 #   6. Some cleanup is done (listing what was just built) if verbose is turned
64 #      on.
65 #
66 # $(1) is the stage
67 # $(2) is the target triple
68 # $(3) is the host triple
69 # $(4) is the crate name
70 define RUST_TARGET_STAGE_N
71
72 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2)
73 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
74                 $$(CRATEFILE_$(4)) \
75                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
76                 $$(LLVM_CONFIG_$(2)) \
77                 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
78                 | $$(TLIB$(1)_T_$(2)_H_$(3))/
79         @$$(call E, rustc: $$(@D)/lib$(4))
80         @touch $$@.start_time
81         $$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
82             $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
83         $$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
84             $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
85         $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
86             $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \
87                 $$(RUST_LIB_FLAGS_ST$(1)) \
88                 -L "$$(RT_OUTPUT_DIR_$(2))" \
89                 $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
90                 $$(LLVM_STDCPP_RUSTFLAGS_$(2)) \
91                 $$(RUSTFLAGS_$(4)) \
92                 $$(RUSTFLAGS$(1)_$(4)_T_$(2)) \
93                 --out-dir $$(@D) \
94                 -C extra-filename=-$$(CFG_FILENAME_EXTRA) \
95                 $$<
96         @touch -r $$@.start_time $$@ && rm $$@.start_time
97         $$(call LIST_ALL_OLD_GLOB_MATCHES, \
98             $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
99         $$(call LIST_ALL_OLD_GLOB_MATCHES, \
100             $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
101
102 endef
103
104 # Macro for building any tool as part of the rust compilation process. Each
105 # tool is defined in crates.mk with a list of library dependencies as well as
106 # the source file for the tool. Building each tool will also be passed '--cfg
107 # <tool>' for usage in driver.rs
108 #
109 # This build rule is similar to the one found above, just tweaked for
110 # locations and things.
111 #
112 # $(1) - stage
113 # $(2) - target triple
114 # $(3) - host triple
115 # $(4) - name of the tool being built
116 define TARGET_TOOL
117
118 $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
119                 $$(TOOL_SOURCE_$(4)) \
120                 $$(TOOL_INPUTS_$(4)) \
121                 $$(foreach dep,$$(TOOL_DEPS_$(4)), \
122                     $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
123                 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
124                 | $$(TBIN$(1)_T_$(2)_H_$(3))/
125         @$$(call E, rustc: $$@)
126         $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4)
127
128 endef
129
130 # Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
131 # a directory that can be cleaned out during the middle of a run of
132 # the get-snapshot.py script.  Therefore, every recipe needs to have
133 # an order-only dependency either on $(SNAPSHOT_RUSTC_POST_CLEANUP) or
134 # on $$(TSREQ$(1)_T_$(2)_H_$(3)), to ensure that no products will be
135 # put into the target area until after the get-snapshot.py script has
136 # had its chance to clean it out; otherwise the other products will be
137 # inadvertently included in the clean out.
138 SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
139
140 define TARGET_HOST_RULES
141
142 $$(TLIB$(1)_T_$(2)_H_$(3))/:
143         mkdir -p $$@
144
145 $$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
146             | $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
147         @$$(call E, cp: $$@)
148         $$(Q)cp $$< $$@
149 endef
150
151 $(foreach source,$(CFG_HOST), \
152  $(foreach target,$(CFG_TARGET), \
153   $(eval $(call TARGET_HOST_RULES,0,$(target),$(source))) \
154   $(eval $(call TARGET_HOST_RULES,1,$(target),$(source))) \
155   $(eval $(call TARGET_HOST_RULES,2,$(target),$(source))) \
156   $(eval $(call TARGET_HOST_RULES,3,$(target),$(source)))))
157
158 # In principle, each host can build each target for both libs and tools
159 $(foreach crate,$(CRATES), \
160  $(foreach source,$(CFG_HOST), \
161   $(foreach target,$(CFG_TARGET), \
162    $(eval $(call RUST_TARGET_STAGE_N,0,$(target),$(source),$(crate))) \
163    $(eval $(call RUST_TARGET_STAGE_N,1,$(target),$(source),$(crate))) \
164    $(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate))) \
165    $(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
166
167 $(foreach host,$(CFG_HOST), \
168  $(foreach target,$(CFG_TARGET), \
169   $(foreach stage,$(STAGES), \
170    $(foreach tool,$(TOOLS), \
171     $(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))