1 # Copyright 2014 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.
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.
11 ######################################################################
12 # Version numbers and strings
13 ######################################################################
16 CFG_RELEASE_NUM=0.13.0
18 CFG_FILENAME_EXTRA=4e7c5e5c
20 ifeq ($(CFG_RELEASE_CHANNEL),stable)
21 # This is the normal semver version string, e.g. "0.12.0", "0.12.0-nightly"
22 CFG_RELEASE=$(CFG_RELEASE_NUM)
23 # This is the string used in dist artifact file names, e.g. "0.12.0", "nightly"
24 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
26 ifeq ($(CFG_RELEASE_CHANNEL),beta)
27 CFG_RELEASE=$(CFG_RELEASE_NUM)-beta
28 # When building beta/nightly distributables just reuse the same "beta"
29 # name so when we upload we'll always override the previous
30 # nighly. This doesn't actually impact the version reported by rustc -
31 # it's just for file naming.
34 ifeq ($(CFG_RELEASE_CHANNEL),nightly)
35 CFG_RELEASE=$(CFG_RELEASE_NUM)-nightly
36 CFG_PACKAGE_VERS=nightly
38 ifeq ($(CFG_RELEASE_CHANNEL),dev)
39 CFG_RELEASE=$(CFG_RELEASE_NUM)-dev
40 CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-dev
43 # The name of the package to use for creating tarballs, installers etc.
44 CFG_PACKAGE_NAME=rust-$(CFG_PACKAGE_VERS)
46 # The version string plus commit information - this is what rustc reports
47 CFG_VERSION = $(CFG_RELEASE)
48 CFG_GIT_DIR := $(CFG_SRC_DIR).git
49 # since $(CFG_GIT) may contain spaces (especially on Windows),
50 # we need to escape them. (" " to r"\ ")
51 # Note that $(subst ...) ignores space after `subst`,
52 # so we use a hack: define $(SPACE) which contains space character.
56 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
57 CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
58 CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
59 CFG_SHORT_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse --short=9 HEAD)
60 CFG_VERSION += ($(CFG_SHORT_VER_HASH) $(CFG_VER_DATE))
64 # Windows exe's need numeric versions - don't use anything but
65 # numbers and dots here
66 CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
69 ######################################################################
71 ######################################################################
73 # We track all of the object files we might build so that we can find
74 # and include all of the .d files in one fell swoop.
77 MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
78 MKFILES_FOR_TARBALL:=$(MKFILE_DEPS)
79 ifneq ($(NO_MKFILE_DEPS),)
82 NON_BUILD_HOST = $(filter-out $(CFG_BUILD),$(CFG_HOST))
83 NON_BUILD_TARGET = $(filter-out $(CFG_BUILD),$(CFG_TARGET))
85 ifneq ($(MAKE_RESTARTS),)
86 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
89 CFG_INFO := $(info cfg: build triple $(CFG_BUILD))
90 CFG_INFO := $(info cfg: host triples $(CFG_HOST))
91 CFG_INFO := $(info cfg: target triples $(CFG_TARGET))
93 ifneq ($(wildcard $(NON_BUILD_HOST)),)
94 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
96 ifneq ($(wildcard $(NON_BUILD_TARGET)),)
97 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
100 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
102 CFG_GCCISH_LINK_FLAGS :=
104 # Turn off broken quarantine (see jemalloc/jemalloc#161)
105 CFG_JEMALLOC_FLAGS := --disable-fill
107 ifdef CFG_DISABLE_OPTIMIZE
108 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
110 CFG_JEMALLOC_FLAGS += --enable-debug
112 # The rtopt cfg turns off runtime sanity checks
113 CFG_RUSTC_FLAGS += -O --cfg rtopt
116 CFG_JEMALLOC_FLAGS += $(JEMALLOC_FLAGS)
118 ifdef CFG_DISABLE_DEBUG
119 CFG_RUSTC_FLAGS += --cfg ndebug
120 CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
122 $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
123 CFG_RUSTC_FLAGS += --cfg debug
124 CFG_GCCISH_CFLAGS += -DRUST_DEBUG
128 CFG_RUSTC_FLAGS += --save-temps
131 CFG_RUSTC_FLAGS += -Z asm-comments
134 CFG_RUSTC_FLAGS += -Z time-passes
136 ifdef TIME_LLVM_PASSES
137 CFG_RUSTC_FLAGS += -Z time-llvm-passes
140 CFG_RUSTC_FLAGS += -Z trace
142 ifdef CFG_ENABLE_RPATH
143 CFG_RUSTC_FLAGS += -C rpath
146 # The executables crated during this compilation process have no need to include
147 # static copies of libstd and libextra. We also generate dynamic versions of all
148 # libraries, so in the interest of space, prefer dynamic linking throughout the
149 # compilation process.
151 # Note though that these flags are omitted for the *bins* in stage2+. This means
152 # that the snapshot will be generated with a statically linked rustc so we only
153 # have to worry about the distribution of one file (with its native dynamic
155 RUSTFLAGS_STAGE0 += -C prefer-dynamic
156 RUSTFLAGS_STAGE1 += -C prefer-dynamic
157 RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
158 RUST_LIB_FLAGS_ST3 += -C prefer-dynamic
160 # Landing pads require a lot of codegen. We can get through bootstrapping faster
161 # by not emitting them.
162 RUSTFLAGS_STAGE0 += -Z no-landing-pads
164 # platform-specific auto-configuration
165 include $(CFG_SRC_DIR)mk/platform.mk
167 # Run the stage1/2 compilers under valgrind
168 ifdef VALGRIND_COMPILE
169 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
171 CFG_VALGRIND_COMPILE :=
175 ifndef CFG_DISABLE_VALGRIND_RPASS
176 $(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
177 CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
179 CFG_VALGRIND_RPASS :=
183 ifdef CFG_ENABLE_VALGRIND
184 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
189 ######################################################################
190 # Target-and-rule "utility variables"
191 ######################################################################
193 define DEF_FOR_TARGET
194 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
195 ifndef CFG_LLVM_TARGET_$(1)
196 CFG_LLVM_TARGET_$(1) := $(1)
199 $(foreach target,$(CFG_TARGET), \
200 $(eval $(call DEF_FOR_TARGET,$(target))))
202 # "Source" files we generate in builddir along the way.
205 # Delete the built-in rules.
214 ######################################################################
215 # Cleaning out old crates
216 ######################################################################
218 # $(1) is the path for directory to match against
219 # $(2) is the glob to use in the match
221 # Note that a common bug is to accidentally construct the glob denoted
222 # by $(2) with a space character prefix, which invalidates the
223 # construction $(1)$(2).
224 define CHECK_FOR_OLD_GLOB_MATCHES
225 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(notdir $(2))\' "libraries:" $$MATCHES; fi
228 # Same interface as above, but deletes rather than just listing the files.
230 define REMOVE_ALL_OLD_GLOB_MATCHES
231 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: removing previous" \'$(notdir $(1))\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
234 define REMOVE_ALL_OLD_GLOB_MATCHES
235 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then rm $$MATCHES ; fi
239 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
240 # than in the macros above because it needs the result of running the
241 # `ls` command after other rules in the command list have run; the
242 # macro-expander for $(wildcard ...) would deliver its results too
243 # soon. (This is in contrast to the macros above, which are meant to
244 # be run at the outset of a command list in a rule.)
246 define LIST_ALL_OLD_GLOB_MATCHES
247 @echo "info: now are following matches for" '$(notdir $(1))' "libraries:"
248 @( ls $(1) 2>/dev/null || true )
251 define LIST_ALL_OLD_GLOB_MATCHES
255 ######################################################################
257 ######################################################################
260 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser mcjit \
261 interpreter instrumentation
263 # Only build these LLVM tools
264 LLVM_TOOLS=bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract
267 # The configure script defines these variables with the target triples
268 # separated by Z. This defines new ones with the expected format.
269 ifeq ($$(CFG_LLVM_ROOT),)
270 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
271 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
273 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_ROOT)
276 # Any rules that depend on LLVM should depend on LLVM_CONFIG
277 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
278 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
279 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
280 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
281 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
282 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
283 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
284 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
285 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
286 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
287 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
288 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
290 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
291 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
295 $(foreach host,$(CFG_HOST), \
296 $(eval $(call DEF_LLVM_VARS,$(host))))
298 ######################################################################
299 # Exports for sub-utilities
300 ######################################################################
302 # Note that any variable that re-configure should pick up needs to be
314 export CFG_VERSION_WIN
316 export CFG_PACKAGE_NAME
321 export CFG_LIBDIR_RELATIVE
322 export CFG_DISABLE_INJECT_STD_VERSION
324 ######################################################################
325 # Per-stage targets and runner
326 ######################################################################
331 # $(1) is the stage number
332 # $(2) is the target triple
333 # $(3) is the host triple
335 # Destinations of artifacts for the host compiler
336 HROOT$(1)_H_$(3) = $(3)/stage$(1)
337 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
338 ifeq ($$(CFG_WINDOWSY_$(3)),1)
339 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
342 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/lib
344 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
348 # Destinations of artifacts for target architectures
349 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustlib/$(2)
350 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
351 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
353 # Preqrequisites for using the stageN compiler
355 HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
358 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
360 tmp/install-debugger-scripts$(1)_H_$(3).done
363 # Prerequisites for using the stageN compiler to build target artifacts
364 TSREQ$(1)_T_$(2)_H_$(3) = \
365 $$(HSREQ$(1)_H_$(3)) \
366 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a \
367 $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
369 # Prerequisites for a working stageN compiler and libraries, for a specific
371 SREQ$(1)_T_$(2)_H_$(3) = \
372 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
373 $$(foreach dep,$$(TARGET_CRATES), \
374 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
375 tmp/install-debugger-scripts$(1)_T_$(2)_H_$(3).done
377 # Prerequisites for a working stageN compiler and complete set of target
379 CSREQ$(1)_T_$(2)_H_$(3) = \
380 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
381 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
382 $$(foreach dep,$$(CRATES),$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
385 # Don't run the stage0 compiler under valgrind - that ship has sailed
386 CFG_VALGRIND_COMPILE$(1) =
388 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
391 # Add RUSTFLAGS_STAGEN values to the build command
392 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
394 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
398 # Same macro/variables as above, but defined in a separate loop so it can use
399 # all the variables above for all archs. The RPATH_VAR setup sometimes needs to
400 # reach across triples to get things in order.
402 # Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
403 # * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
404 # environment to access or extend the lookup path for dynamic
405 # libraries. Note on Windows, that key is `$PATH`, and thus not
406 # only conflates programs with dynamic libraries, but also often
407 # contains spaces which confuse make.
408 # * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
409 # * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
411 # Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
416 ifeq ($$(OSTYPE_$(3)),apple-darwin)
417 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
419 ifeq ($$(CFG_WINDOWSY_$(3)),1)
420 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
422 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
426 LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
427 $$(CURDIR)/$$(HLIB$(1)_H_$(3))
428 LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
429 $$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
431 HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
432 $$(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))
433 TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
434 $$(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))
436 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
438 # Pass --cfg stage0 only for the build->host part of stage0;
439 # if you're building a cross config, the host->* parts are
440 # effectively stage1, since it uses the just-built stage0.
442 # This logic is similar to how the LD_LIBRARY_PATH variable must
443 # change be slightly different when doing cross compilations.
444 # The build doesn't copy over all target libraries into
445 # a new directory, so we need to point the library path at
446 # the build directory where all the target libraries came
447 # from (the stage0 build host). Otherwise the relative rpaths
448 # inside of the rustc binary won't get resolved correctly.
450 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
451 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
453 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
457 STAGE$(1)_T_$(2)_H_$(3) := \
458 $$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \
459 $$(call CFG_RUN_TARG_$(3),$(1), \
460 $$(CFG_VALGRIND_COMPILE$(1)) \
461 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
462 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
463 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
466 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
467 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
469 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
470 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
471 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
476 $(foreach build,$(CFG_HOST), \
477 $(eval $(foreach target,$(CFG_TARGET), \
478 $(eval $(foreach stage,$(STAGES), \
479 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
481 $(foreach build,$(CFG_HOST), \
482 $(eval $(foreach target,$(CFG_TARGET), \
483 $(eval $(foreach stage,$(STAGES), \
484 $(eval $(call SREQ_CMDS,$(stage),$(target),$(build))))))))
486 ######################################################################
489 # Builds a functional Rustc for the given host.
490 ######################################################################
492 define DEF_RUSTC_STAGE_TARGET
493 # $(1) == architecture
496 rustc-stage$(2)-H-$(1): \
497 $$(foreach target,$$(CFG_TARGET),$$(SREQ$(2)_T_$$(target)_H_$(1)))
501 $(foreach host,$(CFG_HOST), \
502 $(eval $(foreach stage,1 2 3, \
503 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
505 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
506 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
507 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
509 define DEF_RUSTC_TARGET
510 # $(1) == architecture
512 rustc-H-$(1): rustc-stage2-H-$(1)
515 $(foreach host,$(CFG_TARGET), \
516 $(eval $(call DEF_RUSTC_TARGET,$(host))))
518 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
519 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
520 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
521 rustc: rustc-H-$(CFG_BUILD)
523 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
525 ######################################################################
527 ######################################################################
532 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
534 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
536 # This is a target only
537 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
541 $(foreach target,$(CFG_TARGET), \
542 $(foreach host,$(CFG_HOST), \
543 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
545 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
546 $(foreach host,$(CFG_HOST), \
547 all-target-$(target)-host-$(host)))
549 all: $(ALL_TARGET_RULES) $(GENERATED) docs
551 ######################################################################
552 # Build system documentation
553 ######################################################################
555 # $(1) is the name of the doc <section> in Makefile.in
556 # pick everything between tags | remove first line | remove last line
557 # | remove extra (?) line | strip leading `#` from lines
558 SHOW_DOCS = $(Q)awk '/<$(1)>/,/<\/$(1)>/' $(S)/Makefile.in | sed '1d' | sed '$$d' | sed 's/^\# \?//'
561 $(call SHOW_DOCS,help)
564 $(call SHOW_DOCS,tips)
567 $(call SHOW_DOCS,nitty-gritty)