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