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