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