]> git.proxmox.com Git - rustc.git/blob - mk/target.mk
Imported Upstream version 1.9.0+dfsg1
[rustc.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 # Used as defaults for the runtime ar and cc tools
17 export CFG_DEFAULT_LINKER
18 export CFG_DEFAULT_AR
19
20 # Macro that generates the full list of dependencies for a crate at a particular
21 # stage/target/host tuple.
22 #
23 # $(1) - stage
24 # $(2) - target
25 # $(3) - host
26 # $(4) crate
27 define RUST_CRATE_FULLDEPS
28 CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4) := \
29 $$(CRATEFILE_$(4)) \
30 $$(RSINPUTS_$(4)) \
31 $$(foreach dep,$$(RUST_DEPS_$(4)_T_$(2)), \
32 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
33 $$(foreach dep,$$(NATIVE_DEPS_$(4)), \
34 $$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),$$(dep))) \
35 $$(foreach dep,$$(NATIVE_DEPS_$(4)_T_$(2)), \
36 $$(RT_OUTPUT_DIR_$(2))/$$(dep))
37 endef
38
39 $(foreach host,$(CFG_HOST), \
40 $(foreach target,$(CFG_TARGET), \
41 $(foreach stage,$(STAGES), \
42 $(foreach crate,$(CRATES), \
43 $(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
44
45 # RUST_TARGET_STAGE_N template: This defines how target artifacts are built
46 # for all stage/target architecture combinations. This is one giant rule which
47 # works as follows:
48 #
49 # 1. The immediate dependencies are the rust source files
50 # 2. Each rust crate dependency is listed (based on their stamp files),
51 # as well as all native dependencies (listed in RT_OUTPUT_DIR)
52 # 3. The stage (n-1) compiler is required through the TSREQ dependency
53 # 4. When actually executing the rule, the first thing we do is to clean out
54 # old libs and rlibs via the REMOVE_ALL_OLD_GLOB_MATCHES macro
55 # 5. Finally, we get around to building the actual crate. It's just one
56 # "small" invocation of the previous stage rustc. We use -L to
57 # RT_OUTPUT_DIR so all the native dependencies are picked up.
58 # Additionally, we pass in the llvm dir so rustc can link against it.
59 # 6. Some cleanup is done (listing what was just built) if verbose is turned
60 # on.
61 #
62 # $(1) is the stage
63 # $(2) is the target triple
64 # $(3) is the host triple
65 # $(4) is the crate name
66 define RUST_TARGET_STAGE_N
67
68 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2)
69 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
70 $$(CRATEFILE_$(4)) \
71 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
72 $$(LLVM_CONFIG_$(2)) \
73 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
74 | $$(TLIB$(1)_T_$(2)_H_$(3))/
75 @$$(call E, rustc: $$(@D)/lib$(4))
76 @touch $$@.start_time
77 $$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
78 $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
79 $$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
80 $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
81 $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
82 $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \
83 $$(RUST_LIB_FLAGS_ST$(1)) \
84 -L "$$(RT_OUTPUT_DIR_$(2))" \
85 $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
86 $$(LLVM_STDCPP_RUSTFLAGS_$(2)) \
87 $$(RUSTFLAGS_$(4)) \
88 $$(RUSTFLAGS$(1)_$(4)) \
89 $$(RUSTFLAGS$(1)_$(4)_T_$(2)) \
90 --out-dir $$(@D) \
91 -C extra-filename=-$$(CFG_FILENAME_EXTRA) \
92 -C metadata=$$(CFG_FILENAME_EXTRA) \
93 $$<
94 @touch -r $$@.start_time $$@ && rm $$@.start_time
95 $$(call LIST_ALL_OLD_GLOB_MATCHES, \
96 $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
97 $$(call LIST_ALL_OLD_GLOB_MATCHES, \
98 $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
99
100 endef
101
102 # Macro for building any tool as part of the rust compilation process. Each
103 # tool is defined in crates.mk with a list of library dependencies as well as
104 # the source file for the tool. Building each tool will also be passed '--cfg
105 # <tool>' for usage in driver.rs
106 #
107 # This build rule is similar to the one found above, just tweaked for
108 # locations and things.
109 #
110 # $(1) - stage
111 # $(2) - target triple
112 # $(3) - host triple
113 # $(4) - name of the tool being built
114 define TARGET_TOOL
115
116 $$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
117 $$(TOOL_SOURCE_$(4)) \
118 $$(TOOL_INPUTS_$(4)) \
119 $$(foreach dep,$$(TOOL_DEPS_$(4)), \
120 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
121 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
122 | $$(TBIN$(1)_T_$(2)_H_$(3))/
123 @$$(call E, rustc: $$@)
124 $$(STAGE$(1)_T_$(2)_H_$(3)) \
125 $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
126 -o $$@ $$< --cfg $(4)
127
128 endef
129
130 # Macro for building runtime startup/shutdown object files;
131 # these are Rust's equivalent of crti.o, crtn.o
132 #
133 # $(1) - stage
134 # $(2) - target triple
135 # $(3) - host triple
136 # $(4) - object basename
137 define TARGET_RUSTRT_STARTUP_OBJ
138
139 $$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o: \
140 $(S)src/rtstartup/$(4).rs \
141 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.core \
142 $$(HSREQ$(1)_T_$(2)_H_$(3)) \
143 | $$(TBIN$(1)_T_$(2)_H_$(3))/
144 @$$(call E, rustc: $$@)
145 $$(STAGE$(1)_T_$(2)_H_$(3)) --emit=obj -o $$@ $$<
146
147 ifeq ($$(CFG_RUSTRT_HAS_STARTUP_OBJS_$(2)), 1)
148 # Add dependencies on Rust startup objects to all crates that depend on core.
149 # This ensures that they are built after core (since they depend on it),
150 # but before everything else (since they are needed for linking dylib crates).
151 $$(foreach crate, $$(TARGET_CRATES_$(2)), \
152 $$(if $$(findstring core,$$(DEPS_$$(crate))), \
153 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate))) : $$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o
154 endif
155
156 endef
157
158 # Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
159 # a directory that can be cleaned out during the middle of a run of
160 # the get-snapshot.py script. Therefore, every recipe needs to have
161 # an order-only dependency either on $(SNAPSHOT_RUSTC_POST_CLEANUP) or
162 # on $$(TSREQ$(1)_T_$(2)_H_$(3)), to ensure that no products will be
163 # put into the target area until after the get-snapshot.py script has
164 # had its chance to clean it out; otherwise the other products will be
165 # inadvertently included in the clean out.
166 SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
167
168 define TARGET_HOST_RULES
169
170 $$(TLIB$(1)_T_$(2)_H_$(3))/:
171 mkdir -p $$@
172
173 $$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
174 | $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
175 @$$(call E, cp: $$@)
176 $$(Q)cp $$< $$@
177 endef
178
179 $(foreach source,$(CFG_HOST), \
180 $(foreach target,$(CFG_TARGET), \
181 $(eval $(call TARGET_HOST_RULES,0,$(target),$(source))) \
182 $(eval $(call TARGET_HOST_RULES,1,$(target),$(source))) \
183 $(eval $(call TARGET_HOST_RULES,2,$(target),$(source))) \
184 $(eval $(call TARGET_HOST_RULES,3,$(target),$(source)))))
185
186 # In principle, each host can build each target for both libs and tools
187 $(foreach crate,$(CRATES), \
188 $(foreach source,$(CFG_HOST), \
189 $(foreach target,$(CFG_TARGET), \
190 $(eval $(call RUST_TARGET_STAGE_N,0,$(target),$(source),$(crate))) \
191 $(eval $(call RUST_TARGET_STAGE_N,1,$(target),$(source),$(crate))) \
192 $(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate))) \
193 $(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
194
195 $(foreach host,$(CFG_HOST), \
196 $(foreach target,$(CFG_TARGET), \
197 $(foreach stage,$(STAGES), \
198 $(foreach tool,$(TOOLS), \
199 $(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))
200
201 $(foreach host,$(CFG_HOST), \
202 $(foreach target,$(CFG_TARGET), \
203 $(foreach stage,$(STAGES), \
204 $(foreach obj,rsbegin rsend, \
205 $(eval $(call TARGET_RUSTRT_STARTUP_OBJ,$(stage),$(target),$(host),$(obj)))))))