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