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