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