]> git.lizzy.rs Git - rust.git/blob - mk/main.mk
Register new snapshots.
[rust.git] / mk / main.mk
1 # Copyright 2014-2015 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 ######################################################################
12 # Version numbers and strings
13 ######################################################################
14
15 # The version number
16 CFG_RELEASE_NUM=1.0.0
17
18 # An optional number to put after the label, e.g. '.2' -> '-beta.2'
19 # NB Make sure it starts with a dot to conform to semver pre-release
20 # versions (section 9)
21 CFG_PRERELEASE_VERSION=.1
22
23 CFG_FILENAME_EXTRA=4e7c5e5c
24
25 ifeq ($(CFG_RELEASE_CHANNEL),stable)
26 # This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
27 CFG_RELEASE=$(CFG_RELEASE_NUM)
28 # This is the string used in dist artifact file names, e.g. "0.12.0", "nightly"
29 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
30 CFG_DISABLE_UNSTABLE_FEATURES=1
31 endif
32 ifeq ($(CFG_RELEASE_CHANNEL),beta)
33 CFG_RELEASE=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
34 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
35 CFG_DISABLE_UNSTABLE_FEATURES=1
36 endif
37 ifeq ($(CFG_RELEASE_CHANNEL),nightly)
38 CFG_RELEASE=$(CFG_RELEASE_NUM)-nightly
39 # When building nightly distributables just reuse the same "nightly" name
40 # so when we upload we'll always override the previous nighly. This
41 # doesn't actually impact the version reported by rustc - it's just
42 # for file naming.
43 CFG_PACKAGE_VERS=nightly
44 endif
45 ifeq ($(CFG_RELEASE_CHANNEL),dev)
46 CFG_RELEASE=$(CFG_RELEASE_NUM)-dev
47 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-dev
48 endif
49
50 # The name of the package to use for creating tarballs, installers etc.
51 CFG_PACKAGE_NAME=rustc-$(CFG_PACKAGE_VERS)
52
53 # The version string plus commit information - this is what rustc reports
54 CFG_VERSION = $(CFG_RELEASE)
55 CFG_GIT_DIR := $(CFG_SRC_DIR).git
56 # since $(CFG_GIT) may contain spaces (especially on Windows),
57 # we need to escape them. (" " to r"\ ")
58 # Note that $(subst ...) ignores space after `subst`,
59 # so we use a hack: define $(SPACE) which contains space character.
60 SPACE :=
61 SPACE +=
62 ifneq ($(CFG_GIT),)
63 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
64     CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
65     CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
66     CFG_SHORT_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse --short=9 HEAD)
67     CFG_VERSION += ($(CFG_SHORT_VER_HASH) $(CFG_VER_DATE))
68 endif
69 endif
70
71 # Windows exe's need numeric versions - don't use anything but
72 # numbers and dots here
73 CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
74
75
76 ######################################################################
77 # More configuration
78 ######################################################################
79
80 # We track all of the object files we might build so that we can find
81 # and include all of the .d files in one fell swoop.
82 ALL_OBJ_FILES :=
83
84 MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
85 MKFILES_FOR_TARBALL:=$(MKFILE_DEPS)
86 ifneq ($(NO_MKFILE_DEPS),)
87 MKFILE_DEPS :=
88 endif
89 NON_BUILD_HOST = $(filter-out $(CFG_BUILD),$(CFG_HOST))
90 NON_BUILD_TARGET = $(filter-out $(CFG_BUILD),$(CFG_TARGET))
91
92 ifneq ($(MAKE_RESTARTS),)
93 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
94 endif
95
96 CFG_INFO := $(info cfg: build triple $(CFG_BUILD))
97 CFG_INFO := $(info cfg: host triples $(CFG_HOST))
98 CFG_INFO := $(info cfg: target triples $(CFG_TARGET))
99
100 ifneq ($(wildcard $(NON_BUILD_HOST)),)
101 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
102 endif
103 ifneq ($(wildcard $(NON_BUILD_TARGET)),)
104 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
105 endif
106
107 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
108 CFG_GCCISH_CFLAGS :=
109 CFG_GCCISH_LINK_FLAGS :=
110
111 # Turn off broken quarantine (see jemalloc/jemalloc#161)
112 CFG_JEMALLOC_FLAGS := --disable-fill
113
114 ifdef CFG_DISABLE_OPTIMIZE
115   $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
116   CFG_RUSTC_FLAGS +=
117   CFG_JEMALLOC_FLAGS += --enable-debug
118 else
119   # The rtopt cfg turns off runtime sanity checks
120   CFG_RUSTC_FLAGS += -O --cfg rtopt
121 endif
122
123 CFG_JEMALLOC_FLAGS += $(JEMALLOC_FLAGS)
124
125 ifdef CFG_DISABLE_DEBUG
126   CFG_RUSTC_FLAGS += --cfg ndebug
127 else
128   $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
129   CFG_RUSTC_FLAGS += --cfg debug
130 endif
131
132 ifdef SAVE_TEMPS
133   CFG_RUSTC_FLAGS += --save-temps
134 endif
135 ifdef ASM_COMMENTS
136   CFG_RUSTC_FLAGS += -Z asm-comments
137 endif
138 ifdef TIME_PASSES
139   CFG_RUSTC_FLAGS += -Z time-passes
140 endif
141 ifdef TIME_LLVM_PASSES
142   CFG_RUSTC_FLAGS += -Z time-llvm-passes
143 endif
144 ifdef TRACE
145   CFG_RUSTC_FLAGS += -Z trace
146 endif
147 ifdef CFG_ENABLE_RPATH
148 CFG_RUSTC_FLAGS += -C rpath
149 endif
150
151 # The executables crated during this compilation process have no need to include
152 # static copies of libstd and libextra. We also generate dynamic versions of all
153 # libraries, so in the interest of space, prefer dynamic linking throughout the
154 # compilation process.
155 #
156 # Note though that these flags are omitted for the *bins* in stage2+. This means
157 # that the snapshot will be generated with a statically linked rustc so we only
158 # have to worry about the distribution of one file (with its native dynamic
159 # dependencies)
160 RUSTFLAGS_STAGE0 += -C prefer-dynamic
161 RUSTFLAGS_STAGE1 += -C prefer-dynamic
162 RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
163 RUST_LIB_FLAGS_ST3 += -C prefer-dynamic
164
165 # Landing pads require a lot of codegen. We can get through bootstrapping faster
166 # by not emitting them.
167 RUSTFLAGS_STAGE0 += -Z no-landing-pads
168
169 # platform-specific auto-configuration
170 include $(CFG_SRC_DIR)mk/platform.mk
171
172 # Run the stage1/2 compilers under valgrind
173 ifdef VALGRIND_COMPILE
174   CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
175 else
176   CFG_VALGRIND_COMPILE :=
177 endif
178
179
180 ifndef CFG_DISABLE_VALGRIND_RPASS
181   $(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
182   CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
183 else
184   CFG_VALGRIND_RPASS :=
185 endif
186
187
188 ifdef CFG_ENABLE_VALGRIND
189   $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
190 else
191   CFG_VALGRIND :=
192 endif
193
194 ######################################################################
195 # Target-and-rule "utility variables"
196 ######################################################################
197
198 define DEF_FOR_TARGET
199 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
200 ifndef CFG_LLVM_TARGET_$(1)
201 CFG_LLVM_TARGET_$(1) := $(1)
202 endif
203 endef
204 $(foreach target,$(CFG_TARGET), \
205   $(eval $(call DEF_FOR_TARGET,$(target))))
206
207 # "Source" files we generate in builddir along the way.
208 GENERATED :=
209
210 # Delete the built-in rules.
211 .SUFFIXES:
212 %:: %,v
213 %:: RCS/%,v
214 %:: RCS/%
215 %:: s.%
216 %:: SCCS/s.%
217
218
219 ######################################################################
220 # Cleaning out old crates
221 ######################################################################
222
223 # $(1) is the path for directory to match against
224 # $(2) is the glob to use in the match
225 #
226 # Note that a common bug is to accidentally construct the glob denoted
227 # by $(2) with a space character prefix, which invalidates the
228 # construction $(1)$(2).
229 define CHECK_FOR_OLD_GLOB_MATCHES
230   $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(notdir $(2))\' "libraries:" $$MATCHES; fi
231 endef
232
233 # Same interface as above, but deletes rather than just listing the files.
234 ifdef VERBOSE
235 define REMOVE_ALL_OLD_GLOB_MATCHES
236   $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: removing previous" \'$(notdir $(1))\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
237 endef
238 else
239 define REMOVE_ALL_OLD_GLOB_MATCHES
240   $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then rm $$MATCHES ; fi
241 endef
242 endif
243
244 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
245 # than in the macros above because it needs the result of running the
246 # `ls` command after other rules in the command list have run; the
247 # macro-expander for $(wildcard ...) would deliver its results too
248 # soon. (This is in contrast to the macros above, which are meant to
249 # be run at the outset of a command list in a rule.)
250 ifdef VERBOSE
251 define LIST_ALL_OLD_GLOB_MATCHES
252   @echo "info: now are following matches for" '$(notdir $(1))' "libraries:"
253   @( ls $(1) 2>/dev/null || true )
254 endef
255 else
256 define LIST_ALL_OLD_GLOB_MATCHES
257 endef
258 endif
259
260 ######################################################################
261 # LLVM macros
262 ######################################################################
263
264 # FIXME: x86-ism
265 LLVM_COMPONENTS=x86 arm aarch64 mips powerpc ipo bitreader bitwriter linker asmparser mcjit \
266                 interpreter instrumentation
267
268 # Only build these LLVM tools
269 LLVM_TOOLS=bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract
270
271 define DEF_LLVM_VARS
272 # The configure script defines these variables with the target triples
273 # separated by Z. This defines new ones with the expected format.
274 ifeq ($$(CFG_LLVM_ROOT),)
275 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
276 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
277 else
278 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_ROOT)
279 endif
280
281 # Any rules that depend on LLVM should depend on LLVM_CONFIG
282 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
283 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
284 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
285 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
286 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
287 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
288 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
289 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
290 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
291 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
292 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
293 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
294
295 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
296 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
297
298 endef
299
300 $(foreach host,$(CFG_HOST), \
301  $(eval $(call DEF_LLVM_VARS,$(host))))
302
303 ######################################################################
304 # Exports for sub-utilities
305 ######################################################################
306
307 # Note that any variable that re-configure should pick up needs to be
308 # exported
309
310 export CFG_SRC_DIR
311 export CFG_BUILD_DIR
312 ifdef CFG_VER_DATE
313 export CFG_VER_DATE
314 endif
315 ifdef CFG_VER_HASH
316 export CFG_VER_HASH
317 endif
318 export CFG_VERSION
319 export CFG_VERSION_WIN
320 export CFG_RELEASE
321 export CFG_PACKAGE_NAME
322 export CFG_BUILD
323 export CFG_RELEASE_CHANNEL
324 export CFG_LLVM_ROOT
325 export CFG_PREFIX
326 export CFG_LIBDIR
327 export CFG_LIBDIR_RELATIVE
328 export CFG_DISABLE_INJECT_STD_VERSION
329 ifdef CFG_DISABLE_UNSTABLE_FEATURES
330 CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATURES))
331 # Turn on feature-staging
332 export CFG_DISABLE_UNSTABLE_FEATURES
333 endif
334 # Subvert unstable feature lints to do the self-build
335 export CFG_BOOTSTRAP_KEY
336
337 ######################################################################
338 # Per-stage targets and runner
339 ######################################################################
340
341 # Valid setting-strings are 'all', 'none', 'gdb', 'lldb'
342 # This 'function' will determine which debugger scripts to copy based on a
343 # target triple. See debuggers.mk for more information.
344 TRIPLE_TO_DEBUGGER_SCRIPT_SETTING=\
345  $(if $(findstring windows,$(1)),none,$(if $(findstring darwin,$(1)),lldb,gdb))
346
347 STAGES = 0 1 2 3
348
349 define SREQ
350 # $(1) is the stage number
351 # $(2) is the target triple
352 # $(3) is the host triple
353
354 # Destinations of artifacts for the host compiler
355 HROOT$(1)_H_$(3) = $(3)/stage$(1)
356 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
357 ifeq ($$(CFG_WINDOWSY_$(3)),1)
358 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
359 else
360 ifeq ($(1),0)
361 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/lib
362 else
363 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
364 endif
365 endif
366
367 # Destinations of artifacts for target architectures
368 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustlib/$(2)
369 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
370 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
371
372 # Preqrequisites for using the stageN compiler
373 ifeq ($(1),0)
374 HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
375 else
376 HSREQ$(1)_H_$(3) = \
377         $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
378         $$(MKFILE_DEPS) \
379         tmp/install-debugger-scripts$(1)_H_$(3)-$$(call TRIPLE_TO_DEBUGGER_SCRIPT_SETTING,$(3)).done
380 endif
381
382 # Prerequisites for using the stageN compiler to build target artifacts
383 TSREQ$(1)_T_$(2)_H_$(3) = \
384         $$(HSREQ$(1)_H_$(3)) \
385         $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a \
386         $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
387
388 # Prerequisites for a working stageN compiler and libraries, for a specific
389 # target
390 SREQ$(1)_T_$(2)_H_$(3) = \
391         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
392         $$(foreach dep,$$(TARGET_CRATES), \
393             $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
394         tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-$$(call TRIPLE_TO_DEBUGGER_SCRIPT_SETTING,$(2)).done
395
396 # Prerequisites for a working stageN compiler and complete set of target
397 # libraries
398 CSREQ$(1)_T_$(2)_H_$(3) = \
399         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
400         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
401         $$(foreach dep,$$(CRATES),$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
402
403 ifeq ($(1),0)
404 # Don't run the stage0 compiler under valgrind - that ship has sailed
405 CFG_VALGRIND_COMPILE$(1) =
406 # FIXME(21230) HACK Extract the key from the snapshot
407 CFG_BOOSTRAP_KEY_ENV$(1) = RUSTC_BOOTSTRAP_KEY=$$$$((grep -a 'save analysis[0-9]' \
408         $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) || echo N) |\
409         sed 's/.*save analysis\([0-9]*\).*/\1/')
410 else
411 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
412 CFG_BOOSTRAP_KEY_ENV$(1) = RUSTC_BOOTSTRAP_KEY=$$(CFG_BOOTSTRAP_KEY)
413 endif
414
415 # Add RUSTFLAGS_STAGEN values to the build command
416 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
417
418 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
419
420 endef
421
422 # Same macro/variables as above, but defined in a separate loop so it can use
423 # all the variables above for all archs. The RPATH_VAR setup sometimes needs to
424 # reach across triples to get things in order.
425 #
426 # Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
427 # * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
428 #   environment to access or extend the lookup path for dynamic
429 #   libraries.  Note on Windows, that key is `$PATH`, and thus not
430 #   only conflates programs with dynamic libraries, but also often
431 #   contains spaces which confuse make.
432 # * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
433 # * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
434 #
435 # Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
436 # above settings.
437 #
438 define SREQ_CMDS
439
440 ifeq ($$(OSTYPE_$(3)),apple-darwin)
441   LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
442 else
443 ifeq ($$(CFG_WINDOWSY_$(3)),1)
444   LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
445 else
446   LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
447 endif
448 endif
449
450 LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
451     $$(CURDIR)/$$(HLIB$(1)_H_$(3))
452 LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
453     $$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
454
455 HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
456   $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3)):$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))
457 TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
458   $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3)):$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))
459
460 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
461
462 # Pass --cfg stage0 only for the build->host part of stage0;
463 # if you're building a cross config, the host->* parts are
464 # effectively stage1, since it uses the just-built stage0.
465 #
466 # This logic is similar to how the LD_LIBRARY_PATH variable must
467 # change be slightly different when doing cross compilations.
468 # The build doesn't copy over all target libraries into
469 # a new directory, so we need to point the library path at
470 # the build directory where all the target libraries came
471 # from (the stage0 build host). Otherwise the relative rpaths
472 # inside of the rustc binary won't get resolved correctly.
473 ifeq ($(1),0)
474 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
475 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
476
477 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
478 endif
479 endif
480
481 STAGE$(1)_T_$(2)_H_$(3) := \
482         $$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \
483                 $$(call CFG_RUN_TARG_$(3),$(1), \
484                 $$(CFG_VALGRIND_COMPILE$(1)) \
485                 $$(CFG_BOOSTRAP_KEY_ENV$(1)) \
486                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
487                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
488                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
489                 $$(RUSTC_FLAGS_$(2))
490
491 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
492         $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
493                 $$(CFG_PERF_TOOL) \
494                 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
495                 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
496                 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
497                 $$(RUSTC_FLAGS_$(2))
498
499 endef
500
501 $(foreach build,$(CFG_HOST), \
502  $(eval $(foreach target,$(CFG_TARGET), \
503   $(eval $(foreach stage,$(STAGES), \
504    $(eval $(call SREQ,$(stage),$(target),$(build))))))))
505
506 $(foreach build,$(CFG_HOST), \
507  $(eval $(foreach target,$(CFG_TARGET), \
508   $(eval $(foreach stage,$(STAGES), \
509    $(eval $(call SREQ_CMDS,$(stage),$(target),$(build))))))))
510
511 ######################################################################
512 # rustc-H-targets
513 #
514 # Builds a functional Rustc for the given host.
515 ######################################################################
516
517 define DEF_RUSTC_STAGE_TARGET
518 # $(1) == architecture
519 # $(2) == stage
520
521 rustc-stage$(2)-H-$(1): \
522         $$(foreach target,$$(CFG_TARGET),$$(SREQ$(2)_T_$$(target)_H_$(1)))
523
524 endef
525
526 $(foreach host,$(CFG_HOST), \
527  $(eval $(foreach stage,1 2 3, \
528   $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
529
530 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
531 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
532 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
533
534 define DEF_RUSTC_TARGET
535 # $(1) == architecture
536
537 rustc-H-$(1): rustc-stage2-H-$(1)
538 endef
539
540 $(foreach host,$(CFG_TARGET), \
541  $(eval $(call DEF_RUSTC_TARGET,$(host))))
542
543 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
544 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
545 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
546 rustc: rustc-H-$(CFG_BUILD)
547
548 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
549
550 ######################################################################
551 # Entrypoint rule
552 ######################################################################
553
554 .DEFAULT_GOAL := all
555
556 define ALL_TARGET_N
557 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
558 # This is a host
559 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
560 else
561 # This is a target only
562 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
563 endif
564 endef
565
566 $(foreach target,$(CFG_TARGET), \
567  $(foreach host,$(CFG_HOST), \
568  $(eval $(call ALL_TARGET_N,$(target),$(host)))))
569
570 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
571         $(foreach host,$(CFG_HOST), \
572  all-target-$(target)-host-$(host)))
573
574 all: $(ALL_TARGET_RULES) $(GENERATED) docs
575
576 ######################################################################
577 # Build system documentation
578 ######################################################################
579
580 # $(1) is the name of the doc <section> in Makefile.in
581 # pick everything between tags | remove first line | remove last line
582 # | remove extra (?) line | strip leading `#` from lines
583 SHOW_DOCS = $(Q)awk '/<$(1)>/,/<\/$(1)>/' $(S)/Makefile.in | sed '1d' | sed '$$d' | sed 's/^\# \?//'
584
585 help:
586         $(call SHOW_DOCS,help)
587
588 tips:
589         $(call SHOW_DOCS,tips)
590
591 nitty-gritty:
592         $(call SHOW_DOCS,nitty-gritty)