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 # Greetings, adventurer! The Rust Build System is at your service.
15 # Whether you want a genuine copy of `rustc`, access to the latest and
16 # most authoritative Rust documentation, or even to investigate the
17 # most intimate workings of the compiler itself, you've come to the
18 # right place. Let's see what's on the menu.
20 # First, start with one of these build targets:
22 # * all - The default. Build a complete, bootstrapped compiler.
23 # `rustc` will be in `${target-triple}/stage2/bin/`. Run it
24 # directly from the build directory if you like. This also
25 # comes with docs in `doc/`.
27 # * check - Run the complete test suite
29 # * clean - Clean the build repertory. It is advised to run this
30 # command if you want to build Rust again, after an update
31 # of the git repository.
33 # * install - Install Rust. Note that installation is not necessary
34 # to use the compiler.
36 # * uninstall - Uninstall the binaries
38 # For tips on working with The Rust Build System, just:
50 # # The Rust Build System Tip Line
52 # There are a bazillion different targets you might want to build. Here
55 # * docs - Build gobs of HTML documentation and put it into `doc/`
56 # * check-$(crate) - Test a crate, e.g. `check-std`
57 # * check-ref - Run the language reference tests
58 # * check-docs - Test the documentation examples
59 # * check-stage$(stage)-$(crate) - Test a crate in a specific stage
60 # * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
61 # * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
63 # Then mix in some of these environment variables to harness the
64 # ultimate power of The Rust Build System.
66 # * `VERBOSE=1` - Print all commands. Use this to see what's going on.
67 # * `RUSTFLAGS=...` - Add compiler flags to all `rustc` invocations
68 # * `JEMALLOC_FLAGS=...` - Pass flags to jemalloc's configure script
70 # * `TESTNAME=...` - Specify the name of tests to run
71 # * `CHECK_IGNORED=1` - Run normally-ignored tests
72 # * `PLEASE_BENCH=1` - Run crate benchmarks (enable `--bench` flag)
74 # * `CFG_ENABLE_VALGRIND=1` - Run tests under valgrind
75 # * `VALGRIND_COMPILE=1` - Run the compiler itself under valgrind
76 # (may require `CFG_ENABLE_VALGRIND`)
78 # * `NO_REBUILD=1` - Don't rebootstrap when testing std
79 # (and possibly other crates)
80 # * `NO_MKFILE_DEPS=1` - Don't rebuild for modified .mk files
82 # * `SAVE_TEMPS=1` - Use `--save-temps` flag on all `rustc` invocations
83 # * `ASM_COMMENTS=1` - Use `-Z asm-comments`
84 # * `TIME_PASSES=1` - Use `-Z time-passes`
85 # * `TIME_LLVM_PASSES=1` - Use `-Z time-llvm-passes`
86 # * `TRACE=1` - Use `-Z trace`
88 # # Rust recipes for build system success
90 # // Modifying libstd? Use this comment to run unit tests just on your change
91 # make check-stage1-std NO_REBUILD=1 NO_BENCH=1
93 # // Added a run-pass test? Use this to test running your test
94 # make check-stage1-rpass TESTNAME=my-shiny-new-test
96 # // Having trouble figuring out which test is failing? Turn off parallel tests
97 # make check-stage1-std RUST_TEST_TASKS=1
99 # This is hardly all there is to know of The Rust Build System's
100 # mysteries. The tale continues on the wiki[1].
102 # [1]: https://github.com/rust-lang/rust/wiki/Note-testsuite
104 # If you really feel like getting your hands dirty, then:
106 # run `make nitty-gritty`
112 # # The Rust Build System
114 # Gosh I wish there was something useful here (TODO).
116 # # An (old) explanation of how the build is structured:
118 # *Note: Hey, like, this is probably inaccurate, and is definitely
119 # an outdated and insufficient explanation of the remarkable
120 # Rust Build System.*
122 # There are multiple build stages (0-3) needed to verify that the
123 # compiler is properly self-hosting. Each stage is divided between
124 # 'host' artifacts and 'target' artifacts, where the stageN host
125 # compiler builds artifacts for 1 or more stageN target architectures.
126 # Once the stageN target compiler has been built for the host
127 # architecture it is promoted (copied) to a stageN+1 host artifact.
129 # The stage3 host compiler is a compiler that successfully builds
130 # itself and should (in theory) be bitwise identical to the stage2
131 # host compiler. The process is bootstrapped using a stage0 host
132 # compiler downloaded from a previous snapshot.
134 # At no time should stageN artifacts be interacting with artifacts
135 # from other stages. For consistency, we use the 'promotion' logic
136 # for all artifacts, even those that don't make sense on non-host
139 # The directory layout for a stage is intended to match the layout
140 # of the installed compiler, and looks like the following:
142 # stageN - this is the system root, corresponding to, e.g. /usr
143 # bin - binaries compiled for the host
144 # lib - libraries used by the host compiler
145 # rustlib - rustc's own place to organize libraries
146 # $(target) - target-specific artifacts
147 # bin - binaries for target architectures
148 # lib - libraries for target architectures
150 # A note about host libraries:
152 # The only libraries that get promoted to stageN/lib are those needed
153 # by rustc. In general, rust programs, even those compiled for the
154 # host architecture will use libraries from the target
155 # directories. This gives rust some freedom to experiment with how
156 # libraries are managed and versioned without polluting the common
157 # areas of the filesystem.
159 # General rust binaries may still live in the host bin directory; they
160 # will just link against the libraries in the target lib directory.
162 # Admittedly this is a little convoluted.
167 ######################################################################
169 ######################################################################
171 # Issue #9531: If you change the order of any of the following (or add
172 # new definitions), make sure definitions always precede their uses,
173 # especially for the dependency lists of recipes.
175 # First, load the variables exported by the configure script
178 # Just a few macros used everywhere
179 include $(CFG_SRC_DIR)mk/util.mk
180 # Reconfiguring when the makefiles or submodules change
181 include $(CFG_SRC_DIR)mk/reconfig.mk
182 # All crates and their dependencies
183 include $(CFG_SRC_DIR)mk/crates.mk
184 # Various bits of setup, common macros, and top-level rules
185 include $(CFG_SRC_DIR)mk/main.mk
186 # C and assembly components that are not LLVM
187 include $(CFG_SRC_DIR)mk/rt.mk
188 # Rules for crates in the target directories
189 include $(CFG_SRC_DIR)mk/target.mk
190 # Rules for crates in the host directories
191 include $(CFG_SRC_DIR)mk/host.mk
192 # Special rules for bootstrapping stage0
193 include $(CFG_SRC_DIR)mk/stage0.mk
194 # Rust-specific LLVM extensions
195 include $(CFG_SRC_DIR)mk/rustllvm.mk
197 include $(CFG_SRC_DIR)mk/docs.mk
199 include $(CFG_SRC_DIR)mk/llvm.mk
200 # Rules for installing debugger scripts
201 include $(CFG_SRC_DIR)mk/debuggers.mk
203 ######################################################################
204 # Secondary makefiles, conditionalized for speed
205 ######################################################################
208 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
209 $(findstring clean,$(MAKECMDGOALS))),)
210 CFG_INFO := $(info cfg: including snap rules)
211 include $(CFG_SRC_DIR)mk/snap.mk
215 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
216 $(findstring test,$(MAKECMDGOALS)) \
217 $(findstring perf,$(MAKECMDGOALS)) \
218 $(findstring tidy,$(MAKECMDGOALS))),)
219 CFG_INFO := $(info cfg: including test rules)
220 include $(CFG_SRC_DIR)mk/tests.mk
221 include $(CFG_SRC_DIR)mk/grammar.mk
224 # Performance and benchmarking
225 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
226 CFG_INFO := $(info cfg: including perf rules)
227 include $(CFG_SRC_DIR)mk/perf.mk
230 # Copy all the distributables to another directory for binary install
231 ifneq ($(strip $(findstring prepare,$(MAKECMDGOALS)) \
232 $(findstring dist,$(MAKECMDGOALS)) \
233 $(findstring install,$(MAKECMDGOALS))),)
234 CFG_INFO := $(info cfg: including prepare rules)
235 include $(CFG_SRC_DIR)mk/prepare.mk
238 # Source and binary distribution artifacts
239 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
240 $(findstring install,$(MAKECMDGOALS)) \
241 $(findstring clean,$(MAKECMDGOALS))),)
242 CFG_INFO := $(info cfg: including dist rules)
243 include $(CFG_SRC_DIR)mk/dist.mk
246 # (Unix) Installation from the build directory
247 ifneq ($(findstring install,$(MAKECMDGOALS)),)
248 CFG_INFO := $(info cfg: including install rules)
249 include $(CFG_SRC_DIR)mk/install.mk
253 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
254 CFG_INFO := $(info cfg: including clean rules)
255 include $(CFG_SRC_DIR)mk/clean.mk
259 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
260 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
261 CFG_INFO := $(info cfg: including ctags rules)
262 include $(CFG_SRC_DIR)mk/ctags.mk
265 # Find all of the .d files and include them to add information about
266 # header file dependencies.
267 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
268 -include $(ALL_DEP_FILES)