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