forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.mk
162 lines (134 loc) · 5.44 KB
/
target.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# TARGET_STAGE_N template: This defines how target artifacts are built
# for all stage/target architecture combinations. The arguments:
# $(1) is the stage
# $(2) is the target triple
# $(3) is the host triple
# If you are making non-backwards compatible changes to the runtime
# (resp. corelib), set this flag to 1. It will cause stage1 to use
# the snapshot runtime (resp. corelib) rather than the runtime
# (resp. corelib) from the working directory.
USE_SNAPSHOT_RUNTIME=0
USE_SNAPSHOT_CORELIB=0
define TARGET_STAGE_N
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \
rt/$(2)/arch/$$(HOST_$(2))/libmorestack.a
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
$$(TSREQ$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM): \
rustllvm/$(2)/$$(CFG_RUSTLLVM)
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
$$(RUSTC_INPUTS) \
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTSYNTAX)
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTSYNTAX): \
$$(LIBRUSTSYNTAX_CRATE) $$(LIBRUSTSYNTAX_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM) \
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) $(BORROWCK) -o $$@ $$< && touch $$@
endef
# The stage0 (snapshot) compiler produces binaries that expect the
# snapshot runtime. Normally the working directory runtime and
# snapshot runtime are compatible, so this is no problem. But
# sometimes we want to make non-backwards-compatible changes. In
# those cases, the stage1 compiler and libraries (which are produced
# by stage0) should use the runtime from the snapshot. The stage2
# compiler and libraries (which are produced by stage1) will be the
# first that are expecting to run against the runtime as defined in
# the working directory.
#
# The catch is that you may not add new functions to the runtime
# in this case!
#
# Arguments are the same as for TARGET_BASE_STAGE_N
define TARGET_RT_FROM_SNAPSHOT
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME): \
$$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME)
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
endef
# This rule copies from the runtime for the working directory. It
# applies to targets produced by stage1 or later. See comment on
# previous rule.
#
# Arguments are the same as for TARGET_BASE_STAGE_N
define TARGET_RT_FROM_WD
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME): \
rt/$(2)/$$(CFG_RUNTIME)
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
endef
# As above, but builds the corelib either by taking it out of the
# snapshot or from the working directory.
define TARGET_CORELIB_FROM_SNAPSHOT
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
$$(HLIB$(1)_H_$(3))/$$(CFG_CORELIB) \
$$(CORELIB_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3))
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
$$(Q)cp $$(HLIB$(1)_H_$(3))/$$(CORELIB_GLOB) \
$$(TLIB$(1)_T_$(2)_H_$(3))
endef
define TARGET_CORELIB_FROM_WD
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
endef
# In principle, each host can build each target:
$(foreach source,$(CFG_TARGET_TRIPLES), \
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call TARGET_STAGE_N,0,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,1,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,2,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,3,$(target),$(source)))))
# Host triple either uses the snapshot runtime or runtime from
# working directory, depending on the USE_SNAPSHOT_RUNTIME var.
ifeq ($(USE_SNAPSHOT_RUNTIME),1)
$(foreach src,$(CFG_HOST_TRIPLE),\
$(eval $(call TARGET_RT_FROM_SNAPSHOT,0,$(src),$(src))))
else
$(foreach src,$(CFG_HOST_TRIPLE),\
$(eval $(call TARGET_RT_FROM_WD,0,$(src),$(src))))
endif
ifeq ($(USE_SNAPSHOT_CORELIB),1)
$(foreach src,$(CFG_HOST_TRIPLE),\
$(eval $(call TARGET_CORELIB_FROM_SNAPSHOT,0,$(src),$(src))))
else
$(foreach src,$(CFG_HOST_TRIPLE),\
$(eval $(call TARGET_CORELIB_FROM_WD,0,$(src),$(src))))
endif
# Non-host triples build the stage0 runtime from the working directory
$(foreach source,$(CFG_TARGET_TRIPLES), \
$(foreach target,$(NON_HOST_TRIPLES), \
$(eval $(call TARGET_RT_FROM_WD,0,$(target),$(source))) \
$(eval $(call TARGET_CORELIB_FROM_WD,0,$(target),$(source))) \
))
# After stage0, always build the stage0 runtime from the working directory
$(foreach source,$(CFG_TARGET_TRIPLES), \
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call TARGET_RT_FROM_WD,1,$(target),$(source))) \
$(eval $(call TARGET_RT_FROM_WD,2,$(target),$(source))) \
$(eval $(call TARGET_RT_FROM_WD,3,$(target),$(source))) \
$(eval $(call TARGET_CORELIB_FROM_WD,1,$(target),$(source))) \
$(eval $(call TARGET_CORELIB_FROM_WD,2,$(target),$(source))) \
$(eval $(call TARGET_CORELIB_FROM_WD,3,$(target),$(source))) \
))