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.
13 # # The Rust Build System
15 # Start with these these build targets:
17 # * all - The default rule. Builds a complete stage2 compiler, std,
18 # and extra for all hosts and targets
19 # * docs - Generate HTML documentation for the std and extra libraries
20 # from source code comments
21 # * rustc - The stage 2 compiler for the build platform with standard
26 # * check-stage1-$(crate) - Run tests for a crate, e.g. `check-stage1-std`
27 # * check-stage1-rpass - Run the language tests
28 # * check-docs - Run the doc tests
30 # Then mix in some of these environment variables to harness the
31 # ultimate power of Rust Build System.
33 # * `VERBOSE=1` - Print all commands. Use this to see what's going on.
34 # * `RUSTFLAGS=...` - Add compiler flags to all `rustc` invocations
35 # * `CFG_ENABLE_VALGRIND=1` - Run tests under valgrind
36 # * `VALGRIND_COMPILE=1` - Run the compiler itself under valgrind
37 # (may require `CFG_ENABLE_VALGRIND`)
38 # * `NO_REBUILD=1` - Don't rebootstrap when testing std
39 # (and possibly other crates)
40 # * `SAVE_TEMPS=1` - Use `--save-temps` flag on all `rustc` invocations
41 # * `ASM_COMMENTS=1` - Use `-Z asm-comments`
42 # * `TIME_PASSES=1` - Use `-Z time-passes`
43 # * `TIME_LLVM_PASSES=1` - Use `-Z time-llvm-passes`
44 # * `TRACE=1` - Use `-Z trace`
46 # This is hardly all there is to know of The Rust Build System's
47 # mysteries. Your journey continues on the wiki[1][2].
49 # [1]: https://github.com/mozilla/rust/wiki/Note-build-system
50 # [2]: https://github.com/mozilla/rust/wiki/Note-testsuite
54 # # An (old) explanation of how the build is structured:
56 # *Note: Hey, like, this is probably inaccurate, and is definitely
57 # an outdated and insufficient explanation of the remarkable
58 # and discomfiting Rust Build System.*
60 # There are multiple build stages (0-3) needed to verify that the
61 # compiler is properly self-hosting. Each stage is divided between
62 # 'host' artifacts and 'target' artifacts, where the stageN host
63 # compiler builds artifacts for 1 or more stageN target architectures.
64 # Once the stageN target compiler has been built for the host
65 # architecture it is promoted (copied) to a stageN+1 host artifact.
67 # The stage3 host compiler is a compiler that successfully builds
68 # itself and should (in theory) be bitwise identical to the stage2
69 # host compiler. The process is bootstrapped using a stage0 host
70 # compiler downloaded from a previous snapshot.
72 # At no time should stageN artifacts be interacting with artifacts
73 # from other stages. For consistency, we use the 'promotion' logic
74 # for all artifacts, even those that don't make sense on non-host
77 # The directory layout for a stage is intended to match the layout
78 # of the installed compiler, and looks like the following:
80 # stageN - this is the system root, corresponding to, e.g. /usr
81 # bin - binaries compiled for the host
82 # lib - libraries used by the host compiler
83 # rustlib - rustc's own place to organize libraries
84 # $(target) - target-specific artifacts
85 # bin - binaries for target architectures
86 # lib - libraries for target architectures
88 # A note about host libraries:
90 # The only libraries that get promoted to stageN/lib are those needed
91 # by rustc. In general, rust programs, even those compiled for the
92 # host architecture will use libraries from the target
93 # directories. This gives rust some freedom to experiment with how
94 # libraries are managed and versioned without polluting the common
95 # areas of the filesystem.
97 # General rust binaries may stil live in the host bin directory; they
98 # will just link against the libraries in the target lib directory.
100 # Admittedly this is a little convoluted.
102 ######################################################################
104 ######################################################################
106 # Issue #9531: If you change the order of any of the following (or add
107 # new definitions), make sure definitions always precede their uses,
108 # especially for the dependency lists of recipes.
110 # First, load the variables exported by the configure script
113 # Just a few macros used everywhere
114 include $(CFG_SRC_DIR)mk/util.mk
115 # All crates and their dependencies
116 include $(CFG_SRC_DIR)mk/crates.mk
117 # Reconfiguring when the makefiles or submodules change
118 include $(CFG_SRC_DIR)mk/reconfig.mk
119 # Various bits of setup, common macros, and top-level rules
120 include $(CFG_SRC_DIR)mk/main.mk
121 # C and assembly components that are not LLVM
122 include $(CFG_SRC_DIR)mk/rt.mk
123 # Rules for crates in the target directories
124 include $(CFG_SRC_DIR)mk/target.mk
125 # Rules for crates in the host directories
126 include $(CFG_SRC_DIR)mk/host.mk
127 # Special rules for bootstrapping stage0
128 include $(CFG_SRC_DIR)mk/stage0.mk
129 # Rust-specific LLVM extensions
130 include $(CFG_SRC_DIR)mk/rustllvm.mk
132 include $(CFG_SRC_DIR)mk/docs.mk
134 include $(CFG_SRC_DIR)mk/llvm.mk
136 ######################################################################
137 # Secondary makefiles, conditionalized for speed
138 ######################################################################
140 # Source and binary distribution artifacts
141 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
142 $(findstring check,$(MAKECMDGOALS)) \
143 $(findstring test,$(MAKECMDGOALS)) \
144 $(findstring tidy,$(MAKECMDGOALS)) \
145 $(findstring clean,$(MAKECMDGOALS))),)
146 CFG_INFO := $(info cfg: including dist rules)
147 include $(CFG_SRC_DIR)mk/dist.mk
151 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
152 $(findstring clean,$(MAKECMDGOALS))),)
153 CFG_INFO := $(info cfg: including snap rules)
154 include $(CFG_SRC_DIR)mk/snap.mk
158 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
159 $(findstring test,$(MAKECMDGOALS)) \
160 $(findstring perf,$(MAKECMDGOALS)) \
161 $(findstring tidy,$(MAKECMDGOALS))),)
162 CFG_INFO := $(info cfg: including test rules)
163 include $(CFG_SRC_DIR)mk/tests.mk
166 # Performance and benchmarking
167 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
168 CFG_INFO := $(info cfg: including perf rules)
169 include $(CFG_SRC_DIR)mk/perf.mk
173 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
174 CFG_INFO := $(info cfg: including clean rules)
175 include $(CFG_SRC_DIR)mk/clean.mk
178 # Installation from the build directory
179 ifneq ($(findstring install,$(MAKECMDGOALS)),)
180 CFG_INFO := $(info cfg: including install rules)
181 include $(CFG_SRC_DIR)mk/install.mk
185 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
186 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
187 CFG_INFO := $(info cfg: including ctags rules)
188 include $(CFG_SRC_DIR)mk/ctags.mk
191 # Find all of the .d files and include them to add information about
192 # header file dependencies.
193 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
194 -include $(ALL_DEP_FILES)