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_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_HOST_TRIPLES))
74 NON_BUILD_TARGET_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_TARGET_TRIPLES))
76 ifneq ($(MAKE_RESTARTS),)
77 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
80 CFG_INFO := $(info cfg: build triple $(CFG_BUILD_TRIPLE))
81 CFG_INFO := $(info cfg: host triples $(CFG_HOST_TRIPLES))
82 CFG_INFO := $(info cfg: target triples $(CFG_TARGET_TRIPLES))
84 ifneq ($(wildcard $(NON_BUILD_HOST_TRIPLES)),)
85 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST_TRIPLES))
87 ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
88 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
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_ENABLE_DEBUG
104 $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
105 CFG_RUSTC_FLAGS += --cfg debug
106 CFG_GCCISH_CFLAGS += -DRUST_DEBUG
108 CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
112 CFG_RUSTC_FLAGS += --save-temps
115 CFG_RUSTC_FLAGS += -Z asm-comments
118 CFG_RUSTC_FLAGS += -Z time-passes
120 ifdef TIME_LLVM_PASSES
121 CFG_RUSTC_FLAGS += -Z time-llvm-passes
124 CFG_RUSTC_FLAGS += -Z trace
127 RUSTFLAGS_STAGE1 += -Z no-debug-borrows
128 RUSTFLAGS_STAGE2 += -Z no-debug-borrows
131 # platform-specific auto-configuration
132 include $(CFG_SRC_DIR)mk/platform.mk
134 # Run the stage1/2 compilers under valgrind
135 ifdef VALGRIND_COMPILE
136 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
138 CFG_VALGRIND_COMPILE :=
141 # version-string calculation
142 CFG_GIT_DIR := $(CFG_SRC_DIR).git
143 CFG_RELEASE = 0.8-pre
144 CFG_VERSION = $(CFG_RELEASE)
145 # windows exe's need numeric versions - don't use anything but
146 # numbers and dots here
147 CFG_VERSION_WIN = 0.8
149 ifneq ($(wildcard $(CFG_GIT)),)
150 ifneq ($(wildcard $(CFG_GIT_DIR)),)
151 CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
152 --pretty=format:'(%h %ci)')
153 CFG_VER_HASH = $(shell git --git-dir=$(CFG_GIT_DIR) rev-parse HEAD)
157 ifdef CFG_ENABLE_VALGRIND
158 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
162 ifdef CFG_BAD_VALGRIND
163 $(info cfg: disabling valgrind due to its unreliability on this platform)
168 ######################################################################
169 # Target-and-rule "utility variables"
170 ######################################################################
183 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
185 $(foreach target,$(CFG_TARGET_TRIPLES),\
186 $(eval $(call DEF_X,$(target))))
188 # Look in doc and src dirs.
189 VPATH := $(S)doc $(S)src
191 # "Source" files we generate in builddir along the way.
194 # Delete the built-in rules.
203 ######################################################################
205 ######################################################################
209 CFG_RUNTIME_$(1) :=$(call CFG_LIB_NAME_$(1),rustrt)
210 CFG_RUSTLLVM_$(1) :=$(call CFG_LIB_NAME_$(1),rustllvm)
211 CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std)
212 CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra)
213 CFG_LIBRUSTC_$(1) :=$(call CFG_LIB_NAME_$(1),rustc)
214 CFG_LIBSYNTAX_$(1) :=$(call CFG_LIB_NAME_$(1),syntax)
215 CFG_LIBRUSTPKG_$(1) :=$(call CFG_LIB_NAME_$(1),rustpkg)
216 CFG_LIBRUSTDOC_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc)
217 CFG_LIBRUSTDOCNG_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc_ng)
218 CFG_LIBRUSTI_$(1) :=$(call CFG_LIB_NAME_$(1),rusti)
219 CFG_LIBRUST_$(1) :=$(call CFG_LIB_NAME_$(1),rust)
221 EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra)
222 STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std)
223 LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc)
224 LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax)
225 LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg)
226 LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc)
227 LIBRUSTDOCNG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc_ng)
228 LIBRUSTI_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rusti)
229 LIBRUST_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rust)
230 EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra)
231 STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std)
232 LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc)
233 LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax)
234 LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg)
235 LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc)
236 LIBRUSTDOCNG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc_ng)
237 LIBRUSTI_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rusti)
238 LIBRUST_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rust)
242 # $(1) is the path for directory to match against
243 # $(2) is the glob to use in the match
244 # $(3) is filename (usually the target being created) to filter out from match
245 # (i.e. filename is not out-of-date artifact from prior Rust version/build)
247 # Note that a common bug is to accidentally construct the glob denoted
248 # by $(2) with a space character prefix, which invalidates the
249 # construction $(1)$(2).
250 define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
251 $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "Warning: there are previous" \'$(2)\' "libraries:" $$MATCHES; fi
254 # Same interface as above, but deletes rather than just listing the files.
255 define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
256 $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "Warning: removing previous" \'$(2)\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
259 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
260 # than in the macros above because it needs the result of running the
261 # `ls` command after other rules in the command list have run; the
262 # macro-expander for $(wildcard ...) would deliver its results too
263 # soon. (This is in contrast to the macros above, which are meant to
264 # be run at the outset of a command list in a rule.)
266 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
267 @echo "Info: now are following matches for" '$(2)' "libraries:"
268 @( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
271 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
275 $(foreach target,$(CFG_TARGET_TRIPLES),\
276 $(eval $(call DEF_LIBS,$(target))))
278 ######################################################################
279 # Standard library variables
280 ######################################################################
282 STDLIB_CRATE := $(S)src/libstd/std.rs
283 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
284 *.rs */*.rs */*/*rs */*/*/*rs))
286 ######################################################################
287 # Extra library variables
288 ######################################################################
290 EXTRALIB_CRATE := $(S)src/libextra/extra.rs
291 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/, \
294 ######################################################################
295 # rustc crate variables
296 ######################################################################
298 COMPILER_CRATE := $(S)src/librustc/rustc.rs
299 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/, \
300 *.rs */*.rs */*/*.rs */*/*/*.rs))
302 LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs
303 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
304 *.rs */*.rs */*/*.rs */*/*/*.rs))
306 DRIVER_CRATE := $(S)src/driver/driver.rs
308 ######################################################################
310 ######################################################################
313 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
314 interpreter instrumentation
317 # The configure script defines these variables with the target triples
318 # separated by Z. This defines new ones with the expected format.
319 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
320 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
322 # Any rules that depend on LLVM should depend on LLVM_CONFIG
323 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
324 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
325 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
326 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
327 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
328 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
329 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
330 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
331 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
332 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
333 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
334 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
336 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
337 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
341 $(foreach host,$(CFG_HOST_TRIPLES), \
342 $(eval $(call DEF_LLVM_VARS,$(host))))
344 ######################################################################
345 # Exports for sub-utilities
346 ######################################################################
348 # Note that any variable that re-configure should pick up needs to be
354 export CFG_VERSION_WIN
355 export CFG_BUILD_TRIPLE
357 export CFG_ENABLE_MINGW_CROSS
361 ######################################################################
363 ######################################################################
365 ######################################################################
366 # Per-stage targets and runner
367 ######################################################################
370 # $(1) is the stage number
371 # $(2) is the target triple
372 # $(3) is the host triple
374 # Destinations of artifacts for the host compiler
375 HROOT$(1)_H_$(3) = $(3)/stage$(1)
376 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
377 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
379 # Destinations of artifacts for target architectures
380 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
381 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
382 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
384 # The name of the standard and extra libraries used by rustc
385 ifdef CFG_DISABLE_SHAREDSTD
386 HSTDLIB_DEFAULT$(1)_H_$(3) = \
387 $$(HLIB$(1)_H_$(3))/libstd.rlib
388 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
389 $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
391 HEXTRALIB_DEFAULT$(1)_H_$(3) = \
392 $$(HLIB$(1)_H_$(3))/libextra.rlib
393 TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
394 $$(TLIB$(1)_T_$(2)_H_$(3))/libextra.rlib
396 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
397 $$(HLIB$(1)_H_$(3))/librustc.rlib
398 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
399 $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
401 HSTDLIB_DEFAULT$(1)_H_$(3) = \
402 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB_$(3))
403 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
404 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2))
406 HEXTRALIB_DEFAULT$(1)_H_$(3) = \
407 $$(HLIB$(1)_H_$(3))/$(CFG_EXTRALIB_$(3))
408 TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
409 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
411 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
412 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC_$(3))
413 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
414 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2))
417 # Preqrequisites for using the stageN compiler
419 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
420 $$(HLIB$(1)_H_$(3))/$(CFG_RUNTIME_$(3)) \
421 $$(HLIB$(1)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
422 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
423 $$(HEXTRALIB_DEFAULT$(1)_H_$(3)) \
424 $$(HLIBSYNTAX_DEFAULT$(1)_H_$(3)) \
425 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
428 # Prerequisites for using the stageN compiler to build target artifacts
429 TSREQ$(1)_T_$(2)_H_$(3) = \
430 $$(HSREQ$(1)_H_$(3)) \
431 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) \
432 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
434 # Prerequisites for a working stageN compiler and libraries, for a specific target
435 SREQ$(1)_T_$(2)_H_$(3) = \
436 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
437 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
438 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
440 # Prerequisites for a working stageN compiler and libraries, for a specific target
441 CSREQ$(1)_T_$(2)_H_$(3) = \
442 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
443 $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
444 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
445 $$(HBIN$(1)_H_$(3))/rustdoc_ng$$(X_$(3)) \
446 $$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \
447 $$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \
448 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \
449 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \
450 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOCNG_$(3)) \
451 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTI_$(3)) \
452 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUST_$(3)) \
453 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
454 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) \
455 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2)) \
456 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \
457 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \
458 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \
459 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOCNG_$(2)) \
460 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTI_$(2)) \
461 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUST_$(2))
464 # Don't run the the stage0 compiler under valgrind - that ship has sailed
465 CFG_VALGRIND_COMPILE$(1) =
467 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
470 # Add RUSTFLAGS_STAGEN values to the build command
471 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
473 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
475 # Pass --cfg stage0 only for the build->host part of stage0;
476 # if you're building a cross config, the host->* parts are
477 # effectively stage1, since it uses the just-built stage0.
479 ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(3)))
480 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
484 STAGE$(1)_T_$(2)_H_$(3) := \
485 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
486 $$(CFG_VALGRIND_COMPILE$(1)) \
487 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
488 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
489 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
492 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
493 $$(Q)$$(call CFG_RUN_TARG_$(3),$(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)) \
502 $(foreach build,$(CFG_HOST_TRIPLES), \
503 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
504 $(eval $(foreach stage,$(STAGES), \
505 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
507 ######################################################################
510 # Builds a functional Rustc for the given host.
511 ######################################################################
513 define DEF_RUSTC_STAGE_TARGET
514 # $(1) == architecture
517 rustc-stage$(2)-H-$(1): \
518 $$(foreach target,$$(CFG_TARGET_TRIPLES), \
519 $$(SREQ$(2)_T_$$(target)_H_$(1)))
523 $(foreach host,$(CFG_HOST_TRIPLES), \
524 $(eval $(foreach stage,1 2 3, \
525 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
527 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
528 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
529 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
531 define DEF_RUSTC_TARGET
532 # $(1) == architecture
534 rustc-H-$(1): rustc-stage2-H-$(1)
537 $(foreach host,$(CFG_TARGET_TRIPLES), \
538 $(eval $(call DEF_RUSTC_TARGET,$(host))))
540 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
541 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
542 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
543 rustc: rustc-H-$(CFG_BUILD_TRIPLE)
545 rustc-H-all: $(foreach host,$(CFG_HOST_TRIPLES),rustc-H-$(host))
547 ######################################################################
549 ######################################################################
553 ifneq ($(CFG_IN_TRANSITION),)
555 CFG_INFO := $(info cfg:)
556 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
557 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
558 CFG_INFO := $(info cfg:)
560 #XXX This is surely busted
561 all: $(SREQ1$(CFG_BUILD_TRIPLE)) $(GENERATED) docs
566 ifneq ($$(findstring $(1),$$(CFG_HOST_TRIPLES)),)
568 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
570 # This is a target only
571 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
575 $(foreach target,$(CFG_TARGET_TRIPLES), \
576 $(foreach host,$(CFG_HOST_TRIPLES), \
577 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
579 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
580 $(foreach host,$(CFG_HOST_TRIPLES), \
581 all-target-$(target)-host-$(host)))
583 all: $(ALL_TARGET_RULES) $(GENERATED) docs
588 ######################################################################
590 ######################################################################
592 ifndef CFG_DISABLE_MANAGE_SUBMODULES
593 # This is a pretty expensive operation but I don't see any way to avoid it
594 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
599 ifeq ($(NEED_GIT_RECONFIG),0)
601 # If the submodules have changed then always execute config.mk
605 Makefile config.mk: config.stamp
607 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
608 @$(call E, cfg: reconfiguring)
609 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
612 ######################################################################
613 # Primary-target makefiles
614 ######################################################################
616 include $(CFG_SRC_DIR)mk/target.mk
617 include $(CFG_SRC_DIR)mk/host.mk
618 include $(CFG_SRC_DIR)mk/stage0.mk
619 include $(CFG_SRC_DIR)mk/rt.mk
620 include $(CFG_SRC_DIR)mk/rustllvm.mk
621 include $(CFG_SRC_DIR)mk/tools.mk
622 include $(CFG_SRC_DIR)mk/docs.mk
623 include $(CFG_SRC_DIR)mk/llvm.mk
625 ######################################################################
626 # Secondary makefiles, conditionalized for speed
627 ######################################################################
629 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
630 $(findstring check,$(MAKECMDGOALS)) \
631 $(findstring test,$(MAKECMDGOALS)) \
632 $(findstring tidy,$(MAKECMDGOALS)) \
633 $(findstring clean,$(MAKECMDGOALS))),)
634 CFG_INFO := $(info cfg: including dist rules)
635 include $(CFG_SRC_DIR)mk/dist.mk
638 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
639 $(findstring clean,$(MAKECMDGOALS))),)
640 CFG_INFO := $(info cfg: including snap rules)
641 include $(CFG_SRC_DIR)mk/snap.mk
644 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
645 CFG_INFO := $(info cfg: including reformat rules)
646 include $(CFG_SRC_DIR)mk/pp.mk
649 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
650 $(findstring test,$(MAKECMDGOALS)) \
651 $(findstring perf,$(MAKECMDGOALS)) \
652 $(findstring tidy,$(MAKECMDGOALS))),)
653 CFG_INFO := $(info cfg: including test rules)
654 include $(CFG_SRC_DIR)mk/tests.mk
657 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
658 CFG_INFO := $(info cfg: including perf rules)
659 include $(CFG_SRC_DIR)mk/perf.mk
662 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
663 CFG_INFO := $(info cfg: including clean rules)
664 include $(CFG_SRC_DIR)mk/clean.mk
667 ifneq ($(findstring install,$(MAKECMDGOALS)),)
669 CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR)/$(CFG_PREFIX))
670 CFG_PREFIX:=$(DESTDIR)/$(CFG_PREFIX)
674 CFG_INFO := $(info cfg: including install rules)
675 include $(CFG_SRC_DIR)mk/install.mk
678 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
679 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
680 CFG_INFO := $(info cfg: including ctags rules)
681 include $(CFG_SRC_DIR)mk/ctags.mk
684 # Find all of the .d files and include them to add information about
685 # header file dependencies.
686 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
687 -include $(ALL_DEP_FILES)