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