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