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