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