1 # An explanation of how the build is structured:
3 # There are multiple build stages (0-3) needed to verify that the
4 # compiler is properly self-hosting. Each stage is divided between
5 # 'host' artifacts and 'target' artifacts, where the stageN host
6 # compiler builds artifacts for 1 or more stageN target architectures.
7 # Once the stageN target compiler has been built for the host
8 # architecture it is promoted (copied) to a stageN+1 host artifact.
10 # The stage3 host compiler is a compiler that successfully builds
11 # itself and should (in theory) be bitwise identical to the stage2
12 # host compiler. The process is bootstrapped using a stage0 host
13 # compiler downloaded from a previous snapshot.
15 # At no time should stageN artifacts be interacting with artifacts
16 # from other stages. For consistency, we use the 'promotion' logic
17 # for all artifacts, even those that don't make sense on non-host
20 # The directory layout for a stage is intended to match the layout
21 # of the installed compiler, and looks like the following:
23 # stageN - this is the system root, corresponding to, e.g. /usr
24 # bin - binaries compiled for the host
25 # lib - libraries used by the host compiler
26 # rustc - rustc's own place to organize libraries
27 # $(target) - target-specific artifacts
28 # bin - binaries for target architectures
29 # lib - libraries for target architectures
31 # A note about host libraries:
33 # The only libraries that get promoted to stageN/lib are those needed
34 # by rustc. In general, rust programs, even those compiled for the
35 # host architecture will use libraries from the target
36 # directories. This gives rust some freedom to experiment with how
37 # libraries are managed and versioned without polluting the common
38 # areas of the filesystem.
40 # General rust binaries may stil live in the host bin directory; they
41 # will just link against the libraries in the target lib directory.
43 # Admittedly this is a little convoluted.
47 ######################################################################
48 # Residual auto-configuration
49 ######################################################################
56 OUR_MKFILES := Makefile config.mk $(wildcard $(CFG_SRC_DIR)/mk/*.mk)
57 3RDPARTY_MKFILES := $(CFG_SRC_DIR)/src/libuv/Makefile \
58 $(wildcard $(CFG_SRC_DIR)/src/libuv/*.mk)
59 GEN_MKFILES := $(wildcard $(CFG_SRC_DIR)/mk/libuv/*/*/*) \
60 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*) \
61 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*) \
62 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*)
63 MKFILE_DEPS := $(OUR_MKFILES) $(3RDPARTY_MKFILES) $(GEN_MKFILES)
66 NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
68 ifneq ($(MAKE_RESTARTS),)
69 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
72 CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
73 CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
75 ifdef CFG_DISABLE_OPTIMIZE
76 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
83 CFG_RUSTC_FLAGS += --save-temps
86 CFG_RUSTC_FLAGS += --time-passes
88 ifdef TIME_LLVM_PASSES
89 CFG_RUSTC_FLAGS += --time-llvm-passes
95 # platform-specific auto-configuration
96 include $(CFG_SRC_DIR)/mk/platform.mk
98 # Run the stage1/2 compilers under valgrind
99 ifdef VALGRIND_COMPILE
100 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
102 CFG_VALGRIND_COMPILE :=
105 CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
106 CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
107 CFG_CORELIB :=$(call CFG_LIB_NAME,core)
108 CFG_STDLIB :=$(call CFG_LIB_NAME,std)
109 CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
111 STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
112 CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
113 LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
115 # version-string calculation
116 CFG_GIT_DIR := $(CFG_SRC_DIR).git
117 CFG_VERSION = prerelease
118 ifneq ($(wildcard $(CFG_GIT)),)
119 ifneq ($(wildcard $(CFG_GIT_DIR)),)
120 CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
121 --pretty=format:'(%h %ci)')
125 ifdef CFG_DISABLE_VALGRIND
126 $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
129 ifdef CFG_BAD_VALGRIND
130 $(info cfg: disabling valgrind due to its unreliability on this platform)
135 ifeq ($(CFG_MAKEINFO),)
136 $(info cfg: no makeinfo found, omitting doc/rust.html)
138 DOCS += doc/rust.html
141 ifeq ($(CFG_TEXI2PDF),)
142 $(info cfg: no texi2pdf found, omitting doc/rust.pdf)
145 $(info cfg: no tex found, omitting doc/rust.pdf)
151 ifeq ($(CFG_NATURALDOCS),)
152 $(info cfg: no naturaldocs found, omitting library doc build)
154 DOCS += doc/core/index.html doc/std/index.html
157 ifdef CFG_DISABLE_DOCS
158 $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
162 ######################################################################
163 # Target-and-rule "utility variables"
164 ######################################################################
175 X := $(CFG_EXE_SUFFIX)
177 # Look in doc and src dirs.
178 VPATH := $(S)doc $(S)src
180 # "Source" files we generate in builddir along the way.
183 # Delete the built-in rules.
191 ######################################################################
192 # Core library variables
193 ######################################################################
195 CORELIB_CRATE := $(S)src/libcore/core.rc
196 CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
197 core.rc *.rs */*.rs))
199 ######################################################################
200 # Standard library variables
201 ######################################################################
203 STDLIB_CRATE := $(S)src/libstd/std.rc
204 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
207 ######################################################################
208 # rustc crate variables
209 ######################################################################
211 COMPILER_CRATE := $(S)src/comp/rustc.rc
212 COMPILER_INPUTS := $(filter-out $(S)src/comp/driver/rustc.rs, \
213 $(wildcard $(addprefix $(S)src/comp/, \
214 rustc.rc *.rs */*.rs */*/*.rs)))
216 RUSTC_INPUTS := $(S)src/comp/driver/rustc.rs
218 ######################################################################
220 ######################################################################
223 LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser
226 # The configure script defines these variables with the target triples
227 # separated by Z. This defines new ones with the expected format.
228 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
229 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
231 # Any rules that depend on LLVM should depend on LLVM_CONFIG
232 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X)
233 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X)
234 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
235 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
236 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
237 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
238 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
239 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
240 LLVM_CXXFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags)
241 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
243 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X)
244 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)
248 $(foreach target,$(CFG_TARGET_TRIPLES), \
249 $(eval $(call DEF_LLVM_VARS,$(target))))
251 ######################################################################
252 # Exports for sub-utilities
253 ######################################################################
255 # Note that any variable that re-configure should pick up needs to be
261 export CFG_HOST_TRIPLE
263 export CFG_ENABLE_MINGW_CROSS
266 ######################################################################
268 ######################################################################
270 ######################################################################
271 # Per-stage targets and runner
272 ######################################################################
275 # $(1) is the stage number
276 # $(2) is the target triple
277 # $(3) is the host triple
279 # Destinations of artifacts for the host compiler
280 HROOT$(1)_H_$(3) = $(3)/stage$(1)
281 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
282 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/lib
284 # Destinations of artifacts for target architectures
285 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
286 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
287 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
289 # The name of the core and standard libraries used by rustc
290 ifdef CFG_DISABLE_SHAREDSTD
291 HCORELIB_DEFAULT$(1)_H_$(3) = \
292 $$(HLIB$(1)_H_$(3))/libcore.rlib
293 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
294 $$(TLIB$(1)_T_$(2)_H_$(3))/libcore.rlib
296 HSTDLIB_DEFAULT$(1)_H_$(3) = \
297 $$(HLIB$(1)_H_$(3))/libstd.rlib
298 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
299 $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
301 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
302 $$(HLIB$(1)_H_$(3))/librustc.rlib
303 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
304 $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
306 HCORELIB_DEFAULT$(1)_H_$(3) = \
307 $$(HLIB$(1)_H_$(3))/$(CFG_CORELIB)
308 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
309 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB)
311 HSTDLIB_DEFAULT$(1)_H_$(3) = \
312 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB)
313 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
314 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB)
316 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
317 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC)
318 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
319 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC)
322 # Preqrequisites for using the stageN compiler
324 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
325 $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \
326 $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \
327 $$(HCORELIB_DEFAULT$(1)_H_$(3)) \
328 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
329 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
332 # Prerequisites for using the stageN compiler to build target artifacts
333 TSREQ$(1)_T_$(2)_H_$(3) = \
334 $$(HSREQ$(1)_H_$(3)) \
335 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME) \
336 $$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.bc \
337 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
339 # Prerequisites for complete stageN targets
340 SREQ$(1)_T_$(2)_H_$(3) = \
341 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
342 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
343 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
344 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
347 # Don't run the the stage0 compiler under valgrind - that ship has sailed
348 CFG_VALGRIND_COMPILE$(1) =
350 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
353 STAGE$(1)_T_$(2)_H_$(3) := \
354 $$(Q)$$(call CFG_RUN_TARG,$(1), \
355 $$(CFG_VALGRIND_COMPILE$(1)) \
356 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
357 $$(CFG_RUSTC_FLAGS) --target=$(2))
359 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
360 $$(Q)$$(call CFG_RUN_TARG,$(1), \
362 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
363 $$(CFG_RUSTC_FLAGS) --target=$(2))
367 $(foreach build,$(CFG_TARGET_TRIPLES), \
368 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
369 $(eval $(foreach stage,$(STAGES), \
370 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
372 ######################################################################
375 # Builds a functional Rustc for the given host.
376 ######################################################################
378 define DEF_RUSTC_STAGE_TARGET
379 # $(1) == architecture
382 rustc-stage$(2)-H-$(1): \
383 $$(foreach target,$$(CFG_TARGET_TRIPLES), \
384 $$(SREQ$(2)_T_$$(target)_H_$(1)))
388 $(foreach host,$(CFG_TARGET_TRIPLES), \
389 $(eval $(foreach stage,1 2 3, \
390 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
392 rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
393 rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
394 rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
396 define DEF_RUSTC_TARGET
397 # $(1) == architecture
399 rustc-H-$(1): rustc-stage3-H-$(1)
402 $(foreach host,$(CFG_TARGET_TRIPLES), \
403 $(eval $(call DEF_RUSTC_TARGET,$(host))))
405 rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
406 rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
407 rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
408 rustc: rustc-H-$(CFG_HOST_TRIPLE)
410 rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
412 ######################################################################
414 ######################################################################
418 ifneq ($(CFG_IN_TRANSITION),)
420 CFG_INFO := $(info cfg:)
421 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
422 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
423 CFG_INFO := $(info cfg:)
425 all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) $(DOCS)
430 $(foreach target,$(CFG_TARGET_TRIPLES), \
431 $(SREQ3_T_$(target)_H_$(CFG_HOST_TRIPLE)))
432 FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
433 CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
434 RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
436 all: rustc $(GENERATED) $(DOCS) $(FUZZ) $(CARGO) $(RUSTDOC)
441 ######################################################################
443 ######################################################################
445 ifndef CFG_DISABLE_MANAGE_SUBMODULES
446 # This is a pretty expensive operation but I don't see any way to avoid it
447 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
452 ifeq ($(NEED_GIT_RECONFIG),0)
454 # If the submodules have changed then always execute config.mk
458 config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
459 @$(call E, cfg: reconfiguring)
460 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
463 ######################################################################
464 # Primary-target makefiles
465 ######################################################################
467 include $(CFG_SRC_DIR)/mk/target.mk
468 include $(CFG_SRC_DIR)/mk/host.mk
469 include $(CFG_SRC_DIR)/mk/stage0.mk
470 include $(CFG_SRC_DIR)/mk/rt.mk
471 include $(CFG_SRC_DIR)/mk/rustllvm.mk
472 include $(CFG_SRC_DIR)/mk/autodep.mk
473 include $(CFG_SRC_DIR)/mk/tools.mk
474 include $(CFG_SRC_DIR)/mk/docs.mk
475 include $(CFG_SRC_DIR)/mk/llvm.mk
477 ######################################################################
478 # Secondary makefiles, conditionalized for speed
479 ######################################################################
481 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
482 $(findstring check,$(MAKECMDGOALS)) \
483 $(findstring test,$(MAKECMDGOALS)) \
484 $(findstring tidy,$(MAKECMDGOALS)) \
485 $(findstring clean,$(MAKECMDGOALS))),)
486 CFG_INFO := $(info cfg: including dist rules)
487 include $(CFG_SRC_DIR)/mk/dist.mk
490 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
491 $(findstring clean,$(MAKECMDGOALS))),)
492 CFG_INFO := $(info cfg: including snap rules)
493 include $(CFG_SRC_DIR)/mk/snap.mk
496 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
497 CFG_INFO := $(info cfg: including reformat rules)
498 include $(CFG_SRC_DIR)/mk/pp.mk
501 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
502 $(findstring test,$(MAKECMDGOALS)) \
503 $(findstring perf,$(MAKECMDGOALS)) \
504 $(findstring tidy,$(MAKECMDGOALS))),)
505 CFG_INFO := $(info cfg: including test rules)
506 include $(CFG_SRC_DIR)/mk/tests.mk
509 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
510 CFG_INFO := $(info cfg: including perf rules)
511 include $(CFG_SRC_DIR)/mk/perf.mk
514 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
515 CFG_INFO := $(info cfg: including clean rules)
516 include $(CFG_SRC_DIR)/mk/clean.mk
519 ifneq ($(findstring install,$(MAKECMDGOALS)),)
520 CFG_INFO := $(info cfg: including install rules)
521 include $(CFG_SRC_DIR)/mk/install.mk
524 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
525 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
526 CFG_INFO := $(info cfg: including ctags rules)
527 include $(CFG_SRC_DIR)/mk/ctags.mk