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