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