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