]> git.lizzy.rs Git - rust.git/blob - Makefile.in
ebcd5c7960344cb8c6a38c4fca70fed841976de8
[rust.git] / Makefile.in
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 # An explanation of how the build is structured:
12 #
13 # There are multiple build stages (0-3) needed to verify that the
14 # compiler is properly self-hosting. Each stage is divided between
15 # 'host' artifacts and 'target' artifacts, where the stageN host
16 # compiler builds artifacts for 1 or more stageN target architectures.
17 # Once the stageN target compiler has been built for the host
18 # architecture it is promoted (copied) to a stageN+1 host artifact.
19 #
20 # The stage3 host compiler is a compiler that successfully builds
21 # itself and should (in theory) be bitwise identical to the stage2
22 # host compiler. The process is bootstrapped using a stage0 host
23 # compiler downloaded from a previous snapshot.
24 #
25 # At no time should stageN artifacts be interacting with artifacts
26 # from other stages. For consistency, we use the 'promotion' logic
27 # for all artifacts, even those that don't make sense on non-host
28 # architectures.
29 #
30 # The directory layout for a stage is intended to match the layout
31 # of the installed compiler, and looks like the following:
32 #
33 # stageN - this is the system root, corresponding to, e.g. /usr
34 #   bin - binaries compiled for the host
35 #   lib - libraries used by the host compiler
36 #     rustc - rustc's own place to organize libraries
37 #       $(target) - target-specific artifacts
38 #         bin - binaries for target architectures
39 #         lib - libraries for target architectures
40 #
41 # A note about host libraries:
42 #
43 # The only libraries that get promoted to stageN/lib are those needed
44 # by rustc. In general, rust programs, even those compiled for the
45 # host architecture will use libraries from the target
46 # directories. This gives rust some freedom to experiment with how
47 # libraries are managed and versioned without polluting the common
48 # areas of the filesystem.
49 #
50 # General rust binaries may stil live in the host bin directory; they
51 # will just link against the libraries in the target lib directory.
52 #
53 # Admittedly this is a little convoluted.
54
55 STAGES = 0 1 2 3
56
57 ######################################################################
58 # Residual auto-configuration
59 ######################################################################
60
61 # Recursive wildcard function
62 # http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
63 rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
64   $(filter $(subst *,%,$2),$d))
65
66 include config.mk
67
68 # We track all of the object files we might build so that we can find
69 # and include all of the .d files in one fell swoop.
70 ALL_OBJ_FILES :=
71
72 MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
73 NON_BUILD_HOST_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_HOST_TRIPLES))
74 NON_BUILD_TARGET_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_TARGET_TRIPLES))
75
76 ifneq ($(MAKE_RESTARTS),)
77 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
78 endif
79
80 CFG_INFO := $(info cfg: build triple $(CFG_BUILD_TRIPLE))
81 CFG_INFO := $(info cfg: host triples $(CFG_HOST_TRIPLES))
82 CFG_INFO := $(info cfg: target triples $(CFG_TARGET_TRIPLES))
83
84 ifneq ($(wildcard $(NON_BUILD_HOST_TRIPLES)),)
85 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST_TRIPLES))
86 endif
87 ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
88 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
89 endif
90
91 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
92 CFG_GCCISH_CFLAGS :=
93 CFG_GCCISH_LINK_FLAGS :=
94
95 ifdef CFG_DISABLE_OPTIMIZE
96   $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
97   CFG_RUSTC_FLAGS +=
98 else
99   # The rtopt cfg turns off runtime sanity checks
100   CFG_RUSTC_FLAGS += -O --cfg rtopt
101 endif
102
103 ifdef CFG_ENABLE_DEBUG
104   $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
105   CFG_GCCISH_CFLAGS += -DRUST_DEBUG
106 else
107   CFG_RUSTC_FLAGS += --cfg ndebug
108   CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
109 endif
110
111 ifdef SAVE_TEMPS
112   CFG_RUSTC_FLAGS += --save-temps
113 endif
114 ifdef ASM_COMMENTS
115   CFG_RUSTC_FLAGS += -Z asm-comments
116 endif
117 ifdef TIME_PASSES
118   CFG_RUSTC_FLAGS += -Z time-passes
119 endif
120 ifdef TIME_LLVM_PASSES
121   CFG_RUSTC_FLAGS += -Z time-llvm-passes
122 endif
123 ifdef TRACE
124   CFG_RUSTC_FLAGS += -Z trace
125 endif
126 ifndef DEBUG_BORROWS
127   RUSTFLAGS_STAGE1 += -Z no-debug-borrows
128   RUSTFLAGS_STAGE2 += -Z no-debug-borrows
129 endif
130
131 # platform-specific auto-configuration
132 include $(CFG_SRC_DIR)mk/platform.mk
133
134 # Run the stage1/2 compilers under valgrind
135 ifdef VALGRIND_COMPILE
136   CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
137 else
138   CFG_VALGRIND_COMPILE :=
139 endif
140
141 # version-string calculation
142 CFG_GIT_DIR := $(CFG_SRC_DIR).git
143 CFG_RELEASE = 0.8-pre
144 CFG_VERSION = $(CFG_RELEASE)
145 # windows exe's need numeric versions - don't use anything but
146 # numbers and dots here
147 CFG_VERSION_WIN = 0.8
148
149 ifneq ($(wildcard $(CFG_GIT)),)
150 ifneq ($(wildcard $(CFG_GIT_DIR)),)
151     CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
152                      --pretty=format:'(%h %ci)')
153     CFG_VER_HASH = $(shell git --git-dir=$(CFG_GIT_DIR) rev-parse HEAD)
154 endif
155 endif
156
157 ifdef CFG_ENABLE_VALGRIND
158   $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
159 else
160   CFG_VALGRIND :=
161 endif
162 ifdef CFG_BAD_VALGRIND
163   $(info cfg: disabling valgrind due to its unreliability on this platform)
164   CFG_VALGRIND :=
165 endif
166
167
168 ######################################################################
169 # Target-and-rule "utility variables"
170 ######################################################################
171
172 ifdef VERBOSE
173   Q :=
174   E =
175 else
176   Q := @
177   E = echo $(1)
178 endif
179
180 S := $(CFG_SRC_DIR)
181
182 define DEF_X
183 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
184 endef
185 $(foreach target,$(CFG_TARGET_TRIPLES),\
186   $(eval $(call DEF_X,$(target))))
187
188 # Look in doc and src dirs.
189 VPATH := $(S)doc $(S)src
190
191 # "Source" files we generate in builddir along the way.
192 GENERATED :=
193
194 # Delete the built-in rules.
195 .SUFFIXES:
196 %:: %,v
197 %:: RCS/%,v
198 %:: RCS/%
199 %:: s.%
200 %:: SCCS/s.%
201
202
203 ######################################################################
204 # Crates
205 ######################################################################
206
207 define DEF_LIBS
208
209 CFG_RUNTIME_$(1) :=$(call CFG_LIB_NAME_$(1),rustrt)
210 CFG_RUSTLLVM_$(1) :=$(call CFG_LIB_NAME_$(1),rustllvm)
211 CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std)
212 CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra)
213 CFG_LIBRUSTC_$(1) :=$(call CFG_LIB_NAME_$(1),rustc)
214 CFG_LIBSYNTAX_$(1) :=$(call CFG_LIB_NAME_$(1),syntax)
215 CFG_LIBRUSTPKG_$(1) :=$(call CFG_LIB_NAME_$(1),rustpkg)
216 CFG_LIBRUSTDOC_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc)
217 CFG_LIBRUSTDOCNG_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc_ng)
218 CFG_LIBRUSTI_$(1) :=$(call CFG_LIB_NAME_$(1),rusti)
219 CFG_LIBRUST_$(1) :=$(call CFG_LIB_NAME_$(1),rust)
220
221 EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra)
222 STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std)
223 LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc)
224 LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax)
225 LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg)
226 LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc)
227 LIBRUSTDOCNG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc_ng)
228 LIBRUSTI_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rusti)
229 LIBRUST_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rust)
230 EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra)
231 STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std)
232 LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc)
233 LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax)
234 LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg)
235 LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc)
236 LIBRUSTDOCNG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc_ng)
237 LIBRUSTI_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rusti)
238 LIBRUST_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rust)
239
240 endef
241
242 # $(1) is the path for directory to match against
243 # $(2) is the glob to use in the match
244 # $(3) is filename (usually the target being created) to filter out from match
245 #      (i.e. filename is not out-of-date artifact from prior Rust version/build)
246 #
247 # Note that a common bug is to accidentally construct the glob denoted
248 # by $(2) with a space character prefix, which invalidates the
249 # construction $(1)$(2).
250 define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
251   $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "Warning: there are previous" \'$(2)\' "libraries:" $$MATCHES; fi
252 endef
253
254 # Same interface as above, but deletes rather than just listing the files.
255 define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
256   $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "Warning: removing previous" \'$(2)\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
257 endef
258
259 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
260 # than in the macros above because it needs the result of running the
261 # `ls` command after other rules in the command list have run; the
262 # macro-expander for $(wildcard ...) would deliver its results too
263 # soon. (This is in contrast to the macros above, which are meant to
264 # be run at the outset of a command list in a rule.)
265 ifdef VERBOSE
266 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
267   @echo "Info: now are following matches for" '$(2)' "libraries:"
268   @( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
269 endef
270 else
271 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
272 endef
273 endif
274
275 $(foreach target,$(CFG_TARGET_TRIPLES),\
276   $(eval $(call DEF_LIBS,$(target))))
277
278 ######################################################################
279 # Standard library variables
280 ######################################################################
281
282 STDLIB_CRATE := $(S)src/libstd/std.rs
283 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/,        \
284                                            *.rs */*.rs */*/*rs */*/*/*rs))
285
286 ######################################################################
287 # Extra library variables
288 ######################################################################
289
290 EXTRALIB_CRATE := $(S)src/libextra/extra.rs
291 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/,          \
292                                           *.rs */*.rs))
293
294 ######################################################################
295 # rustc crate variables
296 ######################################################################
297
298 COMPILER_CRATE := $(S)src/librustc/rustc.rs
299 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/,      \
300                            *.rs */*.rs */*/*.rs */*/*/*.rs))
301
302 LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs
303 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
304                            *.rs */*.rs */*/*.rs */*/*/*.rs))
305
306 DRIVER_CRATE := $(S)src/driver/driver.rs
307
308 ######################################################################
309 # LLVM macros
310 ######################################################################
311
312 # FIXME: x86-ism
313 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
314                 interpreter instrumentation
315
316 define DEF_LLVM_VARS
317 # The configure script defines these variables with the target triples
318 # separated by Z. This defines new ones with the expected format.
319 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
320 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
321
322 # Any rules that depend on LLVM should depend on LLVM_CONFIG
323 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
324 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
325 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
326 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
327 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
328 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
329 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
330 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
331 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
332 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
333 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
334 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
335
336 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
337 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
338
339 endef
340
341 $(foreach host,$(CFG_HOST_TRIPLES), \
342  $(eval $(call DEF_LLVM_VARS,$(host))))
343
344 ######################################################################
345 # Exports for sub-utilities
346 ######################################################################
347
348 # Note that any variable that re-configure should pick up needs to be
349 # exported
350
351 export CFG_SRC_DIR
352 export CFG_BUILD_DIR
353 export CFG_VERSION
354 export CFG_VERSION_WIN
355 export CFG_BUILD_TRIPLE
356 export CFG_LLVM_ROOT
357 export CFG_ENABLE_MINGW_CROSS
358 export CFG_PREFIX
359 export CFG_LIBDIR
360
361 ######################################################################
362 # Subprograms
363 ######################################################################
364
365 ######################################################################
366 # Per-stage targets and runner
367 ######################################################################
368
369 define SREQ
370 # $(1) is the stage number
371 # $(2) is the target triple
372 # $(3) is the host triple
373
374 # Destinations of artifacts for the host compiler
375 HROOT$(1)_H_$(3) = $(3)/stage$(1)
376 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
377 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
378
379 # Destinations of artifacts for target architectures
380 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
381 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
382 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
383
384 # The name of the standard and extra libraries used by rustc
385 ifdef CFG_DISABLE_SHAREDSTD
386   HSTDLIB_DEFAULT$(1)_H_$(3) = \
387     $$(HLIB$(1)_H_$(3))/libstd.rlib
388   TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
389     $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
390
391   HEXTRALIB_DEFAULT$(1)_H_$(3) = \
392     $$(HLIB$(1)_H_$(3))/libextra.rlib
393   TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
394     $$(TLIB$(1)_T_$(2)_H_$(3))/libextra.rlib
395
396   HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
397     $$(HLIB$(1)_H_$(3))/librustc.rlib
398   TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
399     $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
400 else
401   HSTDLIB_DEFAULT$(1)_H_$(3) = \
402     $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB_$(3))
403   TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
404     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2))
405
406   HEXTRALIB_DEFAULT$(1)_H_$(3) = \
407     $$(HLIB$(1)_H_$(3))/$(CFG_EXTRALIB_$(3))
408   TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
409     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
410
411   HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
412     $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC_$(3))
413   TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
414     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2))
415 endif
416
417 # Preqrequisites for using the stageN compiler
418 HSREQ$(1)_H_$(3) = \
419         $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
420         $$(HLIB$(1)_H_$(3))/$(CFG_RUNTIME_$(3)) \
421         $$(HLIB$(1)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
422         $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
423         $$(HEXTRALIB_DEFAULT$(1)_H_$(3)) \
424         $$(HLIBSYNTAX_DEFAULT$(1)_H_$(3)) \
425         $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
426         $$(MKFILE_DEPS)
427
428 # Prerequisites for using the stageN compiler to build target artifacts
429 TSREQ$(1)_T_$(2)_H_$(3) = \
430         $$(HSREQ$(1)_H_$(3)) \
431         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) \
432         $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
433
434 # Prerequisites for a working stageN compiler and libraries, for a specific target
435 SREQ$(1)_T_$(2)_H_$(3) = \
436         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
437         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
438         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
439
440 # Prerequisites for a working stageN compiler and libraries, for a specific target
441 CSREQ$(1)_T_$(2)_H_$(3) = \
442         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
443         $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
444         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
445         $$(HBIN$(1)_H_$(3))/rustdoc_ng$$(X_$(3)) \
446         $$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \
447         $$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \
448         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \
449         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \
450         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOCNG_$(3)) \
451         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTI_$(3)) \
452         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUST_$(3)) \
453         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
454         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))  \
455         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2))  \
456         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \
457         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \
458         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \
459         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOCNG_$(2)) \
460         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTI_$(2)) \
461         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUST_$(2))
462
463 ifeq ($(1),0)
464 # Don't run the the stage0 compiler under valgrind - that ship has sailed
465 CFG_VALGRIND_COMPILE$(1) =
466 else
467 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
468 endif
469
470 # Add RUSTFLAGS_STAGEN values to the build command
471 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
472
473 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
474
475 # Pass --cfg stage0 only for the build->host part of stage0;
476 # if you're building a cross config, the host->* parts are
477 # effectively stage1, since it uses the just-built stage0.
478 ifeq ($(1),0)
479 ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(3)))
480 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
481 endif
482 endif
483
484 STAGE$(1)_T_$(2)_H_$(3) :=                                              \
485         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
486                 $$(CFG_VALGRIND_COMPILE$(1))                    \
487                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
488                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
489                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
490                 $$(RUSTC_FLAGS_$(2))
491
492 PERF_STAGE$(1)_T_$(2)_H_$(3) :=                                 \
493         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
494                 $$(CFG_PERF_TOOL)                                               \
495                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
496                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
497                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
498                 $$(RUSTC_FLAGS_$(2))
499
500 endef
501
502 $(foreach build,$(CFG_HOST_TRIPLES), \
503  $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
504   $(eval $(foreach stage,$(STAGES), \
505    $(eval $(call SREQ,$(stage),$(target),$(build))))))))
506
507 ######################################################################
508 # rustc-H-targets
509 #
510 # Builds a functional Rustc for the given host.
511 ######################################################################
512
513 define DEF_RUSTC_STAGE_TARGET
514 # $(1) == architecture
515 # $(2) == stage
516
517 rustc-stage$(2)-H-$(1):                                                 \
518         $$(foreach target,$$(CFG_TARGET_TRIPLES),       \
519                 $$(SREQ$(2)_T_$$(target)_H_$(1)))
520
521 endef
522
523 $(foreach host,$(CFG_HOST_TRIPLES),                                                     \
524  $(eval $(foreach stage,1 2 3,                                                                  \
525   $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
526
527 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
528 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
529 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
530
531 define DEF_RUSTC_TARGET
532 # $(1) == architecture
533
534 rustc-H-$(1): rustc-stage2-H-$(1)
535 endef
536
537 $(foreach host,$(CFG_TARGET_TRIPLES),                   \
538  $(eval $(call DEF_RUSTC_TARGET,$(host))))
539
540 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
541 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
542 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
543 rustc: rustc-H-$(CFG_BUILD_TRIPLE)
544
545 rustc-H-all: $(foreach host,$(CFG_HOST_TRIPLES),rustc-H-$(host))
546
547 ######################################################################
548 # Entrypoint rule
549 ######################################################################
550
551 .DEFAULT_GOAL := all
552
553 ifneq ($(CFG_IN_TRANSITION),)
554
555 CFG_INFO := $(info cfg:)
556 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
557 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
558 CFG_INFO := $(info cfg:)
559
560 #XXX This is surely busted
561 all: $(SREQ1$(CFG_BUILD_TRIPLE)) $(GENERATED) docs
562
563 else
564
565 define ALL_TARGET_N
566 ifneq ($$(findstring $(1),$$(CFG_HOST_TRIPLES)),)
567 # This is a host
568 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
569 else
570 # This is a target only
571 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
572 endif
573 endef
574
575 $(foreach target,$(CFG_TARGET_TRIPLES), \
576  $(foreach host,$(CFG_HOST_TRIPLES), \
577  $(eval $(call ALL_TARGET_N,$(target),$(host)))))
578
579 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
580         $(foreach host,$(CFG_HOST_TRIPLES), \
581  all-target-$(target)-host-$(host)))
582
583 all: $(ALL_TARGET_RULES) $(GENERATED) docs
584
585 endif
586
587
588 ######################################################################
589 # Re-configuration
590 ######################################################################
591
592 ifndef CFG_DISABLE_MANAGE_SUBMODULES
593 # This is a pretty expensive operation but I don't see any way to avoid it
594 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
595 else
596 NEED_GIT_RECONFIG=0
597 endif
598
599 ifeq ($(NEED_GIT_RECONFIG),0)
600 else
601 # If the submodules have changed then always execute config.mk
602 .PHONY: config.stamp
603 endif
604
605 Makefile config.mk: config.stamp
606
607 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
608         @$(call E, cfg: reconfiguring)
609         $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
610
611
612 ######################################################################
613 # Primary-target makefiles
614 ######################################################################
615
616 include $(CFG_SRC_DIR)mk/target.mk
617 include $(CFG_SRC_DIR)mk/host.mk
618 include $(CFG_SRC_DIR)mk/stage0.mk
619 include $(CFG_SRC_DIR)mk/rt.mk
620 include $(CFG_SRC_DIR)mk/rustllvm.mk
621 include $(CFG_SRC_DIR)mk/tools.mk
622 include $(CFG_SRC_DIR)mk/docs.mk
623 include $(CFG_SRC_DIR)mk/llvm.mk
624
625 ######################################################################
626 # Secondary makefiles, conditionalized for speed
627 ######################################################################
628
629 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS))   \
630                $(findstring check,$(MAKECMDGOALS))  \
631                $(findstring test,$(MAKECMDGOALS))   \
632                $(findstring tidy,$(MAKECMDGOALS))   \
633                $(findstring clean,$(MAKECMDGOALS))),)
634   CFG_INFO := $(info cfg: including dist rules)
635   include $(CFG_SRC_DIR)mk/dist.mk
636 endif
637
638 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))   \
639                $(findstring clean,$(MAKECMDGOALS))),)
640   CFG_INFO := $(info cfg: including snap rules)
641   include $(CFG_SRC_DIR)mk/snap.mk
642 endif
643
644 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
645   CFG_INFO := $(info cfg: including reformat rules)
646   include $(CFG_SRC_DIR)mk/pp.mk
647 endif
648
649 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
650                $(findstring test,$(MAKECMDGOALS))  \
651                $(findstring perf,$(MAKECMDGOALS))  \
652                $(findstring tidy,$(MAKECMDGOALS))),)
653   CFG_INFO := $(info cfg: including test rules)
654   include $(CFG_SRC_DIR)mk/tests.mk
655 endif
656
657 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
658   CFG_INFO := $(info cfg: including perf rules)
659   include $(CFG_SRC_DIR)mk/perf.mk
660 endif
661
662 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
663   CFG_INFO := $(info cfg: including clean rules)
664   include $(CFG_SRC_DIR)mk/clean.mk
665 endif
666
667 ifneq ($(findstring install,$(MAKECMDGOALS)),)
668   ifdef DESTDIR
669     CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR)/$(CFG_PREFIX))
670     CFG_PREFIX:=$(DESTDIR)/$(CFG_PREFIX)
671     export CFG_PREFIX
672   endif
673
674   CFG_INFO := $(info cfg: including install rules)
675   include $(CFG_SRC_DIR)mk/install.mk
676 endif
677
678 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
679                $(findstring TAGS.vi,$(MAKECMDGOALS))),)
680   CFG_INFO := $(info cfg: including ctags rules)
681   include $(CFG_SRC_DIR)mk/ctags.mk
682 endif
683
684 # Find all of the .d files and include them to add information about
685 # header file dependencies.
686 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
687 -include $(ALL_DEP_FILES)