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.12.0
17 CFG_RELEASE_LABEL=-pre
19 CFG_FILENAME_EXTRA=4e7c5e5c
21 ifndef CFG_ENABLE_NIGHTLY
22 # This is the normal version string
23 CFG_RELEASE=$(CFG_RELEASE_NUM)$(CFG_RELEASE_LABEL)
24 CFG_PACKAGE_VERS=$(CFG_RELEASE)
26 # Modify the version label for nightly builds
27 CFG_RELEASE=$(CFG_RELEASE_NUM)$(CFG_RELEASE_LABEL)-nightly
28 # When building nightly distributables just reuse the same "rust-nightly" name
29 # so when we upload we'll always override the previous nighly. This doesn't actually
30 # impact the version reported by rustc - it's just for file naming.
31 CFG_PACKAGE_VERS=nightly
33 # The name of the package to use for creating tarballs, installers etc.
34 CFG_PACKAGE_NAME=rust-$(CFG_PACKAGE_VERS)
36 # The version string plus commit information - this is what rustc reports
37 CFG_VERSION = $(CFG_RELEASE)
38 CFG_GIT_DIR := $(CFG_SRC_DIR).git
39 # since $(CFG_GIT) may contain spaces (especially on Windows),
40 # we need to escape them. (" " to r"\ ")
41 # Note that $(subst ...) ignores space after `subst`,
42 # so we use a hack: define $(SPACE) which contains space character.
45 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT))),)
46 ifneq ($(wildcard $(subst $(SPACE),\$(SPACE),$(CFG_GIT_DIR))),)
47 CFG_VER_DATE = $(shell git --git-dir='$(CFG_GIT_DIR)' log -1 --pretty=format:'%ci')
48 CFG_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse HEAD)
49 CFG_SHORT_VER_HASH = $(shell git --git-dir='$(CFG_GIT_DIR)' rev-parse --short=9 HEAD)
50 CFG_VERSION += ($(CFG_SHORT_VER_HASH) $(CFG_VER_DATE))
54 # Windows exe's need numeric versions - don't use anything but
55 # numbers and dots here
56 CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
59 ######################################################################
61 ######################################################################
63 # We track all of the object files we might build so that we can find
64 # and include all of the .d files in one fell swoop.
67 MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
68 MKFILES_FOR_TARBALL:=$(MKFILE_DEPS)
69 ifneq ($(NO_MKFILE_DEPS),)
72 NON_BUILD_HOST = $(filter-out $(CFG_BUILD),$(CFG_HOST))
73 NON_BUILD_TARGET = $(filter-out $(CFG_BUILD),$(CFG_TARGET))
75 ifneq ($(MAKE_RESTARTS),)
76 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
79 CFG_INFO := $(info cfg: build triple $(CFG_BUILD))
80 CFG_INFO := $(info cfg: host triples $(CFG_HOST))
81 CFG_INFO := $(info cfg: target triples $(CFG_TARGET))
83 ifneq ($(wildcard $(NON_BUILD_HOST)),)
84 CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST))
86 ifneq ($(wildcard $(NON_BUILD_TARGET)),)
87 CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET))
90 CFG_RUSTC_FLAGS := $(RUSTFLAGS)
92 CFG_GCCISH_LINK_FLAGS :=
94 ifdef CFG_DISABLE_OPTIMIZE
95 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
98 # The rtopt cfg turns off runtime sanity checks
99 CFG_RUSTC_FLAGS += -O --cfg rtopt
102 ifdef CFG_DISABLE_DEBUG
103 CFG_RUSTC_FLAGS += --cfg ndebug
104 CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
106 $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
107 CFG_RUSTC_FLAGS += --cfg debug
108 CFG_GCCISH_CFLAGS += -DRUST_DEBUG
112 CFG_RUSTC_FLAGS += --save-temps
115 CFG_RUSTC_FLAGS += -Z asm-comments
118 CFG_RUSTC_FLAGS += -Z time-passes
120 ifdef TIME_LLVM_PASSES
121 CFG_RUSTC_FLAGS += -Z time-llvm-passes
124 CFG_RUSTC_FLAGS += -Z trace
126 ifdef CFG_ENABLE_RPATH
127 CFG_RUSTC_FLAGS += -C rpath
130 # The executables crated during this compilation process have no need to include
131 # static copies of libstd and libextra. We also generate dynamic versions of all
132 # libraries, so in the interest of space, prefer dynamic linking throughout the
133 # compilation process.
135 # Note though that these flags are omitted for stage2+. This means that the
136 # snapshot will be generated with a statically linked rustc so we only have to
137 # worry about the distribution of one file (with its native dynamic
139 RUSTFLAGS_STAGE0 += -C prefer-dynamic
140 RUSTFLAGS_STAGE1 += -C prefer-dynamic
142 # platform-specific auto-configuration
143 include $(CFG_SRC_DIR)mk/platform.mk
145 # Run the stage1/2 compilers under valgrind
146 ifdef VALGRIND_COMPILE
147 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
149 CFG_VALGRIND_COMPILE :=
152 ifdef CFG_ENABLE_VALGRIND
153 $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
157 ifdef CFG_BAD_VALGRIND
158 $(info cfg: disabling valgrind due to its unreliability on this platform)
163 ######################################################################
164 # Target-and-rule "utility variables"
165 ######################################################################
168 X_$(1) := $(CFG_EXE_SUFFIX_$(1))
170 $(foreach target,$(CFG_TARGET),\
171 $(eval $(call DEF_X,$(target))))
173 # "Source" files we generate in builddir along the way.
176 # Delete the built-in rules.
185 ######################################################################
186 # Cleaning out old crates
187 ######################################################################
189 # $(1) is the path for directory to match against
190 # $(2) is the glob to use in the match
192 # Note that a common bug is to accidentally construct the glob denoted
193 # by $(2) with a space character prefix, which invalidates the
194 # construction $(1)$(2).
195 define CHECK_FOR_OLD_GLOB_MATCHES
196 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: there are previous" \'$(notdir $(2))\' "libraries:" $$MATCHES; fi
199 # Same interface as above, but deletes rather than just listing the files.
201 define REMOVE_ALL_OLD_GLOB_MATCHES
202 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then echo "warning: removing previous" \'$(notdir $(1))\' "libraries:" $$MATCHES; rm $$MATCHES ; fi
205 define REMOVE_ALL_OLD_GLOB_MATCHES
206 $(Q)MATCHES="$(wildcard $(1))"; if [ -n "$$MATCHES" ] ; then rm $$MATCHES ; fi
210 # We use a different strategy for LIST_ALL_OLD_GLOB_MATCHES_EXCEPT
211 # than in the macros above because it needs the result of running the
212 # `ls` command after other rules in the command list have run; the
213 # macro-expander for $(wildcard ...) would deliver its results too
214 # soon. (This is in contrast to the macros above, which are meant to
215 # be run at the outset of a command list in a rule.)
217 define LIST_ALL_OLD_GLOB_MATCHES
218 @echo "info: now are following matches for" '$(notdir $(1))' "libraries:"
219 @( ls $(1) 2>/dev/null || true )
222 define LIST_ALL_OLD_GLOB_MATCHES
226 ######################################################################
228 ######################################################################
231 LLVM_COMPONENTS=x86 arm mips ipo bitreader bitwriter linker asmparser jit mcjit \
232 interpreter instrumentation
234 # Only build these LLVM tools
235 LLVM_TOOLS=bugpoint llc llvm-ar llvm-as llvm-dis llvm-mc opt llvm-extract
238 # The configure script defines these variables with the target triples
239 # separated by Z. This defines new ones with the expected format.
240 ifeq ($$(CFG_LLVM_ROOT),)
241 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
242 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
244 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_ROOT)
247 # Any rules that depend on LLVM should depend on LLVM_CONFIG
248 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
249 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
250 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
251 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
252 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
253 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
254 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
255 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
256 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
257 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
258 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
259 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
261 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))
262 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X_$(1))
266 $(foreach host,$(CFG_HOST), \
267 $(eval $(call DEF_LLVM_VARS,$(host))))
269 ######################################################################
270 # Exports for sub-utilities
271 ######################################################################
273 # Note that any variable that re-configure should pick up needs to be
285 export CFG_VERSION_WIN
287 export CFG_PACKAGE_NAME
290 export CFG_ENABLE_MINGW_CROSS
293 export CFG_LIBDIR_RELATIVE
294 export CFG_DISABLE_INJECT_STD_VERSION
296 ######################################################################
297 # Per-stage targets and runner
298 ######################################################################
303 # $(1) is the stage number
304 # $(2) is the target triple
305 # $(3) is the host triple
307 # Destinations of artifacts for the host compiler
308 HROOT$(1)_H_$(3) = $(3)/stage$(1)
309 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
310 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR_RELATIVE)
312 # Destinations of artifacts for target architectures
313 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustlib/$(2)
314 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
315 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/lib
317 # Preqrequisites for using the stageN compiler
319 HSREQ$(1)_H_$(3) = $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
322 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
326 # Prerequisites for using the stageN compiler to build target artifacts
327 TSREQ$(1)_T_$(2)_H_$(3) = \
328 $$(HSREQ$(1)_H_$(3)) \
329 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a \
330 $$(TLIB$(1)_T_$(2)_H_$(3))/libcompiler-rt.a
332 # Prerequisites for a working stageN compiler and libraries, for a specific
334 SREQ$(1)_T_$(2)_H_$(3) = \
335 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
336 $$(foreach dep,$$(TARGET_CRATES),\
337 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
339 # Prerequisites for a working stageN compiler and complete set of target
341 CSREQ$(1)_T_$(2)_H_$(3) = \
342 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
343 $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
344 $$(foreach dep,$$(CRATES),$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep))
347 # Don't run the stage0 compiler under valgrind - that ship has sailed
348 CFG_VALGRIND_COMPILE$(1) =
350 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
353 # Add RUSTFLAGS_STAGEN values to the build command
354 EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
356 CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
360 # Same macro/variables as above, but defined in a separate loop so it can use
361 # all the variables above for all archs. The RPATH_VAR setup sometimes needs to
362 # reach across triples to get things in order.
364 # Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
365 # * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
366 # environment to access or extend the lookup path for dynamic
367 # libraries. Note on Windows, that key is `$PATH`, and thus not
368 # only conflates programs with dynamic libraries, but also often
369 # contains spaces which confuse make.
370 # * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
371 # * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
373 # Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
378 ifeq ($$(OSTYPE_$(3)),apple-darwin)
379 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
381 ifeq ($$(CFG_WINDOWSY_$(3)),1)
382 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
384 LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
388 LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
389 $$(CURDIR)/$$(HLIB$(1)_H_$(3))
390 LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
391 $$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
393 HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
394 $$(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))
395 TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
396 $$(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))
398 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
400 # Pass --cfg stage0 only for the build->host part of stage0;
401 # if you're building a cross config, the host->* parts are
402 # effectively stage1, since it uses the just-built stage0.
404 # This logic is similar to how the LD_LIBRARY_PATH variable must
405 # change be slightly different when doing cross compilations.
406 # The build doesn't copy over all target libraries into
407 # a new directory, so we need to point the library path at
408 # the build directory where all the target libraries came
409 # from (the stage0 build host). Otherwise the relative rpaths
410 # inside of the rustc binary won't get resolved correctly.
412 ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
413 CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
415 RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
419 STAGE$(1)_T_$(2)_H_$(3) := \
420 $$(Q)$$(RPATH_VAR$(1)_T_$(2)_H_$(3)) \
421 $$(call CFG_RUN_TARG_$(3),$(1), \
422 $$(CFG_VALGRIND_COMPILE$(1)) \
423 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
424 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
425 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
428 PERF_STAGE$(1)_T_$(2)_H_$(3) := \
429 $$(Q)$$(call CFG_RUN_TARG_$(3),$(1), \
431 $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
432 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
433 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2)) \
438 $(foreach build,$(CFG_HOST), \
439 $(eval $(foreach target,$(CFG_TARGET), \
440 $(eval $(foreach stage,$(STAGES), \
441 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
443 $(foreach build,$(CFG_HOST), \
444 $(eval $(foreach target,$(CFG_TARGET), \
445 $(eval $(foreach stage,$(STAGES), \
446 $(eval $(call SREQ_CMDS,$(stage),$(target),$(build))))))))
448 ######################################################################
451 # Builds a functional Rustc for the given host.
452 ######################################################################
454 define DEF_RUSTC_STAGE_TARGET
455 # $(1) == architecture
458 rustc-stage$(2)-H-$(1): \
459 $$(foreach target,$$(CFG_TARGET),$$(SREQ$(2)_T_$$(target)_H_$(1)))
463 $(foreach host,$(CFG_HOST), \
464 $(eval $(foreach stage,1 2 3, \
465 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
467 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
468 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
469 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
471 define DEF_RUSTC_TARGET
472 # $(1) == architecture
474 rustc-H-$(1): rustc-stage2-H-$(1)
477 $(foreach host,$(CFG_TARGET), \
478 $(eval $(call DEF_RUSTC_TARGET,$(host))))
480 rustc-stage1: rustc-stage1-H-$(CFG_BUILD)
481 rustc-stage2: rustc-stage2-H-$(CFG_BUILD)
482 rustc-stage3: rustc-stage3-H-$(CFG_BUILD)
483 rustc: rustc-H-$(CFG_BUILD)
485 rustc-H-all: $(foreach host,$(CFG_HOST),rustc-H-$(host))
487 ######################################################################
489 ######################################################################
494 ifneq ($$(findstring $(1),$$(CFG_HOST)),)
496 all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
498 # This is a target only
499 all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
503 $(foreach target,$(CFG_TARGET), \
504 $(foreach host,$(CFG_HOST), \
505 $(eval $(call ALL_TARGET_N,$(target),$(host)))))
507 ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET), \
508 $(foreach host,$(CFG_HOST), \
509 all-target-$(target)-host-$(host)))
511 all: $(ALL_TARGET_RULES) $(GENERATED) docs
513 ######################################################################
514 # Build system documentation
515 ######################################################################
517 # $(1) is the name of the doc <section> in Makefile.in
518 # pick everything between tags | remove first line | remove last line
519 # | remove extra (?) line | strip leading `#` from lines
520 SHOW_DOCS = $(Q)awk '/<$(1)>/,/<\/$(1)>/' $(S)/Makefile.in | sed '1d' | sed '$$d' | sed 's/^\# \?//'
523 $(call SHOW_DOCS,help)
526 $(call SHOW_DOCS,tips)
529 $(call SHOW_DOCS,nitty-gritty)