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