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