]> git.lizzy.rs Git - rust.git/blob - Makefile.in
Register new snapshots
[rust.git] / Makefile.in
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.
4 #
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.
10
11 # An explanation of how the build is structured:
12 #
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.
19 #
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.
24 #
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
28 # architectures.
29 #
30 # The directory layout for a stage is intended to match the layout
31 # of the installed compiler, and looks like the following:
32 #
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
40 #
41 # A note about host libraries:
42 #
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.
49 #
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.
52 #
53 # Admittedly this is a little convoluted.
54
55 STAGES = 0 1 2 3
56
57 ######################################################################
58 # Residual auto-configuration
59 ######################################################################
60
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))
65
66 include config.mk
67
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.
70 ALL_OBJ_FILES :=
71
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))
75
76 ifneq ($(MAKE_RESTARTS),)
77 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
78 endif
79
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))
83
84 ifneq ($(wildcard $(NON_BUILD_HOST)),)
85 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
86 endif
87 ifneq ($(wildcard $(NON_BUILD_TARGET)),)
88 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
89 endif
90
91 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
92 CFG_GCCISH_CFLAGS :=
93 CFG_GCCISH_LINK_FLAGS :=
94
95 ifdef CFG_DISABLE_OPTIMIZE
96   $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
97   CFG_RUSTC_FLAGS +=
98 else
99   # The rtopt cfg turns off runtime sanity checks
100   CFG_RUSTC_FLAGS += -O --cfg rtopt
101 endif
102
103 ifdef CFG_DISABLE_DEBUG
104   CFG_RUSTC_FLAGS += --cfg ndebug
105   CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
106 else
107   $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
108   CFG_RUSTC_FLAGS += --cfg debug
109   CFG_GCCISH_CFLAGS += -DRUST_DEBUG
110 endif
111
112 ifdef SAVE_TEMPS
113   CFG_RUSTC_FLAGS += --save-temps
114 endif
115 ifdef ASM_COMMENTS
116   CFG_RUSTC_FLAGS += -Z asm-comments
117 endif
118 ifdef TIME_PASSES
119   CFG_RUSTC_FLAGS += -Z time-passes
120 endif
121 ifdef TIME_LLVM_PASSES
122   CFG_RUSTC_FLAGS += -Z time-llvm-passes
123 endif
124 ifdef TRACE
125   CFG_RUSTC_FLAGS += -Z trace
126 endif
127 ifndef DEBUG_BORROWS
128   RUSTFLAGS_STAGE0 += -Z no-debug-borrows
129   RUSTFLAGS_STAGE1 += -Z no-debug-borrows
130   RUSTFLAGS_STAGE2 += -Z no-debug-borrows
131 endif
132
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.
137 RUSTFLAGS_STAGE0 += -Z prefer-dynamic
138 RUSTFLAGS_STAGE1 += -Z prefer-dynamic
139 RUSTFLAGS_STAGE2 += -Z prefer-dynamic
140 RUSTFLAGS_STAGE3 += -Z prefer-dynamic
141
142 # platform-specific auto-configuration
143 include $(CFG_SRC_DIR)mk/platform.mk
144
145 # Run the stage1/2 compilers under valgrind
146 ifdef VALGRIND_COMPILE
147   CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
148 else
149   CFG_VALGRIND_COMPILE :=
150 endif
151
152 # version-string calculation
153 CFG_GIT_DIR := $(CFG_SRC_DIR).git
154 CFG_RELEASE = 0.9-pre
155 CFG_VERSION = $(CFG_RELEASE)
156 # windows exe's need numeric versions - don't use anything but
157 # numbers and dots here
158 CFG_VERSION_WIN = 0.9
159
160 # since $(CFG_GIT) may contain spaces (especially on Windows),
161 # we need to escape them. (" " to r"\ ")
162 # Note that $(subst ...) ignores space after `subst`,
163 # so we use a hack: define $(SPACE) which contains space character.
164 SPACE :=
165 SPACE +=
166 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT))),)
167 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
168     CFG_VERSION += $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 \
169                      --pretty=format:'(%h %ci)')
170     CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
171 endif
172 endif
173
174 ifdef CFG_ENABLE_VALGRIND
175   $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
176 else
177   CFG_VALGRIND :=
178 endif
179 ifdef CFG_BAD_VALGRIND
180   $(info cfg: disabling valgrind due to its unreliability on this platform)
181   CFG_VALGRIND :=
182 endif
183
184
185 ######################################################################
186 # Target-and-rule "utility variables"
187 ######################################################################
188
189 ifdef VERBOSE
190   Q :=
191   E =
192 else
193   Q := @
194   E = echo $(1)
195 endif
196
197 S := $(CFG_SRC_DIR)
198
199 define DEF_X
200 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
201 endef
202 $(foreach target,$(CFG_TARGET),\
203   $(eval $(call DEF_X,$(target))))
204
205 # Look in doc and src dirs.
206 VPATH := $(S)doc $(S)src
207
208 # "Source" files we generate in builddir along the way.
209 GENERATED :=
210
211 # Delete the built-in rules.
212 .SUFFIXES:
213 %:: %,v
214 %:: RCS/%,v
215 %:: RCS/%
216 %:: s.%
217 %:: SCCS/s.%
218
219
220 ######################################################################
221 # Crates
222 ######################################################################
223
224 define DEF_LIBS
225
226 CFG_RUNTIME_$(1) :=$(call CFG_STATIC_LIB_NAME_$(1),rustrt)
227 CFG_RUSTLLVM_$(1) :=$(call CFG_LIB_NAME_$(1),rustllvm)
228 CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std)
229 CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra)
230 CFG_LIBRUSTC_$(1) :=$(call CFG_LIB_NAME_$(1),rustc)
231 CFG_LIBSYNTAX_$(1) :=$(call CFG_LIB_NAME_$(1),syntax)
232 CFG_LIBRUSTPKG_$(1) :=$(call CFG_LIB_NAME_$(1),rustpkg)
233 CFG_LIBRUSTDOC_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc)
234 CFG_LIBRUSTUV_$(1) :=$(call CFG_LIB_NAME_$(1),rustuv)
235
236 EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra)
237 STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std)
238 LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc)
239 LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax)
240 LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg)
241 LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc)
242 LIBRUSTUV_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustuv)
243 EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra)
244 STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std)
245 LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc)
246 LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax)
247 LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg)
248 LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc)
249 LIBRUSTUV_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustuv)
250
251 EXTRALIB_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,extra)
252 STDLIB_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,std)
253 LIBRUSTUV_RGLOB_$(1) :=$(call CFG_RLIB_GLOB,rustuv)
254
255 endef
256
257 # $(1) is the path for directory to match against
258 # $(2) is the glob to use in the match
259 # $(3) is filename (usually the target being created) to filter out from match
260 #      (i.e. filename is not out-of-date artifact from prior Rust version/build)
261 #
262 # Note that a common bug is to accidentally construct the glob denoted
263 # by $(2) with a space character prefix, which invalidates the
264 # construction $(1)$(2).
265 define CHECK_FOR_OLD_GLOB_MATCHES_EXCEPT
266   $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(2)\' "libraries:" $$MATCHES; fi
267 endef
268
269 # Same interface as above, but deletes rather than just listing the files.
270 define REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT
271   $(Q)MATCHES="$(filter-out %$(3),$(wildcard $(1)/$(2)))"; if [ -n "$$MATCHES" ] ; then echo "warning: removing previous" \'$(2)\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
272 endef
273
274 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
275 # than in the macros above because it needs the result of running the
276 # `ls` command after other rules in the command list have run; the
277 # macro-expander for $(wildcard ...) would deliver its results too
278 # soon. (This is in contrast to the macros above, which are meant to
279 # be run at the outset of a command list in a rule.)
280 ifdef VERBOSE
281 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
282   @echo "info: now are following matches for" '$(2)' "libraries:"
283   @( cd $(1) && ( ls $(2) 2>/dev/null || true ) | grep -v $(3) || true )
284 endef
285 else
286 define LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
287 endef
288 endif
289
290 $(foreach target,$(CFG_TARGET),\
291   $(eval $(call DEF_LIBS,$(target))))
292
293 ######################################################################
294 # Standard library variables
295 ######################################################################
296
297 STDLIB_CRATE := $(S)src/libstd/lib.rs
298 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/,        \
299                                            *.rs */*.rs */*/*rs */*/*/*rs))
300
301 ######################################################################
302 # Extra library variables
303 ######################################################################
304
305 EXTRALIB_CRATE := $(S)src/libextra/lib.rs
306 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/,          \
307                                           *.rs */*.rs))
308
309 ######################################################################
310 # Rust UV library variables
311 ######################################################################
312
313 LIBRUSTUV_CRATE := $(S)src/librustuv/lib.rs
314 LIBRUSTUV_INPUTS := $(wildcard $(addprefix $(S)src/librustuv/,          \
315                                           *.rs */*.rs))
316
317 ######################################################################
318 # rustc crate variables
319 ######################################################################
320
321 COMPILER_CRATE := $(S)src/librustc/lib.rs
322 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/,      \
323                            *.rs */*.rs */*/*.rs */*/*/*.rs))
324
325 LIBSYNTAX_CRATE := $(S)src/libsyntax/lib.rs
326 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
327                            *.rs */*.rs */*/*.rs */*/*/*.rs))
328
329 DRIVER_CRATE := $(S)src/driver/driver.rs
330
331 ######################################################################
332 # LLVM macros
333 ######################################################################
334
335 # FIXME: x86-ism
336 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
337                 interpreter instrumentation
338
339 define DEF_LLVM_VARS
340 # The configure script defines these variables with the target triples
341 # separated by Z. This defines new ones with the expected format.
342 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
343 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
344
345 # Any rules that depend on LLVM should depend on LLVM_CONFIG
346 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
347 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
348 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
349 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
350 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
351 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
352 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
353 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
354 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
355 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
356 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
357 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
358
359 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
360 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
361
362 endef
363
364 $(foreach host,$(CFG_HOST), \
365  $(eval $(call DEF_LLVM_VARS,$(host))))
366
367 ######################################################################
368 # Exports for sub-utilities
369 ######################################################################
370
371 # Note that any variable that re-configure should pick up needs to be
372 # exported
373
374 export CFG_SRC_DIR
375 export CFG_BUILD_DIR
376 export CFG_VERSION
377 export CFG_VERSION_WIN
378 export CFG_BUILD
379 export CFG_LLVM_ROOT
380 export CFG_ENABLE_MINGW_CROSS
381 export CFG_PREFIX
382 export CFG_LIBDIR
383
384 ######################################################################
385 # Subprograms
386 ######################################################################
387
388 ######################################################################
389 # Per-stage targets and runner
390 ######################################################################
391
392 define SREQ
393 # $(1) is the stage number
394 # $(2) is the target triple
395 # $(3) is the host triple
396
397 # Destinations of artifacts for the host compiler
398 HROOT$(1)_H_$(3) = $(3)/stage$(1)
399 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
400 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
401
402 # Destinations of artifacts for target architectures
403 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
404 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
405 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
406
407 # The name of the standard and extra libraries used by rustc
408 HSTDLIB_DEFAULT$(1)_H_$(3) = \
409   $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB_$(3))
410 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
411   $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2))
412
413 HEXTRALIB_DEFAULT$(1)_H_$(3) = \
414   $$(HLIB$(1)_H_$(3))/$(CFG_EXTRALIB_$(3))
415 TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
416   $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
417
418 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
419   $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC_$(3))
420 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
421   $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2))
422
423 HLIBRUSTUV_DEFAULT$(1)_H_$(3) = \
424   $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTUV_$(3))
425 TLIBRUSTUV_DEFAULT$(1)_T_$(2)_H_$(3) = \
426   $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2))
427
428 # Preqrequisites for using the stageN compiler
429 HSREQ$(1)_H_$(3) = \
430         $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
431         $$(HLIB$(1)_H_$(3))/$(CFG_RUNTIME_$(3)) \
432         $$(HLIB$(1)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
433         $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
434         $$(HEXTRALIB_DEFAULT$(1)_H_$(3)) \
435         $$(HLIBSYNTAX_DEFAULT$(1)_H_$(3)) \
436         $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
437         $$(HLIBRUSTUV_DEFAULT$(1)_H_$(3)) \
438         $$(MKFILE_DEPS)
439
440 # Prerequisites for using the stageN compiler to build target artifacts
441 TSREQ$(1)_T_$(2)_H_$(3) = \
442         $$(HSREQ$(1)_H_$(3)) \
443         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) \
444         $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
445
446 # Prerequisites for a working stageN compiler and libraries, for a specific target
447 SREQ$(1)_T_$(2)_H_$(3) = \
448         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
449         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
450         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) \
451         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2))
452
453 # Prerequisites for a working stageN compiler and libraries, for a specific target
454 CSREQ$(1)_T_$(2)_H_$(3) = \
455         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
456         $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
457         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
458         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \
459         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \
460         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
461         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))  \
462         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2))  \
463         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \
464         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \
465         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \
466         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTUV_$(2))
467
468 ifeq ($(1),0)
469 # Don't run the the stage0 compiler under valgrind - that ship has sailed
470 CFG_VALGRIND_COMPILE$(1) =
471 else
472 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
473 endif
474
475 # Add RUSTFLAGS_STAGEN values to the build command
476 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
477
478 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
479
480 # Pass --cfg stage0 only for the build->host part of stage0;
481 # if you're building a cross config, the host->* parts are
482 # effectively stage1, since it uses the just-built stage0.
483 ifeq ($(1),0)
484 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
485 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
486 endif
487 endif
488
489 STAGE$(1)_T_$(2)_H_$(3) :=                                              \
490         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
491                 $$(CFG_VALGRIND_COMPILE$(1))                    \
492                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
493                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
494                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
495                 $$(RUSTC_FLAGS_$(2))
496
497 PERF_STAGE$(1)_T_$(2)_H_$(3) :=                                 \
498         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
499                 $$(CFG_PERF_TOOL)                                               \
500                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
501                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
502                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
503                 $$(RUSTC_FLAGS_$(2))
504
505 endef
506
507 $(foreach build,$(CFG_HOST), \
508  $(eval $(foreach target,$(CFG_TARGET), \
509   $(eval $(foreach stage,$(STAGES), \
510    $(eval $(call SREQ,$(stage),$(target),$(build))))))))
511
512 ######################################################################
513 # rustc-H-targets
514 #
515 # Builds a functional Rustc for the given host.
516 ######################################################################
517
518 define DEF_RUSTC_STAGE_TARGET
519 # $(1) == architecture
520 # $(2) == stage
521
522 rustc-stage$(2)-H-$(1):                                                 \
523         $$(foreach target,$$(CFG_TARGET),       \
524                 $$(SREQ$(2)_T_$$(target)_H_$(1)))
525
526 endef
527
528 $(foreach host,$(CFG_HOST),                                                     \
529  $(eval $(foreach stage,1 2 3,                                                                  \
530   $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
531
532 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
533 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
534 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
535
536 define DEF_RUSTC_TARGET
537 # $(1) == architecture
538
539 rustc-H-$(1): rustc-stage2-H-$(1)
540 endef
541
542 $(foreach host,$(CFG_TARGET),                   \
543  $(eval $(call DEF_RUSTC_TARGET,$(host))))
544
545 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
546 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
547 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
548 rustc: rustc-H-$(CFG_BUILD)
549
550 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
551
552 ######################################################################
553 # Entrypoint rule
554 ######################################################################
555
556 .DEFAULT_GOAL := all
557
558 ifneq ($(CFG_IN_TRANSITION),)
559
560 CFG_INFO := $(info cfg:)
561 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
562 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
563 CFG_INFO := $(info cfg:)
564
565 #XXX This is surely busted
566 all: $(SREQ1$(CFG_BUILD)) $(GENERATED) docs
567
568 else
569
570 define ALL_TARGET_N
571 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
572 # This is a host
573 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
574 else
575 # This is a target only
576 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
577 endif
578 endef
579
580 $(foreach target,$(CFG_TARGET), \
581  $(foreach host,$(CFG_HOST), \
582  $(eval $(call ALL_TARGET_N,$(target),$(host)))))
583
584 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
585         $(foreach host,$(CFG_HOST), \
586  all-target-$(target)-host-$(host)))
587
588 all: $(ALL_TARGET_RULES) $(GENERATED) docs
589
590 endif
591
592
593 ######################################################################
594 # Re-configuration
595 ######################################################################
596
597 ifndef CFG_DISABLE_MANAGE_SUBMODULES
598 # This is a pretty expensive operation but I don't see any way to avoid it
599 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
600 else
601 NEED_GIT_RECONFIG=0
602 endif
603
604 ifeq ($(NEED_GIT_RECONFIG),0)
605 else
606 # If the submodules have changed then always execute config.mk
607 .PHONY: config.stamp
608 endif
609
610 Makefile config.mk: config.stamp
611
612 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
613         @$(call E, cfg: reconfiguring)
614         $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
615
616
617 ######################################################################
618 # Primary-target makefiles
619 ######################################################################
620
621 # Issue #9531: If you change the order of any of the following (or add
622 # new definitions), make sure definitions always precede their uses,
623 # especially for the dependency lists of recipes.
624
625 include $(CFG_SRC_DIR)mk/rt.mk
626 include $(CFG_SRC_DIR)mk/target.mk
627 include $(CFG_SRC_DIR)mk/host.mk
628 include $(CFG_SRC_DIR)mk/stage0.mk
629 include $(CFG_SRC_DIR)mk/rustllvm.mk
630 include $(CFG_SRC_DIR)mk/tools.mk
631 include $(CFG_SRC_DIR)mk/docs.mk
632 include $(CFG_SRC_DIR)mk/llvm.mk
633
634 ######################################################################
635 # Secondary makefiles, conditionalized for speed
636 ######################################################################
637
638 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS))   \
639                $(findstring check,$(MAKECMDGOALS))  \
640                $(findstring test,$(MAKECMDGOALS))   \
641                $(findstring tidy,$(MAKECMDGOALS))   \
642                $(findstring clean,$(MAKECMDGOALS))),)
643   CFG_INFO := $(info cfg: including dist rules)
644   include $(CFG_SRC_DIR)mk/dist.mk
645 endif
646
647 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))   \
648                $(findstring clean,$(MAKECMDGOALS))),)
649   CFG_INFO := $(info cfg: including snap rules)
650   include $(CFG_SRC_DIR)mk/snap.mk
651 endif
652
653 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
654   CFG_INFO := $(info cfg: including reformat rules)
655   include $(CFG_SRC_DIR)mk/pp.mk
656 endif
657
658 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
659                $(findstring test,$(MAKECMDGOALS))  \
660                $(findstring perf,$(MAKECMDGOALS))  \
661                $(findstring tidy,$(MAKECMDGOALS))),)
662   CFG_INFO := $(info cfg: including test rules)
663   include $(CFG_SRC_DIR)mk/tests.mk
664 endif
665
666 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
667   CFG_INFO := $(info cfg: including perf rules)
668   include $(CFG_SRC_DIR)mk/perf.mk
669 endif
670
671 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
672   CFG_INFO := $(info cfg: including clean rules)
673   include $(CFG_SRC_DIR)mk/clean.mk
674 endif
675
676 ifneq ($(findstring install,$(MAKECMDGOALS)),)
677   CFG_INFO := $(info cfg: including install rules)
678   include $(CFG_SRC_DIR)mk/install.mk
679 endif
680
681 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
682                $(findstring TAGS.vi,$(MAKECMDGOALS))),)
683   CFG_INFO := $(info cfg: including ctags rules)
684   include $(CFG_SRC_DIR)mk/ctags.mk
685 endif
686
687 # Find all of the .d files and include them to add information about
688 # header file dependencies.
689 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
690 -include $(ALL_DEP_FILES)