]> git.proxmox.com Git - rustc.git/blame - mk/target.mk
Imported Upstream version 1.3.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
LB
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
1a4d82fc
JJ
18# be overridden during development temporarily. For stage0, we allow warnings
19# which may be bugs in stage0 (should be fixed in stage1+)
20RUST_LIB_FLAGS_ST0 += -W warnings
21RUST_LIB_FLAGS_ST1 += -D warnings
22RUST_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
31define RUST_CRATE_FULLDEPS
32CRATE_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)), \
d9579d0f
AL
38 $$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),$$(dep))) \
39 $$(foreach dep,$$(NATIVE_DEPS_$(4)_T_$(2)), \
62682a34
SL
40 $$(RT_OUTPUT_DIR_$(2))/$$(dep)) \
41 $$(foreach dep,$$(NATIVE_TOOL_DEPS_$(4)_T_$(2)), \
42 $$(TBIN$(1)_T_$(3)_H_$(3))/$$(dep)) \
43 $$(CUSTOM_DEPS_$(4)_T_$(2))
1a4d82fc
JJ
44endef
45
46$(foreach host,$(CFG_HOST), \
47 $(foreach target,$(CFG_TARGET), \
48 $(foreach stage,$(STAGES), \
49 $(foreach crate,$(CRATES), \
50 $(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
51
52# RUST_TARGET_STAGE_N template: This defines how target artifacts are built
53# for all stage/target architecture combinations. This is one giant rule which
54# works as follows:
55#
56# 1. The immediate dependencies are the rust source files
57# 2. Each rust crate dependency is listed (based on their stamp files),
58# as well as all native dependencies (listed in RT_OUTPUT_DIR)
59# 3. The stage (n-1) compiler is required through the TSREQ dependency, along
60# with the morestack library
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)) \
62682a34 96 $$(RUSTFLAGS_$(4)_T_$(2)) \
1a4d82fc
JJ
97 --out-dir $$(@D) \
98 -C extra-filename=-$$(CFG_FILENAME_EXTRA) \
99 $$<
c34b1796 100 @touch -r $$@.start_time $$@ && rm $$@.start_time
1a4d82fc
JJ
101 $$(call LIST_ALL_OLD_GLOB_MATCHES, \
102 $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
103 $$(call LIST_ALL_OLD_GLOB_MATCHES, \
104 $$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
223e47cc 105
1a4d82fc 106endef
223e47cc 107
1a4d82fc
JJ
108# Macro for building any tool as part of the rust compilation process. Each
109# tool is defined in crates.mk with a list of library dependencies as well as
110# the source file for the tool. Building each tool will also be passed '--cfg
111# <tool>' for usage in driver.rs
112#
113# This build rule is similar to the one found above, just tweaked for
114# locations and things.
115#
116# $(1) - stage
117# $(2) - target triple
118# $(3) - host triple
119# $(4) - name of the tool being built
120define TARGET_TOOL
121
122$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
123 $$(TOOL_SOURCE_$(4)) \
124 $$(TOOL_INPUTS_$(4)) \
125 $$(foreach dep,$$(TOOL_DEPS_$(4)), \
126 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
127 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
128 | $$(TBIN$(1)_T_$(2)_H_$(3))/
129 @$$(call E, rustc: $$@)
130 $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --cfg $(4)
223e47cc 131
1a4d82fc 132endef
223e47cc 133
1a4d82fc
JJ
134# Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
135# a directory that can be cleaned out during the middle of a run of
136# the get-snapshot.py script. Therefore, every recipe needs to have
137# an order-only dependency either on $(SNAPSHOT_RUSTC_POST_CLEANUP) or
138# on $$(TSREQ$(1)_T_$(2)_H_$(3)), to ensure that no products will be
139# put into the target area until after the get-snapshot.py script has
140# had its chance to clean it out; otherwise the other products will be
c34b1796 141# inadvertently included in the clean out.
1a4d82fc 142SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
223e47cc 143
1a4d82fc 144define TARGET_HOST_RULES
223e47cc 145
970d7e83
LB
146$$(TBIN$(1)_T_$(2)_H_$(3))/:
147 mkdir -p $$@
148
970d7e83
LB
149$$(TLIB$(1)_T_$(2)_H_$(3))/:
150 mkdir -p $$@
970d7e83 151
d9579d0f 152$$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
1a4d82fc
JJ
153 | $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
154 @$$(call E, cp: $$@)
155 $$(Q)cp $$< $$@
62682a34
SL
156
157$$(TBIN$(1)_T_$(2)_H_$(3))/%: $$(CFG_LLVM_INST_DIR_$(2))/bin/% \
158 | $$(TBIN$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
159 @$$(call E, cp: $$@)
160 $$(Q)cp $$< $$@
223e47cc
LB
161endef
162
1a4d82fc
JJ
163$(foreach source,$(CFG_HOST), \
164 $(foreach target,$(CFG_TARGET), \
165 $(eval $(call TARGET_HOST_RULES,0,$(target),$(source))) \
166 $(eval $(call TARGET_HOST_RULES,1,$(target),$(source))) \
167 $(eval $(call TARGET_HOST_RULES,2,$(target),$(source))) \
168 $(eval $(call TARGET_HOST_RULES,3,$(target),$(source)))))
169
170# In principle, each host can build each target for both libs and tools
171$(foreach crate,$(CRATES), \
172 $(foreach source,$(CFG_HOST), \
173 $(foreach target,$(CFG_TARGET), \
174 $(eval $(call RUST_TARGET_STAGE_N,0,$(target),$(source),$(crate))) \
175 $(eval $(call RUST_TARGET_STAGE_N,1,$(target),$(source),$(crate))) \
176 $(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate))) \
177 $(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
178
179$(foreach host,$(CFG_HOST), \
180 $(foreach target,$(CFG_TARGET), \
181 $(foreach stage,$(STAGES), \
182 $(foreach tool,$(TOOLS), \
183 $(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))
62682a34
SL
184
185# We have some triples which are bootstrapped from other triples, and this means
186# that we need to fixup some of the native tools that a triple depends on.
187#
188# For example, MSVC requires the llvm-ar.exe executable to manage archives, but
189# it bootstraps from the GNU Windows triple. This means that the compiler will
190# add this directory to PATH when executing new processes:
191#
192# $SYSROOT/rustlib/x86_64-pc-windows-gnu/bin
193#
194# Unfortunately, however, the GNU triple is not known about in stage0, so the
195# tools are actually located in:
196#
197# $SYSROOT/rustlib/x86_64-pc-windows-msvc/bin
198#
199# To remedy this problem, the rules below copy all native tool dependencies into
200# the bootstrap triple's location in stage 0 so the bootstrap compiler can find
201# the right sets of tools. Later stages (1+) will have the right host triple for
202# the compiler, so there's no need to worry there.
203#
204# $(1) - stage
205# $(2) - triple that's being used as host/target
206# $(3) - triple snapshot is built for
207# $(4) - crate
208# $(5) - tool
209define MOVE_TOOLS_TO_SNAPSHOT_HOST_DIR
210ifneq (,$(3))
211$$(TLIB$(1)_T_$(2)_H_$(2))/stamp.$(4): $$(HLIB$(1)_H_$(2))/rustlib/$(3)/bin/$(5)
212
213$$(HLIB$(1)_H_$(2))/rustlib/$(3)/bin/$(5): $$(TBIN$(1)_T_$(2)_H_$(2))/$(5)
214 mkdir -p $$(@D)
215 cp $$< $$@
216endif
217endef
218
219$(foreach target,$(CFG_TARGET), \
220 $(foreach crate,$(CRATES), \
221 $(foreach tool,$(NATIVE_TOOL_DEPS_$(crate)_T_$(target)), \
222 $(eval $(call MOVE_TOOLS_TO_SNAPSHOT_HOST_DIR,0,$(target),$(BOOTSTRAP_FROM_$(target)),$(crate),$(tool))))))
c1a9b12d
SL
223
224# For MSVC targets we need to set up some environment variables for the linker
225# to work correctly when building Rust crates. These two variables are:
226#
227# - LIB tells the linker the default search path for finding system libraries,
228# for example kernel32.dll
229# - PATH needs to be modified to ensure that MSVC's link.exe is first in the
230# path instead of MinGW's /usr/bin/link.exe (entirely unrelated)
231#
232# The values for these variables are detected by the configure script.
233define SETUP_LIB_MSVC_ENV_VARS
234ifeq ($$(findstring msvc,$(2)),msvc)
235$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
236 export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(2)))
237$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
238 export PATH := $$(CFG_MSVC_BINDIR_$$(HOST_$(2))):$$(PATH)
239endif
240endef
241define SETUP_TOOL_MSVC_ENV_VARS
242ifeq ($$(findstring msvc,$(2)),msvc)
243$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
244 export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(2)))
245$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
246 export PATH := $$(CFG_MSVC_BINDIR_$$(HOST_$(2))):$$(PATH)
247endif
248endef
249
250$(foreach host,$(CFG_HOST), \
251 $(foreach target,$(CFG_TARGET), \
252 $(foreach crate,$(CRATES), \
253 $(eval $(call SETUP_LIB_MSVC_ENV_VARS,0,$(target),$(host),$(crate))))))
254$(foreach host,$(CFG_HOST), \
255 $(foreach target,$(CFG_TARGET), \
256 $(foreach tool,$(TOOLS), \
257 $(eval $(call SETUP_TOOL_MSVC_ENV_VARS,0,$(target),$(host),$(tool))))))