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