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.
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.
11 # An explanation of how the build is structured:
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.
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.
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
30 # The directory layout for a stage is intended to match the layout
31 # of the installed compiler, and looks like the following:
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
41 # A note about host libraries:
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.
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.
53 # Admittedly this is a little convoluted.
57 ######################################################################
58 # Residual auto-configuration
59 ######################################################################
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))
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.
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))
76 ifneq ($(MAKE_RESTARTS),)
77 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
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))
84 ifneq ($(wildcard $(NON_BUILD_HOST)),)
85 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
87 ifneq ($(wildcard $(NON_BUILD_TARGET)),)
88 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
91 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
93 CFG_GCCISH_LINK_FLAGS :=
95 ifdef CFG_DISABLE_OPTIMIZE
96 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
99 # The rtopt cfg turns off runtime sanity checks
100 CFG_RUSTC_FLAGS += -O --cfg rtopt
103 ifdef CFG_DISABLE_DEBUG
104 CFG_RUSTC_FLAGS += --cfg ndebug
105 CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
107 $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
108 CFG_RUSTC_FLAGS += --cfg debug
109 CFG_GCCISH_CFLAGS += -DRUST_DEBUG
113 CFG_RUSTC_FLAGS += --save-temps
116 CFG_RUSTC_FLAGS += -Z asm-comments
119 CFG_RUSTC_FLAGS += -Z time-passes
121 ifdef TIME_LLVM_PASSES
122 CFG_RUSTC_FLAGS += -Z time-llvm-passes
125 CFG_RUSTC_FLAGS += -Z trace
128 RUSTFLAGS_STAGE0 += -Z no-debug-borrows
129 RUSTFLAGS_STAGE1 += -Z no-debug-borrows
130 RUSTFLAGS_STAGE2 += -Z no-debug-borrows
133 # platform-specific auto-configuration
134 include $(CFG_SRC_DIR)mk/platform.mk
136 # Run the stage1/2 compilers under valgrind
137 ifdef VALGRIND_COMPILE
138 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
140 CFG_VALGRIND_COMPILE :=
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
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.
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)
165 ifdef CFG_ENABLE_VALGRIND
166 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
170 ifdef CFG_BAD_VALGRIND
171 $(info cfg: disabling valgrind due to its unreliability on this platform)
176 ######################################################################
177 # Target-and-rule "utility variables"
178 ######################################################################
191 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
193 $(foreach target,$(CFG_TARGET),\
194 $(eval $(call DEF_X,$(target))))
196 # Look in doc and src dirs.
197 VPATH := $(S)doc $(S)src
199 # "Source" files we generate in builddir along the way.
202 # Delete the built-in rules.
211 ######################################################################
213 ######################################################################
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)
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)
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)
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
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
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.)
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 )
273 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
277 $(foreach target,$(CFG_TARGET),\
278 $(eval $(call DEF_LIBS,$(target))))
280 ######################################################################
281 # Standard library variables
282 ######################################################################
284 STDLIB_CRATE := $(S)src/libstd/lib.rs
285 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
286 *.rs */*.rs */*/*rs */*/*/*rs))
288 ######################################################################
289 # Extra library variables
290 ######################################################################
292 EXTRALIB_CRATE := $(S)src/libextra/lib.rs
293 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/, \
296 ######################################################################
297 # Rust UV library variables
298 ######################################################################
300 LIBRUSTUV_CRATE := $(S)src/librustuv/lib.rs
301 LIBRUSTUV_INPUTS := $(wildcard $(addprefix $(S)src/librustuv/, \
304 ######################################################################
305 # rustc crate variables
306 ######################################################################
308 COMPILER_CRATE := $(S)src/librustc/lib.rs
309 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/, \
310 *.rs */*.rs */*/*.rs */*/*/*.rs))
312 LIBSYNTAX_CRATE := $(S)src/libsyntax/lib.rs
313 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
314 *.rs */*.rs */*/*.rs */*/*/*.rs))
316 DRIVER_CRATE := $(S)src/driver/driver.rs
318 ######################################################################
320 ######################################################################
323 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
324 interpreter instrumentation
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)))
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)
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))
351 $(foreach host,$(CFG_HOST), \
352 $(eval $(call DEF_LLVM_VARS,$(host))))
354 ######################################################################
355 # Exports for sub-utilities
356 ######################################################################
358 # Note that any variable that re-configure should pick up needs to be
364 export CFG_VERSION_WIN
367 export CFG_ENABLE_MINGW_CROSS
371 ######################################################################
373 ######################################################################
375 ######################################################################
376 # Per-stage targets and runner
377 ######################################################################
380 # $(1) is the stage number
381 # $(2) is the target triple
382 # $(3) is the host triple
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)
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)
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
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
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
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))
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))
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))
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))
432 # Preqrequisites for using the stageN compiler
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)) \
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
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))
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))
473 # Don't run the the stage0 compiler under valgrind - that ship has sailed
474 CFG_VALGRIND_COMPILE$(1) =
476 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
479 # Add RUSTFLAGS_STAGEN values to the build command
480 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
482 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
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.
488 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
489 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
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)) \
501 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
502 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
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)) \
511 $(foreach build,$(CFG_HOST), \
512 $(eval $(foreach target,$(CFG_TARGET), \
513 $(eval $(foreach stage,$(STAGES), \
514 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
516 ######################################################################
519 # Builds a functional Rustc for the given host.
520 ######################################################################
522 define DEF_RUSTC_STAGE_TARGET
523 # $(1) == architecture
526 rustc-stage$(2)-H-$(1): \
527 $$(foreach target,$$(CFG_TARGET), \
528 $$(SREQ$(2)_T_$$(target)_H_$(1)))
532 $(foreach host,$(CFG_HOST), \
533 $(eval $(foreach stage,1 2 3, \
534 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
536 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
537 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
538 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
540 define DEF_RUSTC_TARGET
541 # $(1) == architecture
543 rustc-H-$(1): rustc-stage2-H-$(1)
546 $(foreach host,$(CFG_TARGET), \
547 $(eval $(call DEF_RUSTC_TARGET,$(host))))
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)
554 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
556 ######################################################################
558 ######################################################################
562 ifneq ($(CFG_IN_TRANSITION),)
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:)
569 #XXX This is surely busted
570 all: $(SREQ1$(CFG_BUILD)) $(GENERATED) docs
575 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
577 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
579 # This is a target only
580 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
584 $(foreach target,$(CFG_TARGET), \
585 $(foreach host,$(CFG_HOST), \
586 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
588 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
589 $(foreach host,$(CFG_HOST), \
590 all-target-$(target)-host-$(host)))
592 all: $(ALL_TARGET_RULES) $(GENERATED) docs
597 ######################################################################
599 ######################################################################
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 '^\(+\|-\)')
608 ifeq ($(NEED_GIT_RECONFIG),0)
610 # If the submodules have changed then always execute config.mk
614 Makefile config.mk: config.stamp
616 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
617 @$(call E, cfg: reconfiguring)
618 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
621 ######################################################################
622 # Primary-target makefiles
623 ######################################################################
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.
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
638 ######################################################################
639 # Secondary makefiles, conditionalized for speed
640 ######################################################################
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
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
657 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
658 CFG_INFO := $(info cfg: including reformat rules)
659 include $(CFG_SRC_DIR)mk/pp.mk
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
670 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
671 CFG_INFO := $(info cfg: including perf rules)
672 include $(CFG_SRC_DIR)mk/perf.mk
675 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
676 CFG_INFO := $(info cfg: including clean rules)
677 include $(CFG_SRC_DIR)mk/clean.mk
680 ifneq ($(findstring install,$(MAKECMDGOALS)),)
681 CFG_INFO := $(info cfg: including install rules)
682 include $(CFG_SRC_DIR)mk/install.mk
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
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)