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