blob: 910f6b8a566917968dd866d0de6a0c777f70085d [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
Graydon Hoare071dbfc2012-03-26 23:04:3758MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
Niko Matsakis8371beb2011-11-22 21:04:5259NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
60
Graydon Hoare9c6e7e62011-03-16 16:17:3261ifneq ($(MAKE_RESTARTS),)
62CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
63endif
64
Graydon Hoare13215802011-09-21 18:24:5965CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
Graydon Hoaref9044532012-03-26 23:05:4966
67ifneq ($(wildcard $(NON_HOST_TRIPLES)),)
Niko Matsakis8371beb2011-11-22 21:04:5268CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
Graydon Hoaref9044532012-03-26 23:05:4969endif
Graydon Hoare9c6e7e62011-03-16 16:17:3270
Graydon Hoarecae703c2011-04-08 22:44:4171ifdef CFG_DISABLE_OPTIMIZE
Graydon Hoare19ebc0f2011-04-08 23:29:1972 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
Patrick Waltonc52fb522011-04-29 17:23:0773 CFG_RUSTC_FLAGS :=
Graydon Hoarecae703c2011-04-08 22:44:4174else
Patrick Waltonc52fb522011-04-29 17:23:0775 CFG_RUSTC_FLAGS := -O
Graydon Hoarecae703c2011-04-08 22:44:4176endif
Graydon Hoare4c2245d2011-03-18 06:51:4577
Patrick Walton3f77e7d2011-04-25 21:20:2878ifdef SAVE_TEMPS
Marijn Haverbeke6b11f6c2011-04-26 18:32:0879 CFG_RUSTC_FLAGS += --save-temps
Patrick Walton3f77e7d2011-04-25 21:20:2880endif
Niko Matsakis674587c2012-03-07 04:48:5581ifdef ENFORCE_MUT_VARS
82 CFG_RUSTC_FLAGS += --enforce-mut-vars
83endif
Patrick Walton648c4ae2011-04-29 18:55:3284ifdef TIME_PASSES
85 CFG_RUSTC_FLAGS += --time-passes
86endif
Brian Anderson27522842011-06-19 00:26:4187ifdef TIME_LLVM_PASSES
88 CFG_RUSTC_FLAGS += --time-llvm-passes
89endif
Patrick Walton404db4d2011-05-11 00:48:4990ifdef DEBUG
91 CFG_RUSTC_FLAGS += -g
92endif
Patrick Walton3f77e7d2011-04-25 21:20:2893
Graydon Hoare40624e32011-05-01 20:18:5294# platform-specific auto-configuration
Graydon Hoare89dec282012-03-26 23:05:3395include $(CFG_SRC_DIR)mk/platform.mk
Graydon Hoare4c2245d2011-03-18 06:51:4596
Brian Andersoncad8c732011-05-14 03:20:3497# Run the stage1/2 compilers under valgrind
98ifdef VALGRIND_COMPILE
99 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
100else
101 CFG_VALGRIND_COMPILE :=
102endif
103
Graydon Hoare4c2245d2011-03-18 06:51:45104CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
Graydon Hoare7ac885e2011-03-22 06:06:42105CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
Graydon Hoare447414f2011-12-06 00:46:37106CFG_CORELIB :=$(call CFG_LIB_NAME,core)
Haitao Lib4f450a2011-11-18 08:00:28107CFG_STDLIB :=$(call CFG_LIB_NAME,std)
Brian Anderson5fb9cad2011-07-01 06:16:01108CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
Graydon Hoare4c2245d2011-03-18 06:51:45109
Haitao Li6dbd4c22011-12-02 16:51:59110STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
111CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
112LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
Josh Matthews81424382012-03-21 22:56:20113STDLIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,std)
114CORELIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,core)
115LIBRUSTC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustc)
Haitao Li6dbd4c22011-12-02 16:51:59116
Graydon Hoare1e03f002011-05-06 18:21:51117# version-string calculation
118CFG_GIT_DIR := $(CFG_SRC_DIR).git
Brian Andersonf3fe85d2012-03-22 22:25:02119CFG_RELEASE = 0.2
Graydon Hoare80c7bfb2012-01-18 00:49:44120CFG_VERSION = $(CFG_RELEASE)
121
Graydon Hoare0a8f9a32011-06-13 21:45:26122ifneq ($(wildcard $(CFG_GIT)),)
Graydon Hoare1e03f002011-05-06 18:21:51123ifneq ($(wildcard $(CFG_GIT_DIR)),)
124 CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
125 --pretty=format:'(%h %ci)')
126endif
Graydon Hoare0a8f9a32011-06-13 21:45:26127endif
Graydon Hoare1e03f002011-05-06 18:21:51128
Graydon Hoare94731fa2011-03-30 04:45:09129ifdef CFG_DISABLE_VALGRIND
130 $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
Graydon Hoare4c2245d2011-03-18 06:51:45131 CFG_VALGRIND :=
Graydon Hoare9c6e7e62011-03-16 16:17:32132endif
Patrick Walton518e2d22011-05-06 01:11:40133ifdef CFG_BAD_VALGRIND
134 $(info cfg: disabling valgrind due to its unreliability on this platform)
135 CFG_VALGRIND :=
136endif
Graydon Hoare9c6e7e62011-03-16 16:17:32137
Graydon Hoare28a4e772011-03-23 17:37:35138
Graydon Hoare4c2245d2011-03-18 06:51:45139######################################################################
140# Target-and-rule "utility variables"
141######################################################################
142
143ifdef VERBOSE
144 Q :=
145 E =
146else
147 Q := @
148 E = echo $(1)
149endif
150
Graydon Hoare4c2245d2011-03-18 06:51:45151S := $(CFG_SRC_DIR)
152X := $(CFG_EXE_SUFFIX)
153
154# Look in doc and src dirs.
155VPATH := $(S)doc $(S)src
156
Graydon Hoare4c2245d2011-03-18 06:51:45157# "Source" files we generate in builddir along the way.
Graydon Hoare40624e32011-05-01 20:18:52158GENERATED :=
Graydon Hoare4c2245d2011-03-18 06:51:45159
160# Delete the built-in rules.
161.SUFFIXES:
162%:: %,v
163%:: RCS/%,v
164%:: RCS/%
165%:: s.%
166%:: SCCS/s.%
Graydon Hoare9c6e7e62011-03-16 16:17:32167
Graydon Hoare4c2245d2011-03-18 06:51:45168######################################################################
Graydon Hoare447414f2011-12-06 00:46:37169# Core library variables
170######################################################################
171
172CORELIB_CRATE := $(S)src/libcore/core.rc
173CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
174 core.rc *.rs */*.rs))
175
176######################################################################
Graydon Hoare4c2245d2011-03-18 06:51:45177# Standard library variables
178######################################################################
179
Graydon Hoare447414f2011-12-06 00:46:37180STDLIB_CRATE := $(S)src/libstd/std.rc
181STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
182 std.rc *.rs */*.rs))
Graydon Hoare4c2245d2011-03-18 06:51:45183
184######################################################################
185# rustc crate variables
186######################################################################
187
Graydon Hoare87c14f12012-02-29 19:46:23188COMPILER_CRATE := $(S)src/rustc/rustc.rc
189COMPILER_INPUTS := $(filter-out $(S)src/rustc/driver/rustc.rs, \
190 $(wildcard $(addprefix $(S)src/rustc/, \
Graydon Hoare0fba2d02012-01-10 22:34:53191 rustc.rc *.rs */*.rs */*/*.rs)))
Haitao Libc95ccb2011-12-20 10:17:13192
Graydon Hoare87c14f12012-02-29 19:46:23193RUSTC_INPUTS := $(S)src/rustc/driver/rustc.rs
Graydon Hoare4c2245d2011-03-18 06:51:45194
195######################################################################
Brian Andersona0ff3db2011-11-02 00:09:44196# LLVM macros
197######################################################################
198
Brian Andersona92218e2011-11-27 06:38:36199# FIXME: x86-ism
200LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser
201
Brian Anderson4b6585c2011-11-02 23:21:17202define DEF_LLVM_VARS
203# The configure script defines these variables with the target triples
204# separated by Z. This defines new ones with the expected format.
205CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
206CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
Brian Andersona0ff3db2011-11-02 00:09:44207
Brian Anderson4b6585c2011-11-02 23:21:17208# Any rules that depend on LLVM should depend on LLVM_CONFIG
Brian Anderson283cf352011-12-14 06:43:32209LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X)
210LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X)
Brian Anderson4b6585c2011-11-02 23:21:17211LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
212LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
213LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
214LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
Brian Andersona92218e2011-11-27 06:38:36215LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
Brian Anderson4b6585c2011-11-02 23:21:17216LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
Jyun-Yan You5e250b62012-01-26 09:13:57217# On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
218# so we replace -I with -iquote to ensure that it searches bundled LLVM first.
219LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
Brian Anderson4b6585c2011-11-02 23:21:17220LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
221
Brian Andersonecdeffb2011-12-14 03:03:43222LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X)
223LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)
Brian Anderson4b6585c2011-11-02 23:21:17224
225endef
226
227$(foreach target,$(CFG_TARGET_TRIPLES), \
228 $(eval $(call DEF_LLVM_VARS,$(target))))
229
Brian Andersona0ff3db2011-11-02 00:09:44230######################################################################
Graydon Hoared987b492011-05-03 06:37:52231# Exports for sub-utilities
232######################################################################
233
Brian Anderson6e654562011-10-02 03:12:08234# Note that any variable that re-configure should pick up needs to be
235# exported
236
Graydon Hoared987b492011-05-03 06:37:52237export CFG_SRC_DIR
Graydon Hoaread954fc2011-07-23 19:26:47238export CFG_BUILD_DIR
Graydon Hoare1e03f002011-05-06 18:21:51239export CFG_VERSION
Brian Anderson6306c812011-09-29 19:21:58240export CFG_HOST_TRIPLE
Graydon Hoare6a4a85f2011-05-18 19:00:26241export CFG_LLVM_ROOT
Graydon Hoare0dc2aa32011-06-28 18:18:25242export CFG_ENABLE_MINGW_CROSS
Brian Anderson6e654562011-10-02 03:12:08243export CFG_PREFIX
Brian Anderson9e40e432012-01-11 01:45:03244export CFG_LIBDIR
Graydon Hoared987b492011-05-03 06:37:52245
Patrick Walton04f966f2011-05-05 01:28:30246######################################################################
247# Subprograms
248######################################################################
249
Graydon Hoared987b492011-05-03 06:37:52250######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41251# Per-stage targets and runner
252######################################################################
253
254define SREQ
Niko Matsakis9c12c7c2011-11-21 21:11:40255# $(1) is the stage number
256# $(2) is the target triple
Graydon Hoare766e29c2011-11-30 03:28:15257# $(3) is the host triple
Brian Andersoned106dd2011-09-30 19:08:51258
Brian Anderson38c67a42011-09-30 19:24:28259# Destinations of artifacts for the host compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40260HROOT$(1)_H_$(3) = $(3)/stage$(1)
261HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03262HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
Brian Anderson38c67a42011-09-30 19:24:28263
Brian Anderson9563c172011-10-01 02:00:19264# Destinations of artifacts for target architectures
Niko Matsakis9c12c7c2011-11-21 21:11:40265TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
266TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03267TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
Brian Andersoned106dd2011-09-30 19:08:51268
Graydon Hoare447414f2011-12-06 00:46:37269# The name of the core and standard libraries used by rustc
Rafael Ávila de Espíndola88894b62011-07-20 20:02:36270ifdef CFG_DISABLE_SHAREDSTD
Graydon Hoare447414f2011-12-06 00:46:37271 HCORELIB_DEFAULT$(1)_H_$(3) = \
272 $$(HLIB$(1)_H_$(3))/libcore.rlib
273 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
274 $$(TLIB$(1)_T_$(2)_H_$(3))/libcore.rlib
Graydon Hoare4f826b32011-12-17 01:21:18275
Niko Matsakis9c12c7c2011-11-21 21:11:40276 HSTDLIB_DEFAULT$(1)_H_$(3) = \
277 $$(HLIB$(1)_H_$(3))/libstd.rlib
278 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
279 $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
Graydon Hoare4f826b32011-12-17 01:21:18280
281 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
282 $$(HLIB$(1)_H_$(3))/librustc.rlib
283 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
284 $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
Brian Andersonf634eb22011-09-30 23:11:47285else
Graydon Hoare447414f2011-12-06 00:46:37286 HCORELIB_DEFAULT$(1)_H_$(3) = \
287 $$(HLIB$(1)_H_$(3))/$(CFG_CORELIB)
288 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
289 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB)
Graydon Hoare4f826b32011-12-17 01:21:18290
Niko Matsakis9c12c7c2011-11-21 21:11:40291 HSTDLIB_DEFAULT$(1)_H_$(3) = \
292 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB)
293 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
294 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB)
Graydon Hoare4f826b32011-12-17 01:21:18295
296 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
297 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC)
298 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
299 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC)
Brian Andersonf634eb22011-09-30 23:11:47300endif
301
Brian Anderson6e654562011-10-02 03:12:08302# Preqrequisites for using the stageN compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40303HSREQ$(1)_H_$(3) = \
304 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
305 $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \
306 $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \
Graydon Hoare447414f2011-12-06 00:46:37307 $$(HCORELIB_DEFAULT$(1)_H_$(3)) \
Niko Matsakis9c12c7c2011-11-21 21:11:40308 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
Graydon Hoare4f826b32011-12-17 01:21:18309 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
Niko Matsakis5ce33ce2011-11-29 20:42:05310 $$(MKFILE_DEPS)
Brian Anderson6e654562011-10-02 03:12:08311
312# Prerequisites for using the stageN compiler to build target artifacts
Niko Matsakis9c12c7c2011-11-21 21:11:40313TSREQ$(1)_T_$(2)_H_$(3) = \
314 $$(HSREQ$(1)_H_$(3)) \
315 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME) \
Niko Matsakis9c12c7c2011-11-21 21:11:40316 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
Brian Anderson6e654562011-10-02 03:12:08317
318# Prerequisites for complete stageN targets
Niko Matsakis9c12c7c2011-11-21 21:11:40319SREQ$(1)_T_$(2)_H_$(3) = \
320 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
Graydon Hoare447414f2011-12-06 00:46:37321 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
Graydon Hoare4f826b32011-12-17 01:21:18322 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
323 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
Graydon Hoarefafb42e2011-07-15 23:12:41324
Brian Andersone3d3aaa2011-08-26 18:11:49325ifeq ($(1),0)
326# Don't run the the stage0 compiler under valgrind - that ship has sailed
327CFG_VALGRIND_COMPILE$(1) =
328else
329CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
330endif
331
Niko Matsakis9c12c7c2011-11-21 21:11:40332STAGE$(1)_T_$(2)_H_$(3) := \
333 $$(Q)$$(call CFG_RUN_TARG,$(1), \
334 $$(CFG_VALGRIND_COMPILE$(1)) \
335 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
336 $$(CFG_RUSTC_FLAGS) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37337
Niko Matsakis9c12c7c2011-11-21 21:11:40338PERF_STAGE$(1)_T_$(2)_H_$(3) := \
339 $$(Q)$$(call CFG_RUN_TARG,$(1), \
340 $$(CFG_PERF_TOOL) \
341 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
342 $$(CFG_RUSTC_FLAGS) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37343
Graydon Hoarefafb42e2011-07-15 23:12:41344endef
345
Niko Matsakis9c12c7c2011-11-21 21:11:40346$(foreach build,$(CFG_TARGET_TRIPLES), \
347 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
348 $(eval $(foreach stage,$(STAGES), \
349 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
Graydon Hoarefafb42e2011-07-15 23:12:41350
351######################################################################
Niko Matsakis3bbfe512011-12-03 00:04:27352# rustc-H-targets
353#
354# Builds a functional Rustc for the given host.
355######################################################################
356
Niko Matsakis15d60322011-12-06 22:02:03357define DEF_RUSTC_STAGE_TARGET
358# $(1) == architecture
359# $(2) == stage
360
361rustc-stage$(2)-H-$(1): \
362 $$(foreach target,$$(CFG_TARGET_TRIPLES), \
363 $$(SREQ$(2)_T_$$(target)_H_$(1)))
364
365endef
366
367$(foreach host,$(CFG_TARGET_TRIPLES), \
368 $(eval $(foreach stage,1 2 3, \
369 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
370
Niko Matsakisc28ada02011-12-09 16:16:04371rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
372rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
373rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
374
Niko Matsakis3bbfe512011-12-03 00:04:27375define DEF_RUSTC_TARGET
376# $(1) == architecture
377
Haitao Li394a80c2012-01-16 05:42:03378rustc-H-$(1): rustc-stage2-H-$(1)
Niko Matsakis3bbfe512011-12-03 00:04:27379endef
380
381$(foreach host,$(CFG_TARGET_TRIPLES), \
382 $(eval $(call DEF_RUSTC_TARGET,$(host))))
383
Niko Matsakis68c62722011-12-13 04:28:35384rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
385rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
386rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
387rustc: rustc-H-$(CFG_HOST_TRIPLE)
388
Niko Matsakis49349292011-12-03 00:11:35389rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
Niko Matsakis3bbfe512011-12-03 00:04:27390
391######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41392# Entrypoint rule
Graydon Hoare4c2245d2011-03-18 06:51:45393######################################################################
394
Brian Andersonc9b14cc2011-12-13 20:02:17395.DEFAULT_GOAL := all
396
Graydon Hoareae784df2011-05-14 00:00:43397ifneq ($(CFG_IN_TRANSITION),)
398
Graydon Hoare9ac29482011-05-16 22:14:58399CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43400CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
401CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
Graydon Hoare9ac29482011-05-16 22:14:58402CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43403
Graydon Hoare193279d2012-01-18 22:14:28404all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) docs
Brian Andersonb0560962011-09-30 23:15:02405
Graydon Hoareae784df2011-05-14 00:00:43406else
Brian Anderson86ed9052011-09-30 03:27:28407
Niko Matsakis9c12c7c2011-11-21 21:11:40408TSREQS := \
409 $(foreach target,$(CFG_TARGET_TRIPLES), \
410 $(SREQ3_T_$(target)_H_$(CFG_HOST_TRIPLE)))
411FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
Graydon Hoared1fd7d42011-12-01 19:31:29412CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
Graydon Hoare51a92742011-12-21 02:27:27413RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
Brian Anderson86ed9052011-09-30 03:27:28414
Niko Matsakisd365ec52012-03-15 14:39:57415all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC)
Brian Anderson6e654562011-10-02 03:12:08416
Graydon Hoareae784df2011-05-14 00:00:43417endif
418
Graydon Hoare10f33602011-03-25 17:29:45419
420######################################################################
421# Re-configuration
422######################################################################
423
Brian Anderson8d7863f2011-11-29 01:50:23424ifndef CFG_DISABLE_MANAGE_SUBMODULES
Brian Anderson0e150112011-11-01 01:19:40425# This is a pretty expensive operation but I don't see any way to avoid it
Brian Anderson143f8782011-11-26 04:00:48426NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
Brian Anderson8d7863f2011-11-29 01:50:23427else
428NEED_GIT_RECONFIG=0
429endif
Brian Anderson0e150112011-11-01 01:19:40430
431ifeq ($(NEED_GIT_RECONFIG),0)
432else
433# If the submodules have changed then always execute config.mk
Graydon Hoare071dbfc2012-03-26 23:04:37434.PHONY: config.stamp
Brian Anderson0e150112011-11-01 01:19:40435endif
436
Graydon Hoare071dbfc2012-03-26 23:04:37437Makefile config.mk: config.stamp
438
439config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
Graydon Hoare10f33602011-03-25 17:29:45440 @$(call E, cfg: reconfiguring)
Graydon Hoaredf8161d2011-06-30 20:41:20441 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
Graydon Hoare071dbfc2012-03-26 23:04:37442 $(Q)touch $@
Graydon Hoare10f33602011-03-25 17:29:45443
444
Graydon Hoaree961f532011-03-21 18:23:19445######################################################################
Graydon Hoare79ba3152011-06-25 19:23:27446# Primary-target makefiles
Graydon Hoaree961f532011-03-21 18:23:19447######################################################################
448
Graydon Hoare89dec282012-03-26 23:05:33449include $(CFG_SRC_DIR)mk/target.mk
450include $(CFG_SRC_DIR)mk/host.mk
451include $(CFG_SRC_DIR)mk/stage0.mk
452include $(CFG_SRC_DIR)mk/rt.mk
453include $(CFG_SRC_DIR)mk/rustllvm.mk
454include $(CFG_SRC_DIR)mk/autodep.mk
455include $(CFG_SRC_DIR)mk/tools.mk
456include $(CFG_SRC_DIR)mk/docs.mk
457include $(CFG_SRC_DIR)mk/llvm.mk
Graydon Hoare79ba3152011-06-25 19:23:27458
Graydon Hoare79ba3152011-06-25 19:23:27459######################################################################
460# Secondary makefiles, conditionalized for speed
461######################################################################
462
Graydon Hoaredf8161d2011-06-30 20:41:20463ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
464 $(findstring check,$(MAKECMDGOALS)) \
465 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoare39151f22011-07-13 22:44:09466 $(findstring tidy,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20467 $(findstring clean,$(MAKECMDGOALS))),)
468 CFG_INFO := $(info cfg: including dist rules)
Graydon Hoare89dec282012-03-26 23:05:33469 include $(CFG_SRC_DIR)mk/dist.mk
Graydon Hoare79ba3152011-06-25 19:23:27470endif
471
Graydon Hoaredf8161d2011-06-30 20:41:20472ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
473 $(findstring clean,$(MAKECMDGOALS))),)
474 CFG_INFO := $(info cfg: including snap rules)
Graydon Hoare89dec282012-03-26 23:05:33475 include $(CFG_SRC_DIR)mk/snap.mk
Graydon Hoare79ba3152011-06-25 19:23:27476endif
477
478ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20479 CFG_INFO := $(info cfg: including reformat rules)
Graydon Hoare89dec282012-03-26 23:05:33480 include $(CFG_SRC_DIR)mk/pp.mk
Graydon Hoare79ba3152011-06-25 19:23:27481endif
482
Graydon Hoaredf8161d2011-06-30 20:41:20483ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
484 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoared5b2d622011-09-13 22:06:21485 $(findstring perf,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20486 $(findstring tidy,$(MAKECMDGOALS))),)
487 CFG_INFO := $(info cfg: including test rules)
Graydon Hoare89dec282012-03-26 23:05:33488 include $(CFG_SRC_DIR)mk/tests.mk
Graydon Hoare79ba3152011-06-25 19:23:27489endif
490
Graydon Hoared5b2d622011-09-13 22:06:21491ifneq ($(findstring perf,$(MAKECMDGOALS)),)
492 CFG_INFO := $(info cfg: including perf rules)
Graydon Hoare89dec282012-03-26 23:05:33493 include $(CFG_SRC_DIR)mk/perf.mk
Graydon Hoared5b2d622011-09-13 22:06:21494endif
495
Graydon Hoare79ba3152011-06-25 19:23:27496ifneq ($(findstring clean,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20497 CFG_INFO := $(info cfg: including clean rules)
Graydon Hoare89dec282012-03-26 23:05:33498 include $(CFG_SRC_DIR)mk/clean.mk
Michael Sullivanb01ecb12011-07-21 18:58:01499endif
Brian Anderson9563c172011-10-01 02:00:19500
501ifneq ($(findstring install,$(MAKECMDGOALS)),)
Kevin Cantuc9d53ca2012-01-20 12:17:32502 ifdef DESTDIR
503 CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR))
504 CFG_PREFIX:=$(DESTDIR)
505 export CFG_PREFIX
506 endif
507
Brian Anderson9563c172011-10-01 02:00:19508 CFG_INFO := $(info cfg: including install rules)
Graydon Hoare89dec282012-03-26 23:05:33509 include $(CFG_SRC_DIR)mk/install.mk
Niko Matsakise1c470c2011-10-12 19:10:21510endif
511
512ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
513 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
514 CFG_INFO := $(info cfg: including ctags rules)
Graydon Hoare89dec282012-03-26 23:05:33515 include $(CFG_SRC_DIR)mk/ctags.mk
Niko Matsakise1c470c2011-10-12 19:10:21516endif