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 # rustlib - 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 # 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.
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
142 RUSTFLAGS_STAGE0 += -Z prefer-dynamic
143 RUSTFLAGS_STAGE1 += -Z prefer-dynamic
145 # platform-specific auto-configuration
146 include $(CFG_SRC_DIR)mk/platform.mk
148 # Run the stage1/2 compilers under valgrind
149 ifdef VALGRIND_COMPILE
150 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
152 CFG_VALGRIND_COMPILE :=
155 # version-string calculation
156 CFG_GIT_DIR := $(CFG_SRC_DIR).git
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
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.
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)
177 ifdef CFG_ENABLE_VALGRIND
178 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
182 ifdef CFG_BAD_VALGRIND
183 $(info cfg: disabling valgrind due to its unreliability on this platform)
188 ######################################################################
189 # Target-and-rule "utility variables"
190 ######################################################################
203 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
205 $(foreach target,$(CFG_TARGET),\
206 $(eval $(call DEF_X,$(target))))
208 # Look in doc and src dirs.
209 VPATH := $(S)doc $(S)src
211 # "Source" files we generate in builddir along the way.
214 # Delete the built-in rules.
223 ######################################################################
225 ######################################################################
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 CFG_LIBGREEN_$(1) :=$(call CFG_LIB_NAME_$(1),green)
239 CFG_LIBNATIVE_$(1) :=$(call CFG_LIB_NAME_$(1),native)
241 EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra)
242 STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std)
243 LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc)
244 LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax)
245 LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg)
246 LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc)
247 LIBRUSTUV_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustuv)
248 LIBGREEN_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),green)
249 LIBNATIVE_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),native)
250 EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra)
251 STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std)
252 LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc)
253 LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax)
254 LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg)
255 LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc)
256 LIBRUSTUV_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustuv)
257 LIBGREEN_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),green)
258 LIBNATIVE_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),native)
260 EXTRALIB_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,extra)
261 STDLIB_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,std)
262 LIBRUSTUV_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,rustuv)
263 LIBSYNTAX_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,syntax)
264 LIBRUSTC_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,rustc)
265 LIBNATIVE_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,native)
266 LIBGREEN_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,green)
270 # $(1) is the path for directory to match against
271 # $(2) is the glob to use in the match
272 # $(3) is filename (usually the target being created) to filter out from match
273 # (i.e. filename is not out-of-date artifact from prior Rust version/build)
275 # Note that a common bug is to accidentally construct the glob denoted
276 # by $(2) with a space character prefix, which invalidates the
277 # construction $(1)$(2).
278 define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
279 $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(2)\' "libraries:" $$MATCHES; fi
282 # Same interface as above, but deletes rather than just listing the files.
284 define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
285 $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "warning: removing previous" \'$(2)\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
288 define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
289 $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then rm $$MATCHES ; fi
293 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
294 # than in the macros above because it needs the result of running the
295 # `ls` command after other rules in the command list have run; the
296 # macro-expander for $(wildcard ...) would deliver its results too
297 # soon. (This is in contrast to the macros above, which are meant to
298 # be run at the outset of a command list in a rule.)
300 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
301 @echo "info: now are following matches for" '$(2)' "libraries:"
302 @( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
305 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
309 $(foreach target,$(CFG_TARGET),\
310 $(eval $(call DEF_LIBS,$(target))))
312 ######################################################################
313 # Standard library variables
314 ######################################################################
316 STDLIB_CRATE := $(S)src/libstd/lib.rs
317 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
318 *.rs */*.rs */*/*rs */*/*/*rs))
320 ######################################################################
321 # Extra library variables
322 ######################################################################
324 EXTRALIB_CRATE := $(S)src/libextra/lib.rs
325 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/, \
328 ######################################################################
329 # Rust UV library variables
330 ######################################################################
332 LIBRUSTUV_CRATE := $(S)src/librustuv/lib.rs
333 LIBRUSTUV_INPUTS := $(wildcard $(addprefix $(S)src/librustuv/, \
336 ######################################################################
337 # Green threading library variables
338 ######################################################################
340 LIBGREEN_CRATE := $(S)src/libgreen/lib.rs
341 LIBGREEN_INPUTS := $(wildcard $(addprefix $(S)src/libgreen/, \
344 ######################################################################
345 # Native threading library variables
346 ######################################################################
348 LIBNATIVE_CRATE := $(S)src/libnative/lib.rs
349 LIBNATIVE_INPUTS := $(wildcard $(addprefix $(S)src/libnative/, \
352 ######################################################################
353 # rustc crate variables
354 ######################################################################
356 COMPILER_CRATE := $(S)src/librustc/lib.rs
357 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/, \
358 *.rs */*.rs */*/*.rs */*/*/*.rs))
360 LIBSYNTAX_CRATE := $(S)src/libsyntax/lib.rs
361 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
362 *.rs */*.rs */*/*.rs */*/*/*.rs))
364 DRIVER_CRATE := $(S)src/driver/driver.rs
366 ######################################################################
368 ######################################################################
371 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
372 interpreter instrumentation
375 # The configure script defines these variables with the target triples
376 # separated by Z. This defines new ones with the expected format.
377 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
378 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
380 # Any rules that depend on LLVM should depend on LLVM_CONFIG
381 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
382 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
383 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
384 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
385 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
386 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
387 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
388 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
389 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
390 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
391 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
392 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
394 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
395 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
399 $(foreach host,$(CFG_HOST), \
400 $(eval $(call DEF_LLVM_VARS,$(host))))
402 ######################################################################
403 # Exports for sub-utilities
404 ######################################################################
406 # Note that any variable that re-configure should pick up needs to be
412 export CFG_VERSION_WIN
416 export CFG_ENABLE_MINGW_CROSS
419 export CFG_RUSTLIBDIR
420 export LIBDIR_RELATIVE
422 ######################################################################
424 ######################################################################
426 ######################################################################
427 # Per-stage targets and runner
428 ######################################################################
431 # $(1) is the stage number
432 # $(2) is the target triple
433 # $(3) is the host triple
435 # Destinations of artifacts for the host compiler
436 HROOT$(1)_H_$(3) = $(3)/stage$(1)
437 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
438 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(LIBDIR_RELATIVE)
440 # Destinations of artifacts for target architectures
441 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLIBDIR)/$(2)
442 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
443 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
445 # The name of the standard and extra libraries used by rustc
446 HSTDLIB_DEFAULT$(1)_H_$(3) = \
447 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB_$(3))
448 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
449 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2))
451 HEXTRALIB_DEFAULT$(1)_H_$(3) = \
452 $$(HLIB$(1)_H_$(3))/$(CFG_EXTRALIB_$(3))
453 TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
454 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
456 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
457 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC_$(3))
458 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
459 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2))
461 HLIBRUSTUV_DEFAULT$(1)_H_$(3) = \
462 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTUV_$(3))
463 TLIBRUSTUV_DEFAULT$(1)_T_$(2)_H_$(3) = \
464 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2))
466 HLIBGREEN_DEFAULT$(1)_H_$(3) = \
467 $$(HLIB$(1)_H_$(3))/$(CFG_LIBGREEN_$(3))
468 TLIBGREEN_DEFAULT$(1)_T_$(2)_H_$(3) = \
469 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBGREEN_$(2))
471 HLIBNATIVE_DEFAULT$(1)_H_$(3) = \
472 $$(HLIB$(1)_H_$(3))/$(CFG_LIBNATIVE_$(3))
473 TLIBNATIVE_DEFAULT$(1)_T_$(2)_H_$(3) = \
474 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBNATIVE_$(2))
476 # Preqrequisites for using the stageN compiler
478 HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
481 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
482 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
483 $$(HEXTRALIB_DEFAULT$(1)_H_$(3)) \
484 $$(HLIBSYNTAX_DEFAULT$(1)_H_$(3)) \
485 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
486 $$(HLIBRUSTUV_DEFAULT$(1)_H_$(3)) \
487 $$(HLIBGREEN_DEFAULT$(1)_H_$(3)) \
488 $$(HLIBNATIVE_DEFAULT$(1)_H_$(3)) \
492 # Prerequisites for using the stageN compiler to build target artifacts
493 TSREQ$(1)_T_$(2)_H_$(3) = \
494 $$(HSREQ$(1)_H_$(3)) \
495 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) \
496 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
498 # Prerequisites for a working stageN compiler and libraries, for a specific target
499 SREQ$(1)_T_$(2)_H_$(3) = \
500 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
501 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
502 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) \
503 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2)) \
504 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBGREEN_$(2)) \
505 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBNATIVE_$(2))
507 # Prerequisites for a working stageN compiler and libraries, for a specific target
508 CSREQ$(1)_T_$(2)_H_$(3) = \
509 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
510 $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
511 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
512 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \
513 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \
514 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
515 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) \
516 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2)) \
517 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \
518 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \
519 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \
520 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2)) \
521 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBGREEN_$(2)) \
522 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBNATIVE_$(2))
525 # Don't run the the stage0 compiler under valgrind - that ship has sailed
526 CFG_VALGRIND_COMPILE$(1) =
528 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
531 # Add RUSTFLAGS_STAGEN values to the build command
532 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
534 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
536 # Pass --cfg stage0 only for the build->host part of stage0;
537 # if you're building a cross config, the host->* parts are
538 # effectively stage1, since it uses the just-built stage0.
540 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
541 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
545 STAGE$(1)_T_$(2)_H_$(3) := \
546 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
547 $$(CFG_VALGRIND_COMPILE$(1)) \
548 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
549 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
550 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
553 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
554 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
556 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
557 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
558 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
563 $(foreach build,$(CFG_HOST), \
564 $(eval $(foreach target,$(CFG_TARGET), \
565 $(eval $(foreach stage,$(STAGES), \
566 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
568 ######################################################################
571 # Builds a functional Rustc for the given host.
572 ######################################################################
574 define DEF_RUSTC_STAGE_TARGET
575 # $(1) == architecture
578 rustc-stage$(2)-H-$(1): \
579 $$(foreach target,$$(CFG_TARGET), \
580 $$(SREQ$(2)_T_$$(target)_H_$(1)))
584 $(foreach host,$(CFG_HOST), \
585 $(eval $(foreach stage,1 2 3, \
586 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
588 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
589 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
590 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
592 define DEF_RUSTC_TARGET
593 # $(1) == architecture
595 rustc-H-$(1): rustc-stage2-H-$(1)
598 $(foreach host,$(CFG_TARGET), \
599 $(eval $(call DEF_RUSTC_TARGET,$(host))))
601 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
602 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
603 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
604 rustc: rustc-H-$(CFG_BUILD)
606 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
608 ######################################################################
610 ######################################################################
614 ifneq ($(CFG_IN_TRANSITION),)
616 CFG_INFO := $(info cfg:)
617 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
618 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
619 CFG_INFO := $(info cfg:)
621 #XXX This is surely busted
622 all: $(SREQ1$(CFG_BUILD)) $(GENERATED) docs
627 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
629 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
631 # This is a target only
632 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
636 $(foreach target,$(CFG_TARGET), \
637 $(foreach host,$(CFG_HOST), \
638 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
640 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
641 $(foreach host,$(CFG_HOST), \
642 all-target-$(target)-host-$(host)))
644 all: $(ALL_TARGET_RULES) $(GENERATED) docs
649 ######################################################################
651 ######################################################################
653 ifndef CFG_DISABLE_MANAGE_SUBMODULES
654 # This is a pretty expensive operation but I don't see any way to avoid it
655 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
660 ifeq ($(NEED_GIT_RECONFIG),0)
662 # If the submodules have changed then always execute config.mk
666 Makefile config.mk: config.stamp
668 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
669 @$(call E, cfg: reconfiguring)
670 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
673 ######################################################################
674 # Primary-target makefiles
675 ######################################################################
677 # Issue #9531: If you change the order of any of the following (or add
678 # new definitions), make sure definitions always precede their uses,
679 # especially for the dependency lists of recipes.
681 include $(CFG_SRC_DIR)mk/rt.mk
682 include $(CFG_SRC_DIR)mk/target.mk
683 include $(CFG_SRC_DIR)mk/host.mk
684 include $(CFG_SRC_DIR)mk/stage0.mk
685 include $(CFG_SRC_DIR)mk/rustllvm.mk
686 include $(CFG_SRC_DIR)mk/tools.mk
687 include $(CFG_SRC_DIR)mk/docs.mk
688 include $(CFG_SRC_DIR)mk/llvm.mk
690 ######################################################################
691 # Secondary makefiles, conditionalized for speed
692 ######################################################################
694 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
695 $(findstring check,$(MAKECMDGOALS)) \
696 $(findstring test,$(MAKECMDGOALS)) \
697 $(findstring tidy,$(MAKECMDGOALS)) \
698 $(findstring clean,$(MAKECMDGOALS))),)
699 CFG_INFO := $(info cfg: including dist rules)
700 include $(CFG_SRC_DIR)mk/dist.mk
703 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
704 $(findstring clean,$(MAKECMDGOALS))),)
705 CFG_INFO := $(info cfg: including snap rules)
706 include $(CFG_SRC_DIR)mk/snap.mk
709 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
710 $(findstring test,$(MAKECMDGOALS)) \
711 $(findstring perf,$(MAKECMDGOALS)) \
712 $(findstring tidy,$(MAKECMDGOALS))),)
713 CFG_INFO := $(info cfg: including test rules)
714 include $(CFG_SRC_DIR)mk/tests.mk
717 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
718 CFG_INFO := $(info cfg: including perf rules)
719 include $(CFG_SRC_DIR)mk/perf.mk
722 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
723 CFG_INFO := $(info cfg: including clean rules)
724 include $(CFG_SRC_DIR)mk/clean.mk
727 ifneq ($(findstring install,$(MAKECMDGOALS)),)
728 CFG_INFO := $(info cfg: including install rules)
729 include $(CFG_SRC_DIR)mk/install.mk
732 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
733 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
734 CFG_INFO := $(info cfg: including ctags rules)
735 include $(CFG_SRC_DIR)mk/ctags.mk
738 # Find all of the .d files and include them to add information about
739 # header file dependencies.
740 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
741 -include $(ALL_DEP_FILES)