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