]> git.lizzy.rs Git - rust.git/blob - Makefile.in
auto merge of #7528 : indutny/rust/feature/memory-api, r=cmr
[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_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_HOST_TRIPLES))
74 NON_BUILD_TARGET_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_TARGET_TRIPLES))
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_TRIPLE))
81 CFG_INFO := $(info cfg: host triples $(CFG_HOST_TRIPLES))
82 CFG_INFO := $(info cfg: target triples $(CFG_TARGET_TRIPLES))
83
84 ifneq ($(wildcard $(NON_BUILD_HOST_TRIPLES)),)
85 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST_TRIPLES))
86 endif
87 ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
88 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
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   CFG_RUSTC_FLAGS += -O
100 endif
101
102 ifdef CFG_ENABLE_DEBUG
103   $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
104   CFG_RUSTC_FLAGS += --cfg debug
105   CFG_GCCISH_CFLAGS += -DRUST_DEBUG
106 else
107   CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
108 endif
109
110 ifdef SAVE_TEMPS
111   CFG_RUSTC_FLAGS += --save-temps
112 endif
113 ifdef ASM_COMMENTS
114   CFG_RUSTC_FLAGS += -Z asm-comments
115 endif
116 ifdef TIME_PASSES
117   CFG_RUSTC_FLAGS += -Z time-passes
118 endif
119 ifdef TIME_LLVM_PASSES
120   CFG_RUSTC_FLAGS += -Z time-llvm-passes
121 endif
122 ifdef TRACE
123   CFG_RUSTC_FLAGS += -Z trace
124 endif
125 ifndef DEBUG_BORROWS
126   RUSTFLAGS_STAGE1 += -Z no-debug-borrows
127   RUSTFLAGS_STAGE2 += -Z no-debug-borrows
128 endif
129
130 # platform-specific auto-configuration
131 include $(CFG_SRC_DIR)mk/platform.mk
132
133 # Run the stage1/2 compilers under valgrind
134 ifdef VALGRIND_COMPILE
135   CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
136 else
137   CFG_VALGRIND_COMPILE :=
138 endif
139
140 # version-string calculation
141 CFG_GIT_DIR := $(CFG_SRC_DIR).git
142 CFG_RELEASE = 0.8-pre
143 CFG_VERSION = $(CFG_RELEASE)
144 # windows exe's need numeric versions - don't use anything but
145 # numbers and dots here
146 CFG_VERSION_WIN = 0.8
147
148 ifneq ($(wildcard $(CFG_GIT)),)
149 ifneq ($(wildcard $(CFG_GIT_DIR)),)
150     CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
151                      --pretty=format:'(%h %ci)')
152     CFG_VER_HASH = $(shell git --git-dir=$(CFG_GIT_DIR) rev-parse HEAD)
153 endif
154 endif
155
156 ifdef CFG_ENABLE_VALGRIND
157   $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
158 else
159   CFG_VALGRIND :=
160 endif
161 ifdef CFG_BAD_VALGRIND
162   $(info cfg: disabling valgrind due to its unreliability on this platform)
163   CFG_VALGRIND :=
164 endif
165
166
167 ######################################################################
168 # Target-and-rule "utility variables"
169 ######################################################################
170
171 ifdef VERBOSE
172   Q :=
173   E =
174 else
175   Q := @
176   E = echo $(1)
177 endif
178
179 S := $(CFG_SRC_DIR)
180
181 define DEF_X
182 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
183 endef
184 $(foreach target,$(CFG_TARGET_TRIPLES),\
185   $(eval $(call DEF_X,$(target))))
186
187 # Look in doc and src dirs.
188 VPATH := $(S)doc $(S)src
189
190 # "Source" files we generate in builddir along the way.
191 GENERATED :=
192
193 # Delete the built-in rules.
194 .SUFFIXES:
195 %:: %,v
196 %:: RCS/%,v
197 %:: RCS/%
198 %:: s.%
199 %:: SCCS/s.%
200
201
202 ######################################################################
203 # Crates
204 ######################################################################
205
206 define DEF_LIBS
207
208 CFG_RUNTIME_$(1) :=$(call CFG_LIB_NAME_$(1),rustrt)
209 CFG_RUSTLLVM_$(1) :=$(call CFG_LIB_NAME_$(1),rustllvm)
210 CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std)
211 CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra)
212 CFG_LIBRUSTC_$(1) :=$(call CFG_LIB_NAME_$(1),rustc)
213 CFG_LIBSYNTAX_$(1) :=$(call CFG_LIB_NAME_$(1),syntax)
214 CFG_LIBRUSTPKG_$(1) :=$(call CFG_LIB_NAME_$(1),rustpkg)
215 CFG_LIBRUSTDOC_$(1) :=$(call CFG_LIB_NAME_$(1),rustdoc)
216 CFG_LIBRUSTI_$(1) :=$(call CFG_LIB_NAME_$(1),rusti)
217 CFG_LIBRUST_$(1) :=$(call CFG_LIB_NAME_$(1),rust)
218
219 EXTRALIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),extra)
220 STDLIB_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),std)
221 LIBRUSTC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustc)
222 LIBSYNTAX_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),syntax)
223 LIBRUSTPKG_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustpkg)
224 LIBRUSTDOC_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rustdoc)
225 LIBRUSTI_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rusti)
226 LIBRUST_GLOB_$(1) :=$(call CFG_LIB_GLOB_$(1),rust)
227 EXTRALIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),extra)
228 STDLIB_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),std)
229 LIBRUSTC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustc)
230 LIBSYNTAX_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),syntax)
231 LIBRUSTPKG_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustpkg)
232 LIBRUSTDOC_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rustdoc)
233 LIBRUSTI_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rusti)
234 LIBRUST_DSYM_GLOB_$(1) :=$(call CFG_LIB_DSYM_GLOB_$(1),rust)
235
236 endef
237
238 $(foreach target,$(CFG_TARGET_TRIPLES),\
239   $(eval $(call DEF_LIBS,$(target))))
240
241 ######################################################################
242 # Standard library variables
243 ######################################################################
244
245 STDLIB_CRATE := $(S)src/libstd/std.rs
246 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/,        \
247                                            *.rs */*.rs */*/*rs */*/*/*rs))
248
249 ######################################################################
250 # Extra library variables
251 ######################################################################
252
253 EXTRALIB_CRATE := $(S)src/libextra/extra.rs
254 EXTRALIB_INPUTS := $(wildcard $(addprefix $(S)src/libextra/,          \
255                                           *.rs */*.rs))
256
257 ######################################################################
258 # rustc crate variables
259 ######################################################################
260
261 COMPILER_CRATE := $(S)src/librustc/rustc.rs
262 COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/librustc/,      \
263                            *.rs */*.rs */*/*.rs */*/*/*.rs))
264
265 LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rs
266 LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
267                            *.rs */*.rs */*/*.rs))
268
269 DRIVER_CRATE := $(S)src/driver/driver.rs
270
271 ######################################################################
272 # LLVM macros
273 ######################################################################
274
275 # FIXME: x86-ism
276 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
277                 interpreter instrumentation
278
279 define DEF_LLVM_VARS
280 # The configure script defines these variables with the target triples
281 # separated by Z. This defines new ones with the expected format.
282 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
283 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
284
285 # Any rules that depend on LLVM should depend on LLVM_CONFIG
286 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
287 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
288 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
289 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
290 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
291 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
292 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
293 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
294 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
295 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
296 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
297 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
298
299 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
300 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
301
302 endef
303
304 $(foreach host,$(CFG_HOST_TRIPLES), \
305  $(eval $(call DEF_LLVM_VARS,$(host))))
306
307 ######################################################################
308 # Exports for sub-utilities
309 ######################################################################
310
311 # Note that any variable that re-configure should pick up needs to be
312 # exported
313
314 export CFG_SRC_DIR
315 export CFG_BUILD_DIR
316 export CFG_VERSION
317 export CFG_VERSION_WIN
318 export CFG_BUILD_TRIPLE
319 export CFG_LLVM_ROOT
320 export CFG_ENABLE_MINGW_CROSS
321 export CFG_PREFIX
322 export CFG_LIBDIR
323
324 ######################################################################
325 # Subprograms
326 ######################################################################
327
328 ######################################################################
329 # Per-stage targets and runner
330 ######################################################################
331
332 define SREQ
333 # $(1) is the stage number
334 # $(2) is the target triple
335 # $(3) is the host triple
336
337 # Destinations of artifacts for the host compiler
338 HROOT$(1)_H_$(3) = $(3)/stage$(1)
339 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
340 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
341
342 # Destinations of artifacts for target architectures
343 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
344 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
345 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
346
347 # The name of the standard and extra libraries used by rustc
348 ifdef CFG_DISABLE_SHAREDSTD
349   HSTDLIB_DEFAULT$(1)_H_$(3) = \
350     $$(HLIB$(1)_H_$(3))/libstd.rlib
351   TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
352     $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
353
354   HEXTRALIB_DEFAULT$(1)_H_$(3) = \
355     $$(HLIB$(1)_H_$(3))/libextra.rlib
356   TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
357     $$(TLIB$(1)_T_$(2)_H_$(3))/libextra.rlib
358
359   HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
360     $$(HLIB$(1)_H_$(3))/librustc.rlib
361   TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
362     $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
363 else
364   HSTDLIB_DEFAULT$(1)_H_$(3) = \
365     $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB_$(3))
366   TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
367     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2))
368
369   HEXTRALIB_DEFAULT$(1)_H_$(3) = \
370     $$(HLIB$(1)_H_$(3))/$(CFG_EXTRALIB_$(3))
371   TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
372     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
373
374   HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
375     $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC_$(3))
376   TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
377     $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2))
378 endif
379
380 # Preqrequisites for using the stageN compiler
381 HSREQ$(1)_H_$(3) = \
382         $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
383         $$(HLIB$(1)_H_$(3))/$(CFG_RUNTIME_$(3)) \
384         $$(HLIB$(1)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
385         $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
386         $$(HEXTRALIB_DEFAULT$(1)_H_$(3)) \
387         $$(HLIBSYNTAX_DEFAULT$(1)_H_$(3)) \
388         $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
389         $$(MKFILE_DEPS)
390
391 # Prerequisites for using the stageN compiler to build target artifacts
392 TSREQ$(1)_T_$(2)_H_$(3) = \
393         $$(HSREQ$(1)_H_$(3)) \
394         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)) \
395         $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
396
397 # Prerequisites for a working stageN compiler and libraries, for a specific target
398 SREQ$(1)_T_$(2)_H_$(3) = \
399         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
400         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
401         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))
402
403 # Prerequisites for a working stageN compiler and libraries, for a specific target
404 CSREQ$(1)_T_$(2)_H_$(3) = \
405         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
406         $$(HBIN$(1)_H_$(3))/rustpkg$$(X_$(3)) \
407         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
408         $$(HBIN$(1)_H_$(3))/rusti$$(X_$(3)) \
409         $$(HBIN$(1)_H_$(3))/rust$$(X_$(3)) \
410         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTPKG_$(3)) \
411         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTDOC_$(3)) \
412         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTI_$(3)) \
413         $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUST_$(3)) \
414         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
415         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2))  \
416         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(2))  \
417         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(2)) \
418         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTPKG_$(2)) \
419         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTDOC_$(2)) \
420         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTI_$(2)) \
421         $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUST_$(2))
422
423 ifeq ($(1),0)
424 # Don't run the the stage0 compiler under valgrind - that ship has sailed
425 CFG_VALGRIND_COMPILE$(1) =
426 else
427 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
428 endif
429
430 # Add RUSTFLAGS_STAGEN values to the build command
431 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
432
433 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
434
435 # Pass --cfg stage0 only for the build->host part of stage0;
436 # if you're building a cross config, the host->* parts are
437 # effectively stage1, since it uses the just-built stage0.
438 ifeq ($(1),0)
439 ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(3)))
440 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
441 endif
442 endif
443
444 STAGE$(1)_T_$(2)_H_$(3) :=                                              \
445         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
446                 $$(CFG_VALGRIND_COMPILE$(1))                    \
447                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
448                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
449                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
450                 $$(RUSTC_FLAGS_$(2))
451
452 PERF_STAGE$(1)_T_$(2)_H_$(3) :=                                 \
453         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1),                            \
454                 $$(CFG_PERF_TOOL)                                               \
455                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                     \
456                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3))                     \
457                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
458                 $$(RUSTC_FLAGS_$(2))
459
460 endef
461
462 $(foreach build,$(CFG_HOST_TRIPLES), \
463  $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
464   $(eval $(foreach stage,$(STAGES), \
465    $(eval $(call SREQ,$(stage),$(target),$(build))))))))
466
467 ######################################################################
468 # rustc-H-targets
469 #
470 # Builds a functional Rustc for the given host.
471 ######################################################################
472
473 define DEF_RUSTC_STAGE_TARGET
474 # $(1) == architecture
475 # $(2) == stage
476
477 rustc-stage$(2)-H-$(1):                                                 \
478         $$(foreach target,$$(CFG_TARGET_TRIPLES),       \
479                 $$(SREQ$(2)_T_$$(target)_H_$(1)))
480
481 endef
482
483 $(foreach host,$(CFG_HOST_TRIPLES),                                                     \
484  $(eval $(foreach stage,1 2 3,                                                                  \
485   $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
486
487 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
488 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
489 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
490
491 define DEF_RUSTC_TARGET
492 # $(1) == architecture
493
494 rustc-H-$(1): rustc-stage2-H-$(1)
495 endef
496
497 $(foreach host,$(CFG_TARGET_TRIPLES),                   \
498  $(eval $(call DEF_RUSTC_TARGET,$(host))))
499
500 rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
501 rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
502 rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
503 rustc: rustc-H-$(CFG_BUILD_TRIPLE)
504
505 rustc-H-all: $(foreach host,$(CFG_HOST_TRIPLES),rustc-H-$(host))
506
507 ######################################################################
508 # Entrypoint rule
509 ######################################################################
510
511 .DEFAULT_GOAL := all
512
513 ifneq ($(CFG_IN_TRANSITION),)
514
515 CFG_INFO := $(info cfg:)
516 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
517 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
518 CFG_INFO := $(info cfg:)
519
520 #XXX This is surely busted
521 all: $(SREQ1$(CFG_BUILD_TRIPLE)) $(GENERATED) docs
522
523 else
524
525 define ALL_TARGET_N
526 ifneq ($$(findstring $(1),$$(CFG_HOST_TRIPLES)),)
527 # This is a host
528 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
529 else
530 # This is a target only
531 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
532 endif
533 endef
534
535 $(foreach target,$(CFG_TARGET_TRIPLES), \
536  $(foreach host,$(CFG_HOST_TRIPLES), \
537  $(eval $(call ALL_TARGET_N,$(target),$(host)))))
538
539 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
540         $(foreach host,$(CFG_HOST_TRIPLES), \
541  all-target-$(target)-host-$(host)))
542
543 all: rustllvm/llvm-auto-clean-stamp \
544      $(ALL_TARGET_RULES) $(GENERATED) docs
545
546 endif
547
548 # This is used to independently force an LLVM clean rebuild
549 # when we changed something not otherwise captured by builtin
550 # dependencies. In these cases, commit a change that touches
551 # the stamp in the source dir.
552 rustllvm/llvm-auto-clean-stamp: $(S)src/rustllvm/llvm-auto-clean-trigger
553         $(Q)$(MAKE) clean-llvm
554         touch $@
555
556
557 ######################################################################
558 # Re-configuration
559 ######################################################################
560
561 ifndef CFG_DISABLE_MANAGE_SUBMODULES
562 # This is a pretty expensive operation but I don't see any way to avoid it
563 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
564 else
565 NEED_GIT_RECONFIG=0
566 endif
567
568 ifeq ($(NEED_GIT_RECONFIG),0)
569 else
570 # If the submodules have changed then always execute config.mk
571 .PHONY: config.stamp
572 endif
573
574 Makefile config.mk: config.stamp
575
576 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
577         @$(call E, cfg: reconfiguring)
578         $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
579
580
581 ######################################################################
582 # Primary-target makefiles
583 ######################################################################
584
585 include $(CFG_SRC_DIR)mk/target.mk
586 include $(CFG_SRC_DIR)mk/host.mk
587 include $(CFG_SRC_DIR)mk/stage0.mk
588 include $(CFG_SRC_DIR)mk/rt.mk
589 include $(CFG_SRC_DIR)mk/rustllvm.mk
590 include $(CFG_SRC_DIR)mk/tools.mk
591 include $(CFG_SRC_DIR)mk/docs.mk
592 include $(CFG_SRC_DIR)mk/llvm.mk
593
594 ######################################################################
595 # Secondary makefiles, conditionalized for speed
596 ######################################################################
597
598 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS))   \
599                $(findstring check,$(MAKECMDGOALS))  \
600                $(findstring test,$(MAKECMDGOALS))   \
601                $(findstring tidy,$(MAKECMDGOALS))   \
602                $(findstring clean,$(MAKECMDGOALS))),)
603   CFG_INFO := $(info cfg: including dist rules)
604   include $(CFG_SRC_DIR)mk/dist.mk
605 endif
606
607 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))   \
608                $(findstring clean,$(MAKECMDGOALS))),)
609   CFG_INFO := $(info cfg: including snap rules)
610   include $(CFG_SRC_DIR)mk/snap.mk
611 endif
612
613 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
614   CFG_INFO := $(info cfg: including reformat rules)
615   include $(CFG_SRC_DIR)mk/pp.mk
616 endif
617
618 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
619                $(findstring test,$(MAKECMDGOALS))  \
620                $(findstring perf,$(MAKECMDGOALS))  \
621                $(findstring tidy,$(MAKECMDGOALS))),)
622   CFG_INFO := $(info cfg: including test rules)
623   include $(CFG_SRC_DIR)mk/tests.mk
624 endif
625
626 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
627   CFG_INFO := $(info cfg: including perf rules)
628   include $(CFG_SRC_DIR)mk/perf.mk
629 endif
630
631 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
632   CFG_INFO := $(info cfg: including clean rules)
633   include $(CFG_SRC_DIR)mk/clean.mk
634 endif
635
636 ifneq ($(findstring install,$(MAKECMDGOALS)),)
637   ifdef DESTDIR
638     CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR)/$(CFG_PREFIX))
639     CFG_PREFIX:=$(DESTDIR)/$(CFG_PREFIX)
640     export CFG_PREFIX
641   endif
642
643   CFG_INFO := $(info cfg: including install rules)
644   include $(CFG_SRC_DIR)mk/install.mk
645 endif
646
647 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
648                $(findstring TAGS.vi,$(MAKECMDGOALS))),)
649   CFG_INFO := $(info cfg: including ctags rules)
650   include $(CFG_SRC_DIR)mk/ctags.mk
651 endif
652
653 # Find all of the .d files and include them to add information about
654 # header file dependencies.
655 ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
656 -include $(ALL_DEP_FILES)