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