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