]> git.proxmox.com Git - rustc.git/blame - mk/main.mk
New upstream version 1.14.0+dfsg1
[rustc.git] / mk / main.mk
CommitLineData
1a4d82fc
JJ
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
c30ab7b3 16CFG_RELEASE_NUM=1.14.0
1a4d82fc 17
85aaf69f
SL
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)
c30ab7b3 21CFG_PRERELEASE_VERSION=.5
54a0048b 22
1a4d82fc
JJ
23ifeq ($(CFG_RELEASE_CHANNEL),stable)
24# This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
25CFG_RELEASE=$(CFG_RELEASE_NUM)
26# This is the string used in dist artifact file names, e.g. "0.12.0", "nightly"
27CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
28CFG_DISABLE_UNSTABLE_FEATURES=1
29endif
30ifeq ($(CFG_RELEASE_CHANNEL),beta)
c34b1796 31CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
d9579d0f
AL
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.
36CFG_PACKAGE_VERS=beta
1a4d82fc
JJ
37CFG_DISABLE_UNSTABLE_FEATURES=1
38endif
39ifeq ($(CFG_RELEASE_CHANNEL),nightly)
40CFG_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.
45CFG_PACKAGE_VERS=nightly
46endif
47ifeq ($(CFG_RELEASE_CHANNEL),dev)
48CFG_RELEASE=$(CFG_RELEASE_NUM)-dev
49CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-dev
50endif
51
5bcae85e
SL
52# Append a version-dependent hash to each library, so we can install different
53# versions in the same place
54CFG_FILENAME_EXTRA=$(shell printf '%s' $(CFG_RELEASE)$(CFG_EXTRA_FILENAME) | $(CFG_HASH_COMMAND))
55
c30ab7b3 56# If local-rust is the same major.minor as the current version, then force a local-rebuild
5bcae85e 57ifdef CFG_ENABLE_LOCAL_RUST
c30ab7b3
SL
58SEMVER_PREFIX=$(shell echo $(CFG_RELEASE_NUM) | grep -E -o '^[[:digit:]]+\.[[:digit:]]+')
59LOCAL_RELEASE=$(shell $(S)src/etc/local_stage0.sh --print-rustc-release $(CFG_LOCAL_RUST_ROOT))
60ifneq (,$(filter $(SEMVER_PREFIX).%,$(LOCAL_RELEASE)))
61 CFG_INFO := $(info cfg: auto-detected local-rebuild using $(LOCAL_RELEASE))
5bcae85e
SL
62 CFG_ENABLE_LOCAL_REBUILD = 1
63endif
64endif
65
1a4d82fc
JJ
66# The name of the package to use for creating tarballs, installers etc.
67CFG_PACKAGE_NAME=rustc-$(CFG_PACKAGE_VERS)
68
69# The version string plus commit information - this is what rustc reports
70CFG_VERSION = $(CFG_RELEASE)
71CFG_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.
76SPACE :=
77SPACE +=
78ifneq ($(CFG_GIT),)
79ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
85aaf69f 80 CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --date=short --pretty=format:'%cd')
1a4d82fc
JJ
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))
84endif
85endif
86
87# Windows exe's need numeric versions - don't use anything but
88# numbers and dots here
89CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
90
85aaf69f 91CFG_INFO := $(info cfg: version $(CFG_VERSION))
1a4d82fc
JJ
92
93######################################################################
94# More configuration
95######################################################################
96
1a4d82fc
JJ
97MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
98MKFILES_FOR_TARBALL:=$(MKFILE_DEPS)
99ifneq ($(NO_MKFILE_DEPS),)
100MKFILE_DEPS :=
101endif
102NON_BUILD_HOST = $(filter-out $(CFG_BUILD),$(CFG_HOST))
103NON_BUILD_TARGET = $(filter-out $(CFG_BUILD),$(CFG_TARGET))
104
105ifneq ($(MAKE_RESTARTS),)
106CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
107endif
108
109CFG_INFO := $(info cfg: build triple $(CFG_BUILD))
110CFG_INFO := $(info cfg: host triples $(CFG_HOST))
111CFG_INFO := $(info cfg: target triples $(CFG_TARGET))
112
113ifneq ($(wildcard $(NON_BUILD_HOST)),)
114CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
115endif
116ifneq ($(wildcard $(NON_BUILD_TARGET)),)
117CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
118endif
119
120CFG_RUSTC_FLAGS := $(RUSTFLAGS)
121CFG_GCCISH_CFLAGS :=
122CFG_GCCISH_LINK_FLAGS :=
123
92a42be0 124CFG_JEMALLOC_FLAGS :=
1a4d82fc
JJ
125
126ifdef CFG_DISABLE_OPTIMIZE
127 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
128 CFG_RUSTC_FLAGS +=
129 CFG_JEMALLOC_FLAGS += --enable-debug
130else
131 # The rtopt cfg turns off runtime sanity checks
132 CFG_RUSTC_FLAGS += -O --cfg rtopt
133endif
134
135CFG_JEMALLOC_FLAGS += $(JEMALLOC_FLAGS)
136
9346a6ac
AL
137ifdef CFG_ENABLE_DEBUG_ASSERTIONS
138 $(info cfg: enabling debug assertions (CFG_ENABLE_DEBUG_ASSERTIONS))
62682a34 139 CFG_RUSTC_FLAGS += -C debug-assertions=on
9346a6ac
AL
140endif
141
142ifdef CFG_ENABLE_DEBUGINFO
143 $(info cfg: enabling debuginfo (CFG_ENABLE_DEBUGINFO))
9cc50fc6 144 CFG_RUSTC_FLAGS += -g
c30ab7b3
SL
145else ifdef CFG_ENABLE_DEBUGINFO_LINES
146 $(info cfg: enabling line number debuginfo (CFG_ENABLE_DEBUGINFO_LINES))
147 CFG_RUSTC_FLAGS += -Cdebuginfo=1
1a4d82fc
JJ
148endif
149
150ifdef SAVE_TEMPS
3157f602 151 CFG_RUSTC_FLAGS += -C save-temps
1a4d82fc
JJ
152endif
153ifdef ASM_COMMENTS
154 CFG_RUSTC_FLAGS += -Z asm-comments
155endif
156ifdef TIME_PASSES
157 CFG_RUSTC_FLAGS += -Z time-passes
158endif
159ifdef TIME_LLVM_PASSES
160 CFG_RUSTC_FLAGS += -Z time-llvm-passes
161endif
162ifdef TRACE
163 CFG_RUSTC_FLAGS += -Z trace
164endif
9cc50fc6 165ifndef CFG_DISABLE_RPATH
1a4d82fc
JJ
166CFG_RUSTC_FLAGS += -C rpath
167endif
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)
e9174d1e 178RUSTFLAGS_STAGE0 += -C prefer-dynamic -C no-stack-check
1a4d82fc
JJ
179RUSTFLAGS_STAGE1 += -C prefer-dynamic
180RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
181RUST_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.
b039eaaf
SL
185
186ifdef CFG_DISABLE_STAGE0_LANDING_PADS
187 RUSTFLAGS_STAGE0 += -Z no-landing-pads
188endif
e9174d1e 189
1a4d82fc
JJ
190# platform-specific auto-configuration
191include $(CFG_SRC_DIR)mk/platform.mk
192
193# Run the stage1/2 compilers under valgrind
194ifdef VALGRIND_COMPILE
92a42be0 195 CFG_VALGRIND_COMPILE := $(CFG_VALGRIND)
1a4d82fc
JJ
196else
197 CFG_VALGRIND_COMPILE :=
198endif
199
200
201ifndef CFG_DISABLE_VALGRIND_RPASS
202 $(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
85aaf69f 203 $(info cfg: valgrind-rpass command set to $(CFG_VALGRIND))
1a4d82fc
JJ
204 CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
205else
d9579d0f 206 $(info cfg: disabling valgrind run-pass tests)
1a4d82fc
JJ
207 CFG_VALGRIND_RPASS :=
208endif
209
210
211ifdef CFG_ENABLE_VALGRIND
212 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
92a42be0 213 CFG_JEMALLOC_FLAGS += --enable-valgrind
1a4d82fc
JJ
214else
215 CFG_VALGRIND :=
216endif
217
218######################################################################
219# Target-and-rule "utility variables"
220######################################################################
221
222define DEF_FOR_TARGET
223X_$(1) := $(CFG_EXE_SUFFIX_$(1))
224ifndef CFG_LLVM_TARGET_$(1)
225CFG_LLVM_TARGET_$(1) := $(1)
226endif
227endef
228$(foreach target,$(CFG_TARGET), \
229 $(eval $(call DEF_FOR_TARGET,$(target))))
230
231# "Source" files we generate in builddir along the way.
232GENERATED :=
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).
253define CHECK_FOR_OLD_GLOB_MATCHES
254 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(notdir $(2))\' "libraries:" $$MATCHES; fi
255endef
256
257# Same interface as above, but deletes rather than just listing the files.
258ifdef VERBOSE
259define 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
261endef
262else
263define REMOVE_ALL_OLD_GLOB_MATCHES
264 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then rm $$MATCHES ; fi
265endef
266endif
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.)
274ifdef VERBOSE
275define LIST_ALL_OLD_GLOB_MATCHES
276 @echo "info: now are following matches for" '$(notdir $(1))' "libraries:"
277 @( ls $(1) 2>/dev/null || true )
278endef
279else
280define LIST_ALL_OLD_GLOB_MATCHES
281endef
282endif
283
284######################################################################
285# LLVM macros
286######################################################################
287
c30ab7b3 288LLVM_OPTIONAL_COMPONENTS=x86 arm aarch64 mips powerpc pnacl systemz jsbackend
9cc50fc6 289LLVM_REQUIRED_COMPONENTS=ipo bitreader bitwriter linker asmparser mcjit \
1a4d82fc
JJ
290 interpreter instrumentation
291
9cc50fc6
SL
292ifneq ($(CFG_LLVM_ROOT),)
293# Ensure we only try to link targets that the installed LLVM actually has:
294LLVM_COMPONENTS := $(filter $(shell $(CFG_LLVM_ROOT)/bin/llvm-config$(X_$(CFG_BUILD)) --components),\
295 $(LLVM_OPTIONAL_COMPONENTS)) $(LLVM_REQUIRED_COMPONENTS)
296else
297LLVM_COMPONENTS := $(LLVM_OPTIONAL_COMPONENTS) $(LLVM_REQUIRED_COMPONENTS)
298endif
299
1a4d82fc
JJ
300# Only build these LLVM tools
301LLVM_TOOLS=bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract
302
303define 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.
306ifeq ($$(CFG_LLVM_ROOT),)
307CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
308CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
309else
310CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_ROOT)
311endif
312
313# Any rules that depend on LLVM should depend on LLVM_CONFIG
314LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
315LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
62682a34 316LLVM_AR_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-ar$$(X_$(1))
1a4d82fc
JJ
317LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
318LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
319LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
320LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
e9174d1e 321LLVM_LIBDIR_RUSTFLAGS_$(1)=-L native="$$(LLVM_LIBDIR_$(1))"
1a4d82fc 322LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
62682a34 323ifeq ($$(findstring freebsd,$(1)),freebsd)
1a4d82fc
JJ
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.
326LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
62682a34
SL
327else
328LLVM_CXXFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags)
329endif
1a4d82fc
JJ
330LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
331
332LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
333LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
334
9cc50fc6 335LLVM_ALL_COMPONENTS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --components)
9e0c209e 336LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
9cc50fc6 337
1a4d82fc
JJ
338endef
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
350export CFG_SRC_DIR
62682a34 351export CFG_SRC_DIR_RELATIVE
1a4d82fc
JJ
352export CFG_BUILD_DIR
353ifdef CFG_VER_DATE
354export CFG_VER_DATE
355endif
356ifdef CFG_VER_HASH
357export CFG_VER_HASH
358endif
359export CFG_VERSION
360export CFG_VERSION_WIN
361export CFG_RELEASE
362export CFG_PACKAGE_NAME
363export CFG_BUILD
364export CFG_RELEASE_CHANNEL
365export CFG_LLVM_ROOT
366export CFG_PREFIX
367export CFG_LIBDIR
368export CFG_LIBDIR_RELATIVE
369export CFG_DISABLE_INJECT_STD_VERSION
370ifdef CFG_DISABLE_UNSTABLE_FEATURES
371CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATURES))
372# Turn on feature-staging
373export CFG_DISABLE_UNSTABLE_FEATURES
1a4d82fc 374# Subvert unstable feature lints to do the self-build
9e0c209e 375export RUSTC_BOOTSTRAP=1
85aaf69f 376endif
7453a54e
SL
377ifdef CFG_MUSL_ROOT
378export CFG_MUSL_ROOT
379endif
1a4d82fc 380
9e0c209e
SL
381# FIXME: Transitionary measure to bootstrap using the old bootstrap logic.
382# Remove this once the bootstrap compiler uses the new login in Issue #36548.
c30ab7b3 383export RUSTC_BOOTSTRAP_KEY=62b3e239
9e0c209e 384
1a4d82fc
JJ
385######################################################################
386# Per-stage targets and runner
387######################################################################
388
389# Valid setting-strings are 'all', 'none', 'gdb', 'lldb'
390# This 'function' will determine which debugger scripts to copy based on a
391# target triple. See debuggers.mk for more information.
392TRIPLE_TO_DEBUGGER_SCRIPT_SETTING=\
a7813a04 393 $(if $(findstring windows-msvc,$(1)),none,all)
1a4d82fc
JJ
394
395STAGES = 0 1 2 3
396
397define SREQ
398# $(1) is the stage number
399# $(2) is the target triple
400# $(3) is the host triple
401
402# Destinations of artifacts for the host compiler
403HROOT$(1)_H_$(3) = $(3)/stage$(1)
404HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
92a42be0 405
1a4d82fc 406ifeq ($$(CFG_WINDOWSY_$(3)),1)
92a42be0
SL
407# On Windows we always store host runtime libraries in the 'bin' directory because
408# there's no rpath. Target libraries go under $CFG_LIBDIR_RELATIVE (usually 'lib').
409HLIB_RELATIVE$(1)_H_$(3) = bin
410TROOT$(1)_T_$(2)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)/rustlib/$(2)
411# Remove the next 3 lines after a snapshot
412ifeq ($(1),0)
413RUSTFLAGS_STAGE0 += -L $$(TROOT$(1)_T_$(2)_H_$(3))/lib
414endif
415
1a4d82fc 416else
92a42be0 417
1a4d82fc 418ifeq ($(1),0)
92a42be0 419HLIB_RELATIVE$(1)_H_$(3) = lib
1a4d82fc 420else
92a42be0 421HLIB_RELATIVE$(1)_H_$(3) = $$(CFG_LIBDIR_RELATIVE)
1a4d82fc 422endif
92a42be0
SL
423TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustlib/$(2)
424
1a4d82fc 425endif
92a42be0 426HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(HLIB_RELATIVE$(1)_H_$(3))
1a4d82fc
JJ
427
428# Destinations of artifacts for target architectures
1a4d82fc
JJ
429TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
430TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
431
432# Preqrequisites for using the stageN compiler
433ifeq ($(1),0)
434HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
435else
436HSREQ$(1)_H_$(3) = \
437 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
438 $$(MKFILE_DEPS) \
439 tmp/install-debugger-scripts$(1)_H_$(3)-$$(call TRIPLE_TO_DEBUGGER_SCRIPT_SETTING,$(3)).done
440endif
441
442# Prerequisites for using the stageN compiler to build target artifacts
443TSREQ$(1)_T_$(2)_H_$(3) = \
444 $$(HSREQ$(1)_H_$(3)) \
92a42be0 445 $$(foreach obj,$$(REQUIRED_OBJECTS_$(2)),\
9e0c209e
SL
446 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(obj)) \
447 $$(TLIB0_T_$(2)_H_$(3))/$$(call CFG_STATIC_LIB_NAME_$(2),compiler-rt)
448# ^ This copies `libcompiler-rt.a` to the stage0 sysroot
449# ^ TODO(stage0) update this to not copy `libcompiler-rt.a` to stage0
1a4d82fc
JJ
450
451# Prerequisites for a working stageN compiler and libraries, for a specific
452# target
453SREQ$(1)_T_$(2)_H_$(3) = \
454 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
7453a54e 455 $$(foreach dep,$$(TARGET_CRATES_$(2)), \
1a4d82fc
JJ
456 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
457 tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3)-$$(call TRIPLE_TO_DEBUGGER_SCRIPT_SETTING,$(2)).done
458
459# Prerequisites for a working stageN compiler and complete set of target
460# libraries
461CSREQ$(1)_T_$(2)_H_$(3) = \
462 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
463 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
7453a54e 464 $$(foreach dep,$$(HOST_CRATES),$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
1a4d82fc
JJ
465
466ifeq ($(1),0)
467# Don't run the stage0 compiler under valgrind - that ship has sailed
468CFG_VALGRIND_COMPILE$(1) =
469else
470CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
471endif
472
473# Add RUSTFLAGS_STAGEN values to the build command
474EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
475
476CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
477
478endef
479
480# Same macro/variables as above, but defined in a separate loop so it can use
481# all the variables above for all archs. The RPATH_VAR setup sometimes needs to
482# reach across triples to get things in order.
483#
484# Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
485# * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
486# environment to access or extend the lookup path for dynamic
487# libraries. Note on Windows, that key is `$PATH`, and thus not
488# only conflates programs with dynamic libraries, but also often
489# contains spaces which confuse make.
490# * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
491# * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
492#
493# Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
494# above settings.
495#
496define SREQ_CMDS
497
498ifeq ($$(OSTYPE_$(3)),apple-darwin)
499 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
500else
501ifeq ($$(CFG_WINDOWSY_$(3)),1)
502 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
9e0c209e
SL
503else
504ifeq ($$(OSTYPE_$(3)),unknown-haiku)
505 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LIBRARY_PATH
1a4d82fc
JJ
506else
507 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
508endif
509endif
9e0c209e 510endif
1a4d82fc
JJ
511
512LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
9cc50fc6 513 $$(CURDIR)/$$(HLIB$(1)_H_$(3)):$$(CFG_LLVM_INST_DIR_$(3))/lib
1a4d82fc 514LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
54a0048b 515 $$(CURDIR)/$$(TLIB$(1)_T_$(2)_H_$(3))
1a4d82fc
JJ
516
517HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
518 $$(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))
519TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
520 $$(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))
521
522RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
523
524# Pass --cfg stage0 only for the build->host part of stage0;
525# if you're building a cross config, the host->* parts are
526# effectively stage1, since it uses the just-built stage0.
527#
54a0048b
SL
528# Also be sure to use the right rpath because we're loading libraries from the
529# CFG_BUILD's stage1 directory for our target, so switch this one instance of
530# `RPATH_VAR` to get the bootstrap working.
1a4d82fc
JJ
531ifeq ($(1),0)
532ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
533CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
534
54a0048b 535RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR1_T_$(2)_H_$$(CFG_BUILD))
3157f602
XL
536else
537ifdef CFG_ENABLE_LOCAL_REBUILD
538# Assume the local-rebuild rustc already has stage1 features too.
539CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
540endif
1a4d82fc
JJ
541endif
542endif
543
544STAGE$(1)_T_$(2)_H_$(3) := \
545 $$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \
546 $$(call CFG_RUN_TARG_$(3),$(1), \
547 $$(CFG_VALGRIND_COMPILE$(1)) \
548 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
549 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
550 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
551 $$(RUSTC_FLAGS_$(2))
552
1a4d82fc
JJ
553endef
554
555$(foreach build,$(CFG_HOST), \
556 $(eval $(foreach target,$(CFG_TARGET), \
557 $(eval $(foreach stage,$(STAGES), \
558 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
559
560$(foreach build,$(CFG_HOST), \
561 $(eval $(foreach target,$(CFG_TARGET), \
562 $(eval $(foreach stage,$(STAGES), \
563 $(eval $(call SREQ_CMDS,$(stage),$(target),$(build))))))))
564
565######################################################################
566# rustc-H-targets
567#
568# Builds a functional Rustc for the given host.
569######################################################################
570
571define DEF_RUSTC_STAGE_TARGET
572# $(1) == architecture
573# $(2) == stage
574
575rustc-stage$(2)-H-$(1): \
576 $$(foreach target,$$(CFG_TARGET),$$(SREQ$(2)_T_$$(target)_H_$(1)))
577
578endef
579
580$(foreach host,$(CFG_HOST), \
581 $(eval $(foreach stage,1 2 3, \
582 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
583
584rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
585rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
586rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
587
588define DEF_RUSTC_TARGET
589# $(1) == architecture
590
591rustc-H-$(1): rustc-stage2-H-$(1)
592endef
593
594$(foreach host,$(CFG_TARGET), \
595 $(eval $(call DEF_RUSTC_TARGET,$(host))))
596
597rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
598rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
599rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
600rustc: rustc-H-$(CFG_BUILD)
601
602rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
603
604######################################################################
605# Entrypoint rule
606######################################################################
607
608.DEFAULT_GOAL := all
609
610define ALL_TARGET_N
611ifneq ($$(findstring $(1),$$(CFG_HOST)),)
612# This is a host
613all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
614else
615# This is a target only
616all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
617endif
618endef
619
620$(foreach target,$(CFG_TARGET), \
621 $(foreach host,$(CFG_HOST), \
622 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
623
624ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
625 $(foreach host,$(CFG_HOST), \
626 all-target-$(target)-host-$(host)))
627
9e0c209e
SL
628all-no-docs: $(ALL_TARGET_RULES) $(GENERATED)
629all: all-no-docs docs
1a4d82fc
JJ
630
631######################################################################
632# Build system documentation
633######################################################################
634
635# $(1) is the name of the doc <section> in Makefile.in
636# pick everything between tags | remove first line | remove last line
637# | remove extra (?) line | strip leading `#` from lines
638SHOW_DOCS = $(Q)awk '/<$(1)>/,/<\/$(1)>/' $(S)/Makefile.in | sed '1d' | sed '$$d' | sed 's/^\# \?//'
639
640help:
641 $(call SHOW_DOCS,help)
642
643tips:
644 $(call SHOW_DOCS,tips)
645
646nitty-gritty:
647 $(call SHOW_DOCS,nitty-gritty)