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