blob: 25d44952444fb7e016011486c58420daef929509 [file] [log] [blame]
Brian Anderson6e654562011-10-02 03:12:081# An explanation of how the build is structured:
2#
3# There are multiple build stages (0-3) needed to verify that the
4# compiler is properly self-hosting. Each stage is divided between
5# 'host' artifacts and 'target' artifacts, where the stageN host
6# compiler builds artifacts for 1 or more stageN target architectures.
7# Once the stageN target compiler has been built for the host
8# architecture it is promoted (copied) to a stageN+1 host artifact.
9#
10# The stage3 host compiler is a compiler that successfully builds
11# itself and should (in theory) be bitwise identical to the stage2
12# host compiler. The process is bootstrapped using a stage0 host
13# compiler downloaded from a previous snapshot.
14#
15# At no time should stageN artifacts be interacting with artifacts
16# from other stages. For consistency, we use the 'promotion' logic
17# for all artifacts, even those that don't make sense on non-host
18# architectures.
19#
20# The directory layout for a stage is intended to match the layout
21# of the installed compiler, and looks like the following:
22#
23# stageN - this is the system root, corresponding to, e.g. /usr
24# bin - binaries compiled for the host
25# lib - libraries used by the host compiler
26# rustc - rustc's own place to organize libraries
27# $(target) - target-specific artifacts
28# bin - binaries for target architectures
29# lib - libraries for target architectures
30#
31# A note about host libraries:
32#
33# The only libraries that get promoted to stageN/lib are those needed
Brian Anderson19797df2011-11-03 17:53:4934# by rustc. In general, rust programs, even those compiled for the
Brian Anderson6e654562011-10-02 03:12:0835# host architecture will use libraries from the target
36# directories. This gives rust some freedom to experiment with how
37# libraries are managed and versioned without polluting the common
38# areas of the filesystem.
39#
40# General rust binaries may stil live in the host bin directory; they
41# will just link against the libraries in the target lib directory.
42#
43# Admittedly this is a little convoluted.
44
Niko Matsakis9c12c7c2011-11-21 21:11:4045STAGES = 0 1 2 3
46
Graydon Hoare9c6e7e62011-03-16 16:17:3247######################################################################
48# Residual auto-configuration
49######################################################################
50
Graydon Hoare071dbfc2012-03-26 23:04:3751# Recursive wildcard function
52# http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
53rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
54 $(filter $(subst *,%,$2),$d))
55
Graydon Hoare9c6e7e62011-03-16 16:17:3256include config.mk
Graydon Hoare9c6e7e62011-03-16 16:17:3257
Michael Sullivanf99f2e82012-06-14 18:07:1958# We track all of the object files we might build so that we can find
59# and include all of the .d files in one fell swoop.
60ALL_OBJ_FILES :=
61
Graydon Hoare071dbfc2012-03-26 23:04:3762MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
Niko Matsakis8371beb2011-11-22 21:04:5263NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
64
Graydon Hoare9c6e7e62011-03-16 16:17:3265ifneq ($(MAKE_RESTARTS),)
66CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
67endif
68
Graydon Hoare13215802011-09-21 18:24:5969CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
Graydon Hoaref9044532012-03-26 23:05:4970
71ifneq ($(wildcard $(NON_HOST_TRIPLES)),)
Niko Matsakis8371beb2011-11-22 21:04:5272CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
Graydon Hoaref9044532012-03-26 23:05:4973endif
Graydon Hoare9c6e7e62011-03-16 16:17:3274
Brian Andersonc8426d12012-05-20 01:27:1275CFG_RUSTC_FLAGS := $(RUSTFLAGS)
Brian Andersonf4529732012-03-30 02:10:3876CFG_GCCISH_CFLAGS :=
77CFG_GCCISH_LINK_FLAGS :=
78
Graydon Hoarecae703c2011-04-08 22:44:4179ifdef CFG_DISABLE_OPTIMIZE
Graydon Hoare19ebc0f2011-04-08 23:29:1980 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
Brian Andersonf4529732012-03-30 02:10:3881 CFG_RUSTC_FLAGS +=
Graydon Hoarecae703c2011-04-08 22:44:4182else
Brian Andersonf4529732012-03-30 02:10:3883 CFG_RUSTC_FLAGS += -O
84endif
85
86ifdef CFG_ENABLE_DEBUG
87 $(info cfg: enabling more debugging (CFG_ENABLE_DEBUG))
Brian Anderson1bd4e352012-07-03 00:21:2788 CFG_RUSTC_FLAGS +=
Brian Andersonf4529732012-03-30 02:10:3889 CFG_GCCISH_CFLAGS += -DRUST_DEBUG
90else
Brian Andersonf4529732012-03-30 02:10:3891 CFG_GCCISH_CFLAGS += -DRUST_NDEBUG
Graydon Hoarecae703c2011-04-08 22:44:4192endif
Graydon Hoare4c2245d2011-03-18 06:51:4593
Patrick Walton3f77e7d2011-04-25 21:20:2894ifdef SAVE_TEMPS
Marijn Haverbeke6b11f6c2011-04-26 18:32:0895 CFG_RUSTC_FLAGS += --save-temps
Patrick Walton3f77e7d2011-04-25 21:20:2896endif
Patrick Walton648c4ae2011-04-29 18:55:3297ifdef TIME_PASSES
Niko Matsakis5be8bf12012-05-18 04:53:4998 CFG_RUSTC_FLAGS += -Z time-passes
Patrick Walton648c4ae2011-04-29 18:55:3299endif
Brian Anderson27522842011-06-19 00:26:41100ifdef TIME_LLVM_PASSES
Niko Matsakis5be8bf12012-05-18 04:53:49101 CFG_RUSTC_FLAGS += -Z time-llvm-passes
Brian Anderson27522842011-06-19 00:26:41102endif
Niko Matsakis5e36a992012-08-28 22:54:45103ifdef TRACE
104 CFG_RUSTC_FLAGS += -Z trace
105endif
Patrick Walton3f77e7d2011-04-25 21:20:28106
Graydon Hoare40624e32011-05-01 20:18:52107# platform-specific auto-configuration
Graydon Hoare89dec282012-03-26 23:05:33108include $(CFG_SRC_DIR)mk/platform.mk
Graydon Hoare4c2245d2011-03-18 06:51:45109
Brian Andersoncad8c732011-05-14 03:20:34110# Run the stage1/2 compilers under valgrind
111ifdef VALGRIND_COMPILE
112 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
113else
114 CFG_VALGRIND_COMPILE :=
115endif
116
Graydon Hoare4c2245d2011-03-18 06:51:45117CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
Graydon Hoare7ac885e2011-03-22 06:06:42118CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
Graydon Hoare447414f2011-12-06 00:46:37119CFG_CORELIB :=$(call CFG_LIB_NAME,core)
Haitao Lib4f450a2011-11-18 08:00:28120CFG_STDLIB :=$(call CFG_LIB_NAME,std)
Brian Anderson5fb9cad2011-07-01 06:16:01121CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
Kevin Cantu7dcbaed2012-05-30 04:35:12122CFG_LIBSYNTAX :=$(call CFG_LIB_NAME,syntax)
Graydon Hoare4c2245d2011-03-18 06:51:45123
Haitao Li6dbd4c22011-12-02 16:51:59124STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
125CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
126LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
Kevin Cantu7dcbaed2012-05-30 04:35:12127LIBSYNTAX_GLOB :=$(call CFG_LIB_GLOB,syntax)
Josh Matthews81424382012-03-21 22:56:20128STDLIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,std)
129CORELIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,core)
130LIBRUSTC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustc)
Kevin Cantu7dcbaed2012-05-30 04:35:12131LIBSYNTAX_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,syntax)
Haitao Li6dbd4c22011-12-02 16:51:59132
Graydon Hoare1e03f002011-05-06 18:21:51133# version-string calculation
134CFG_GIT_DIR := $(CFG_SRC_DIR).git
Brian Anderson65b05a6c2012-08-30 21:05:49135CFG_RELEASE = 0.4
Graydon Hoare80c7bfb2012-01-18 00:49:44136CFG_VERSION = $(CFG_RELEASE)
137
Graydon Hoare0a8f9a32011-06-13 21:45:26138ifneq ($(wildcard $(CFG_GIT)),)
Graydon Hoare1e03f002011-05-06 18:21:51139ifneq ($(wildcard $(CFG_GIT_DIR)),)
140 CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
141 --pretty=format:'(%h %ci)')
Paul Stansiferfa882d42012-07-17 23:15:37142 CFG_VER_HASH = $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
143 --pretty=format:'%H')
Graydon Hoare1e03f002011-05-06 18:21:51144endif
Graydon Hoare0a8f9a32011-06-13 21:45:26145endif
Graydon Hoare1e03f002011-05-06 18:21:51146
Graydon Hoare94731fa2011-03-30 04:45:09147ifdef CFG_DISABLE_VALGRIND
148 $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
Graydon Hoare4c2245d2011-03-18 06:51:45149 CFG_VALGRIND :=
Graydon Hoare9c6e7e62011-03-16 16:17:32150endif
Patrick Walton518e2d22011-05-06 01:11:40151ifdef CFG_BAD_VALGRIND
152 $(info cfg: disabling valgrind due to its unreliability on this platform)
153 CFG_VALGRIND :=
154endif
Graydon Hoare9c6e7e62011-03-16 16:17:32155
Graydon Hoare28a4e772011-03-23 17:37:35156
Graydon Hoare4c2245d2011-03-18 06:51:45157######################################################################
158# Target-and-rule "utility variables"
159######################################################################
160
161ifdef VERBOSE
162 Q :=
163 E =
164else
165 Q := @
166 E = echo $(1)
167endif
168
Graydon Hoare4c2245d2011-03-18 06:51:45169S := $(CFG_SRC_DIR)
170X := $(CFG_EXE_SUFFIX)
171
172# Look in doc and src dirs.
173VPATH := $(S)doc $(S)src
174
Graydon Hoare4c2245d2011-03-18 06:51:45175# "Source" files we generate in builddir along the way.
Graydon Hoare40624e32011-05-01 20:18:52176GENERATED :=
Graydon Hoare4c2245d2011-03-18 06:51:45177
178# Delete the built-in rules.
179.SUFFIXES:
180%:: %,v
181%:: RCS/%,v
182%:: RCS/%
183%:: s.%
184%:: SCCS/s.%
Graydon Hoare9c6e7e62011-03-16 16:17:32185
Graydon Hoare4c2245d2011-03-18 06:51:45186######################################################################
Graydon Hoare447414f2011-12-06 00:46:37187# Core library variables
188######################################################################
189
190CORELIB_CRATE := $(S)src/libcore/core.rc
191CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
192 core.rc *.rs */*.rs))
193
194######################################################################
Graydon Hoare4c2245d2011-03-18 06:51:45195# Standard library variables
196######################################################################
197
Graydon Hoare447414f2011-12-06 00:46:37198STDLIB_CRATE := $(S)src/libstd/std.rc
199STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
200 std.rc *.rs */*.rs))
Graydon Hoare4c2245d2011-03-18 06:51:45201
202######################################################################
203# rustc crate variables
204######################################################################
205
Graydon Hoare87c14f12012-02-29 19:46:23206COMPILER_CRATE := $(S)src/rustc/rustc.rc
207COMPILER_INPUTS := $(filter-out $(S)src/rustc/driver/rustc.rs, \
208 $(wildcard $(addprefix $(S)src/rustc/, \
Niko Matsakis28d0ce92012-05-19 17:31:48209 rustc.rc *.rs */*.rs */*/*.rs */*/*/*.rs)))
Haitao Libc95ccb2011-12-20 10:17:13210
Kevin Cantu7dcbaed2012-05-30 04:35:12211LIBSYNTAX_CRATE := $(S)src/libsyntax/syntax.rc
212LIBSYNTAX_INPUTS := $(wildcard $(addprefix $(S)src/libsyntax/, \
213 syntax.rc *.rs */*.rs */*/*.rs))
Brian Andersona0ed1fb2012-03-22 22:27:35214
Graydon Hoare87c14f12012-02-29 19:46:23215RUSTC_INPUTS := $(S)src/rustc/driver/rustc.rs
Graydon Hoare4c2245d2011-03-18 06:51:45216
217######################################################################
Brian Andersona0ff3db2011-11-02 00:09:44218# LLVM macros
219######################################################################
220
Brian Andersona92218e2011-11-27 06:38:36221# FIXME: x86-ism
Zack Corrd7aa9912012-08-25 04:54:30222LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser jit mcjit \
223 interpreter
Brian Andersona92218e2011-11-27 06:38:36224
Brian Anderson4b6585c2011-11-02 23:21:17225define DEF_LLVM_VARS
226# The configure script defines these variables with the target triples
227# separated by Z. This defines new ones with the expected format.
228CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
229CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
Brian Andersona0ff3db2011-11-02 00:09:44230
Brian Anderson4b6585c2011-11-02 23:21:17231# Any rules that depend on LLVM should depend on LLVM_CONFIG
Brian Anderson283cf352011-12-14 06:43:32232LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X)
233LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X)
Brian Anderson4b6585c2011-11-02 23:21:17234LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
235LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
236LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
237LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
Brian Andersona92218e2011-11-27 06:38:36238LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
Brian Anderson4b6585c2011-11-02 23:21:17239LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
Jyun-Yan You5e250b62012-01-26 09:13:57240# On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
241# so we replace -I with -iquote to ensure that it searches bundled LLVM first.
242LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
Brian Anderson4b6585c2011-11-02 23:21:17243LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
244
Brian Andersonecdeffb2011-12-14 03:03:43245LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X)
246LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)
Brian Anderson4b6585c2011-11-02 23:21:17247
248endef
249
250$(foreach target,$(CFG_TARGET_TRIPLES), \
251 $(eval $(call DEF_LLVM_VARS,$(target))))
252
Brian Andersona0ff3db2011-11-02 00:09:44253######################################################################
Graydon Hoared987b492011-05-03 06:37:52254# Exports for sub-utilities
255######################################################################
256
Brian Anderson6e654562011-10-02 03:12:08257# Note that any variable that re-configure should pick up needs to be
258# exported
259
Graydon Hoared987b492011-05-03 06:37:52260export CFG_SRC_DIR
Graydon Hoaread954fc2011-07-23 19:26:47261export CFG_BUILD_DIR
Graydon Hoare1e03f002011-05-06 18:21:51262export CFG_VERSION
Brian Anderson6306c812011-09-29 19:21:58263export CFG_HOST_TRIPLE
Graydon Hoare6a4a85f2011-05-18 19:00:26264export CFG_LLVM_ROOT
Graydon Hoare0dc2aa32011-06-28 18:18:25265export CFG_ENABLE_MINGW_CROSS
Brian Anderson6e654562011-10-02 03:12:08266export CFG_PREFIX
Brian Anderson9e40e432012-01-11 01:45:03267export CFG_LIBDIR
Graydon Hoared987b492011-05-03 06:37:52268
Patrick Walton04f966f2011-05-05 01:28:30269######################################################################
270# Subprograms
271######################################################################
272
Graydon Hoared987b492011-05-03 06:37:52273######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41274# Per-stage targets and runner
275######################################################################
276
277define SREQ
Niko Matsakis9c12c7c2011-11-21 21:11:40278# $(1) is the stage number
279# $(2) is the target triple
Graydon Hoare766e29c2011-11-30 03:28:15280# $(3) is the host triple
Brian Andersoned106dd2011-09-30 19:08:51281
Brian Anderson38c67a42011-09-30 19:24:28282# Destinations of artifacts for the host compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40283HROOT$(1)_H_$(3) = $(3)/stage$(1)
284HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03285HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
Brian Anderson38c67a42011-09-30 19:24:28286
Brian Anderson9563c172011-10-01 02:00:19287# Destinations of artifacts for target architectures
Niko Matsakis9c12c7c2011-11-21 21:11:40288TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
289TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03290TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
Brian Andersoned106dd2011-09-30 19:08:51291
Graydon Hoare447414f2011-12-06 00:46:37292# The name of the core and standard libraries used by rustc
Rafael Ávila de Espíndola88894b62011-07-20 20:02:36293ifdef CFG_DISABLE_SHAREDSTD
Graydon Hoare447414f2011-12-06 00:46:37294 HCORELIB_DEFAULT$(1)_H_$(3) = \
295 $$(HLIB$(1)_H_$(3))/libcore.rlib
296 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
297 $$(TLIB$(1)_T_$(2)_H_$(3))/libcore.rlib
Graydon Hoare4f826b32011-12-17 01:21:18298
Niko Matsakis9c12c7c2011-11-21 21:11:40299 HSTDLIB_DEFAULT$(1)_H_$(3) = \
300 $$(HLIB$(1)_H_$(3))/libstd.rlib
301 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
302 $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
Graydon Hoare4f826b32011-12-17 01:21:18303
304 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
305 $$(HLIB$(1)_H_$(3))/librustc.rlib
306 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
307 $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
Brian Andersonf634eb22011-09-30 23:11:47308else
Graydon Hoare447414f2011-12-06 00:46:37309 HCORELIB_DEFAULT$(1)_H_$(3) = \
310 $$(HLIB$(1)_H_$(3))/$(CFG_CORELIB)
311 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
312 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB)
Graydon Hoare4f826b32011-12-17 01:21:18313
Niko Matsakis9c12c7c2011-11-21 21:11:40314 HSTDLIB_DEFAULT$(1)_H_$(3) = \
315 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB)
316 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
317 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB)
Graydon Hoare4f826b32011-12-17 01:21:18318
319 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
320 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC)
321 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
322 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC)
Brian Andersonf634eb22011-09-30 23:11:47323endif
324
Brian Anderson6e654562011-10-02 03:12:08325# Preqrequisites for using the stageN compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40326HSREQ$(1)_H_$(3) = \
327 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
328 $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \
329 $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \
Graydon Hoare447414f2011-12-06 00:46:37330 $$(HCORELIB_DEFAULT$(1)_H_$(3)) \
Niko Matsakis9c12c7c2011-11-21 21:11:40331 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
Graydon Hoare4f826b32011-12-17 01:21:18332 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
Niko Matsakis5ce33ce2011-11-29 20:42:05333 $$(MKFILE_DEPS)
Brian Anderson6e654562011-10-02 03:12:08334
335# Prerequisites for using the stageN compiler to build target artifacts
Niko Matsakis9c12c7c2011-11-21 21:11:40336TSREQ$(1)_T_$(2)_H_$(3) = \
337 $$(HSREQ$(1)_H_$(3)) \
Brian Anderson8f0bd182012-06-02 04:46:10338 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME) \
Niko Matsakis9c12c7c2011-11-21 21:11:40339 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
Brian Anderson6e654562011-10-02 03:12:08340
341# Prerequisites for complete stageN targets
Niko Matsakis9c12c7c2011-11-21 21:11:40342SREQ$(1)_T_$(2)_H_$(3) = \
343 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
Graydon Hoare447414f2011-12-06 00:46:37344 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
Graydon Hoare4f826b32011-12-17 01:21:18345 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
346 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
Graydon Hoarefafb42e2011-07-15 23:12:41347
Brian Andersone3d3aaa2011-08-26 18:11:49348ifeq ($(1),0)
349# Don't run the the stage0 compiler under valgrind - that ship has sailed
350CFG_VALGRIND_COMPILE$(1) =
351else
352CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
353endif
354
Brian Andersonc88ab582012-06-27 23:01:19355# Add RUSTFLAGS_STAGEN values to the build command
356EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
357
Brian Andersoncb341382012-09-23 21:05:44358CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
359
Graydon Hoaree7b83882012-09-26 21:57:35360# Pass --cfg stage0 only for the build->host part of stage0;
361# if you're building a cross config, the host->* parts are
362# effectively stage1, since it uses the just-built stage0.
363ifeq ($(1),0)
364ifneq ($(strip $(CFG_HOST_TRIPLE)),$(strip $(3)))
365CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
366endif
367endif
368
Niko Matsakis9c12c7c2011-11-21 21:11:40369STAGE$(1)_T_$(2)_H_$(3) := \
370 $$(Q)$$(call CFG_RUN_TARG,$(1), \
371 $$(CFG_VALGRIND_COMPILE$(1)) \
372 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
Brian Andersoncb341382012-09-23 21:05:44373 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
Brian Andersonc88ab582012-06-27 23:01:19374 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37375
Niko Matsakis9c12c7c2011-11-21 21:11:40376PERF_STAGE$(1)_T_$(2)_H_$(3) := \
377 $$(Q)$$(call CFG_RUN_TARG,$(1), \
378 $$(CFG_PERF_TOOL) \
379 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
Brian Andersoncb341382012-09-23 21:05:44380 --cfg $$(CFGFLAG$(1)_T_$(2)_H_$(3)) \
Brian Andersonc88ab582012-06-27 23:01:19381 $$(CFG_RUSTC_FLAGS) $$(EXTRAFLAGS_STAGE$(1)) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37382
Graydon Hoarefafb42e2011-07-15 23:12:41383endef
384
Niko Matsakis9c12c7c2011-11-21 21:11:40385$(foreach build,$(CFG_TARGET_TRIPLES), \
386 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
387 $(eval $(foreach stage,$(STAGES), \
388 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
Graydon Hoarefafb42e2011-07-15 23:12:41389
390######################################################################
Niko Matsakis3bbfe512011-12-03 00:04:27391# rustc-H-targets
392#
393# Builds a functional Rustc for the given host.
394######################################################################
395
Niko Matsakis15d60322011-12-06 22:02:03396define DEF_RUSTC_STAGE_TARGET
397# $(1) == architecture
398# $(2) == stage
399
400rustc-stage$(2)-H-$(1): \
401 $$(foreach target,$$(CFG_TARGET_TRIPLES), \
402 $$(SREQ$(2)_T_$$(target)_H_$(1)))
403
404endef
405
406$(foreach host,$(CFG_TARGET_TRIPLES), \
407 $(eval $(foreach stage,1 2 3, \
408 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
409
Niko Matsakisc28ada02011-12-09 16:16:04410rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
411rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
412rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
413
Niko Matsakis3bbfe512011-12-03 00:04:27414define DEF_RUSTC_TARGET
415# $(1) == architecture
416
Haitao Li394a80c2012-01-16 05:42:03417rustc-H-$(1): rustc-stage2-H-$(1)
Niko Matsakis3bbfe512011-12-03 00:04:27418endef
419
420$(foreach host,$(CFG_TARGET_TRIPLES), \
421 $(eval $(call DEF_RUSTC_TARGET,$(host))))
422
Niko Matsakis68c62722011-12-13 04:28:35423rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
424rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
425rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
426rustc: rustc-H-$(CFG_HOST_TRIPLE)
427
Niko Matsakis49349292011-12-03 00:11:35428rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
Niko Matsakis3bbfe512011-12-03 00:04:27429
430######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41431# Entrypoint rule
Graydon Hoare4c2245d2011-03-18 06:51:45432######################################################################
433
Brian Andersonc9b14cc2011-12-13 20:02:17434.DEFAULT_GOAL := all
435
Graydon Hoareae784df2011-05-14 00:00:43436ifneq ($(CFG_IN_TRANSITION),)
437
Graydon Hoare9ac29482011-05-16 22:14:58438CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43439CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
440CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
Graydon Hoare9ac29482011-05-16 22:14:58441CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43442
Graydon Hoare193279d2012-01-18 22:14:28443all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) docs
Brian Andersonb0560962011-09-30 23:15:02444
Graydon Hoareae784df2011-05-14 00:00:43445else
Brian Anderson86ed9052011-09-30 03:27:28446
Niko Matsakis9c12c7c2011-11-21 21:11:40447TSREQS := \
448 $(foreach target,$(CFG_TARGET_TRIPLES), \
449 $(SREQ3_T_$(target)_H_$(CFG_HOST_TRIPLE)))
Erick Tryzelaare8493112012-06-06 04:40:57450FUZZ := $(HBIN2_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
451CARGO := $(HBIN2_H_$(CFG_HOST_TRIPLE))/cargo$(X)
452RUSTDOC := $(HBIN2_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
Brian Anderson86ed9052011-09-30 03:27:28453
Niko Matsakisd365ec52012-03-15 14:39:57454all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC)
Brian Anderson6e654562011-10-02 03:12:08455
Graydon Hoareae784df2011-05-14 00:00:43456endif
457
Graydon Hoare10f33602011-03-25 17:29:45458
459######################################################################
460# Re-configuration
461######################################################################
462
Brian Anderson8d7863f2011-11-29 01:50:23463ifndef CFG_DISABLE_MANAGE_SUBMODULES
Brian Anderson0e150112011-11-01 01:19:40464# This is a pretty expensive operation but I don't see any way to avoid it
Brian Anderson143f8782011-11-26 04:00:48465NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
Brian Anderson8d7863f2011-11-29 01:50:23466else
467NEED_GIT_RECONFIG=0
468endif
Brian Anderson0e150112011-11-01 01:19:40469
470ifeq ($(NEED_GIT_RECONFIG),0)
471else
472# If the submodules have changed then always execute config.mk
Graydon Hoare071dbfc2012-03-26 23:04:37473.PHONY: config.stamp
Brian Anderson0e150112011-11-01 01:19:40474endif
475
Graydon Hoare071dbfc2012-03-26 23:04:37476Makefile config.mk: config.stamp
477
478config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
Graydon Hoare10f33602011-03-25 17:29:45479 @$(call E, cfg: reconfiguring)
Graydon Hoaredf8161d2011-06-30 20:41:20480 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
Graydon Hoare10f33602011-03-25 17:29:45481
482
Graydon Hoaree961f532011-03-21 18:23:19483######################################################################
Graydon Hoare79ba3152011-06-25 19:23:27484# Primary-target makefiles
Graydon Hoaree961f532011-03-21 18:23:19485######################################################################
486
Graydon Hoare89dec282012-03-26 23:05:33487include $(CFG_SRC_DIR)mk/target.mk
488include $(CFG_SRC_DIR)mk/host.mk
489include $(CFG_SRC_DIR)mk/stage0.mk
490include $(CFG_SRC_DIR)mk/rt.mk
491include $(CFG_SRC_DIR)mk/rustllvm.mk
Graydon Hoare89dec282012-03-26 23:05:33492include $(CFG_SRC_DIR)mk/tools.mk
493include $(CFG_SRC_DIR)mk/docs.mk
494include $(CFG_SRC_DIR)mk/llvm.mk
Graydon Hoare79ba3152011-06-25 19:23:27495
Graydon Hoare79ba3152011-06-25 19:23:27496######################################################################
497# Secondary makefiles, conditionalized for speed
498######################################################################
499
Graydon Hoaredf8161d2011-06-30 20:41:20500ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
501 $(findstring check,$(MAKECMDGOALS)) \
502 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoare39151f22011-07-13 22:44:09503 $(findstring tidy,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20504 $(findstring clean,$(MAKECMDGOALS))),)
505 CFG_INFO := $(info cfg: including dist rules)
Graydon Hoare89dec282012-03-26 23:05:33506 include $(CFG_SRC_DIR)mk/dist.mk
Graydon Hoare79ba3152011-06-25 19:23:27507endif
508
Graydon Hoaredf8161d2011-06-30 20:41:20509ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
510 $(findstring clean,$(MAKECMDGOALS))),)
511 CFG_INFO := $(info cfg: including snap rules)
Graydon Hoare89dec282012-03-26 23:05:33512 include $(CFG_SRC_DIR)mk/snap.mk
Graydon Hoare79ba3152011-06-25 19:23:27513endif
514
515ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20516 CFG_INFO := $(info cfg: including reformat rules)
Graydon Hoare89dec282012-03-26 23:05:33517 include $(CFG_SRC_DIR)mk/pp.mk
Graydon Hoare79ba3152011-06-25 19:23:27518endif
519
Graydon Hoaredf8161d2011-06-30 20:41:20520ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
521 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoared5b2d622011-09-13 22:06:21522 $(findstring perf,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20523 $(findstring tidy,$(MAKECMDGOALS))),)
524 CFG_INFO := $(info cfg: including test rules)
Graydon Hoare89dec282012-03-26 23:05:33525 include $(CFG_SRC_DIR)mk/tests.mk
Graydon Hoare79ba3152011-06-25 19:23:27526endif
527
Graydon Hoared5b2d622011-09-13 22:06:21528ifneq ($(findstring perf,$(MAKECMDGOALS)),)
529 CFG_INFO := $(info cfg: including perf rules)
Graydon Hoare89dec282012-03-26 23:05:33530 include $(CFG_SRC_DIR)mk/perf.mk
Graydon Hoared5b2d622011-09-13 22:06:21531endif
532
Graydon Hoare79ba3152011-06-25 19:23:27533ifneq ($(findstring clean,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20534 CFG_INFO := $(info cfg: including clean rules)
Graydon Hoare89dec282012-03-26 23:05:33535 include $(CFG_SRC_DIR)mk/clean.mk
Michael Sullivanb01ecb12011-07-21 18:58:01536endif
Brian Anderson9563c172011-10-01 02:00:19537
538ifneq ($(findstring install,$(MAKECMDGOALS)),)
Kevin Cantuc9d53ca2012-01-20 12:17:32539 ifdef DESTDIR
540 CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR))
541 CFG_PREFIX:=$(DESTDIR)
542 export CFG_PREFIX
543 endif
544
Brian Anderson9563c172011-10-01 02:00:19545 CFG_INFO := $(info cfg: including install rules)
Graydon Hoare89dec282012-03-26 23:05:33546 include $(CFG_SRC_DIR)mk/install.mk
Niko Matsakise1c470c2011-10-12 19:10:21547endif
548
549ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
550 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
551 CFG_INFO := $(info cfg: including ctags rules)
Graydon Hoare89dec282012-03-26 23:05:33552 include $(CFG_SRC_DIR)mk/ctags.mk
Niko Matsakise1c470c2011-10-12 19:10:21553endif
Michael Sullivanf99f2e82012-06-14 18:07:19554
555# Find all of the .d files and include them to add information about
556# header file dependencies.
557ALL_DEP_FILES := $(ALL_OBJ_FILES:%.o=%.d)
558-include $(ALL_DEP_FILES)