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