blob: 5c5191e079d51f8ce5f53e87110cfb1e86f35a20 [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
51include config.mk
Graydon Hoare9c6e7e62011-03-16 16:17:3252
Niko Matsakis9c00c622011-11-23 23:20:2853ifdef IGNORE_MKFILES
54 MKFILE_DEPS :=
55else
Niko Matsakis5ce33ce2011-11-29 20:42:0556 OUR_MKFILES := Makefile config.mk $(wildcard $(CFG_SRC_DIR)/mk/*.mk)
57 3RDPARTY_MKFILES := $(CFG_SRC_DIR)/src/libuv/Makefile \
58 $(wildcard $(CFG_SRC_DIR)/src/libuv/*.mk)
59 GEN_MKFILES := $(wildcard $(CFG_SRC_DIR)/mk/libuv/*/*/*) \
60 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*) \
61 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*) \
62 $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/libuv/*)
63 MKFILE_DEPS := $(OUR_MKFILES) $(3RDPARTY_MKFILES) $(GEN_MKFILES)
Niko Matsakis9c00c622011-11-23 23:20:2864endif
65
Niko Matsakis8371beb2011-11-22 21:04:5266NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
67
Graydon Hoare9c6e7e62011-03-16 16:17:3268ifneq ($(MAKE_RESTARTS),)
69CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
70endif
71
Graydon Hoare13215802011-09-21 18:24:5972CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
Niko Matsakis8371beb2011-11-22 21:04:5273CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
Graydon Hoare9c6e7e62011-03-16 16:17:3274
Graydon Hoarecae703c2011-04-08 22:44:4175ifdef CFG_DISABLE_OPTIMIZE
Graydon Hoare19ebc0f2011-04-08 23:29:1976 $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
Patrick Waltonc52fb522011-04-29 17:23:0777 CFG_RUSTC_FLAGS :=
Graydon Hoarecae703c2011-04-08 22:44:4178else
Patrick Waltonc52fb522011-04-29 17:23:0779 CFG_RUSTC_FLAGS := -O
Graydon Hoarecae703c2011-04-08 22:44:4180endif
Graydon Hoare4c2245d2011-03-18 06:51:4581
Patrick Walton3f77e7d2011-04-25 21:20:2882ifdef SAVE_TEMPS
Marijn Haverbeke6b11f6c2011-04-26 18:32:0883 CFG_RUSTC_FLAGS += --save-temps
Patrick Walton3f77e7d2011-04-25 21:20:2884endif
Patrick Walton648c4ae2011-04-29 18:55:3285ifdef TIME_PASSES
86 CFG_RUSTC_FLAGS += --time-passes
87endif
Brian Anderson27522842011-06-19 00:26:4188ifdef TIME_LLVM_PASSES
89 CFG_RUSTC_FLAGS += --time-llvm-passes
90endif
Patrick Walton404db4d2011-05-11 00:48:4991ifdef DEBUG
92 CFG_RUSTC_FLAGS += -g
93endif
Patrick Walton3f77e7d2011-04-25 21:20:2894
Graydon Hoare40624e32011-05-01 20:18:5295# platform-specific auto-configuration
96include $(CFG_SRC_DIR)/mk/platform.mk
Graydon Hoare4c2245d2011-03-18 06:51:4597
Brian Andersoncad8c732011-05-14 03:20:3498# Run the stage1/2 compilers under valgrind
99ifdef VALGRIND_COMPILE
100 CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
101else
102 CFG_VALGRIND_COMPILE :=
103endif
104
Graydon Hoare4c2245d2011-03-18 06:51:45105CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
Graydon Hoare7ac885e2011-03-22 06:06:42106CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
Graydon Hoare447414f2011-12-06 00:46:37107CFG_CORELIB :=$(call CFG_LIB_NAME,core)
Haitao Lib4f450a2011-11-18 08:00:28108CFG_STDLIB :=$(call CFG_LIB_NAME,std)
Brian Anderson5fb9cad2011-07-01 06:16:01109CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
Graydon Hoare4c2245d2011-03-18 06:51:45110
Haitao Li6dbd4c22011-12-02 16:51:59111STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
112CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
113LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
114
Graydon Hoare1e03f002011-05-06 18:21:51115# version-string calculation
116CFG_GIT_DIR := $(CFG_SRC_DIR).git
Graydon Hoare79ba3152011-06-25 19:23:27117CFG_VERSION = prerelease
Graydon Hoare0a8f9a32011-06-13 21:45:26118ifneq ($(wildcard $(CFG_GIT)),)
Graydon Hoare1e03f002011-05-06 18:21:51119ifneq ($(wildcard $(CFG_GIT_DIR)),)
120 CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
121 --pretty=format:'(%h %ci)')
122endif
Graydon Hoare0a8f9a32011-06-13 21:45:26123endif
Graydon Hoare1e03f002011-05-06 18:21:51124
Graydon Hoare94731fa2011-03-30 04:45:09125ifdef CFG_DISABLE_VALGRIND
126 $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
Graydon Hoare4c2245d2011-03-18 06:51:45127 CFG_VALGRIND :=
Graydon Hoare9c6e7e62011-03-16 16:17:32128endif
Patrick Walton518e2d22011-05-06 01:11:40129ifdef CFG_BAD_VALGRIND
130 $(info cfg: disabling valgrind due to its unreliability on this platform)
131 CFG_VALGRIND :=
132endif
Graydon Hoare9c6e7e62011-03-16 16:17:32133
Graydon Hoare28a4e772011-03-23 17:37:35134DOCS :=
Graydon Hoarefefdb632012-01-13 03:10:30135ifeq ($(CFG_PANDOC),)
136 $(info cfg: no pandoc found, omitting doc/rust.html)
Graydon Hoare28a4e772011-03-23 17:37:35137else
138 DOCS += doc/rust.html
139endif
140
Graydon Hoarefefdb632012-01-13 03:10:30141ifeq ($(CFG_PANDOC),)
142 $(info cfg: no pandoc found, omitting doc/rust.pdf)
Graydon Hoare28a4e772011-03-23 17:37:35143else
Graydon Hoarefefdb632012-01-13 03:10:30144 ifeq ($(CFG_PDFLATEX),)
145 $(info cfg: no pdflatex found, omitting doc/rust.pdf)
Graydon Hoaref7407472011-03-23 20:31:51146 else
147 DOCS += doc/rust.pdf
148 endif
Graydon Hoare28a4e772011-03-23 17:37:35149endif
150
Brian Anderson0c620072011-10-27 21:59:22151ifeq ($(CFG_NATURALDOCS),)
Graydon Hoare447414f2011-12-06 00:46:37152 $(info cfg: no naturaldocs found, omitting library doc build)
Brian Anderson0c620072011-10-27 21:59:22153else
Graydon Hoare447414f2011-12-06 00:46:37154 DOCS += doc/core/index.html doc/std/index.html
Brian Anderson0c620072011-10-27 21:59:22155endif
156
Graydon Hoare94731fa2011-03-30 04:45:09157ifdef CFG_DISABLE_DOCS
158 $(info cfg: disabling doc build (CFG_DISABLE_DOCS))
159 DOCS :=
160endif
Graydon Hoare28a4e772011-03-23 17:37:35161
Graydon Hoare4c2245d2011-03-18 06:51:45162######################################################################
163# Target-and-rule "utility variables"
164######################################################################
165
166ifdef VERBOSE
167 Q :=
168 E =
169else
170 Q := @
171 E = echo $(1)
172endif
173
Graydon Hoare4c2245d2011-03-18 06:51:45174S := $(CFG_SRC_DIR)
175X := $(CFG_EXE_SUFFIX)
176
177# Look in doc and src dirs.
178VPATH := $(S)doc $(S)src
179
Graydon Hoare4c2245d2011-03-18 06:51:45180# "Source" files we generate in builddir along the way.
Graydon Hoare40624e32011-05-01 20:18:52181GENERATED :=
Graydon Hoare4c2245d2011-03-18 06:51:45182
183# Delete the built-in rules.
184.SUFFIXES:
185%:: %,v
186%:: RCS/%,v
187%:: RCS/%
188%:: s.%
189%:: SCCS/s.%
Graydon Hoare9c6e7e62011-03-16 16:17:32190
Graydon Hoare4c2245d2011-03-18 06:51:45191######################################################################
Graydon Hoare447414f2011-12-06 00:46:37192# Core library variables
193######################################################################
194
195CORELIB_CRATE := $(S)src/libcore/core.rc
196CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/, \
197 core.rc *.rs */*.rs))
198
199######################################################################
Graydon Hoare4c2245d2011-03-18 06:51:45200# Standard library variables
201######################################################################
202
Graydon Hoare447414f2011-12-06 00:46:37203STDLIB_CRATE := $(S)src/libstd/std.rc
204STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/, \
205 std.rc *.rs */*.rs))
Graydon Hoare4c2245d2011-03-18 06:51:45206
207######################################################################
208# rustc crate variables
209######################################################################
210
Graydon Hoare65974392011-03-21 20:42:29211COMPILER_CRATE := $(S)src/comp/rustc.rc
Graydon Hoare0fba2d02012-01-10 22:34:53212COMPILER_INPUTS := $(filter-out $(S)src/comp/driver/rustc.rs, \
213 $(wildcard $(addprefix $(S)src/comp/, \
214 rustc.rc *.rs */*.rs */*/*.rs)))
Haitao Libc95ccb2011-12-20 10:17:13215
216RUSTC_INPUTS := $(S)src/comp/driver/rustc.rs
Graydon Hoare4c2245d2011-03-18 06:51:45217
218######################################################################
Brian Andersona0ff3db2011-11-02 00:09:44219# LLVM macros
220######################################################################
221
Brian Andersona92218e2011-11-27 06:38:36222# FIXME: x86-ism
223LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser
224
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)
240LLVM_CXXFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags)
241LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
242
Brian Andersonecdeffb2011-12-14 03:03:43243LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X)
244LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)
Brian Anderson4b6585c2011-11-02 23:21:17245
246endef
247
248$(foreach target,$(CFG_TARGET_TRIPLES), \
249 $(eval $(call DEF_LLVM_VARS,$(target))))
250
Brian Andersona0ff3db2011-11-02 00:09:44251######################################################################
Graydon Hoared987b492011-05-03 06:37:52252# Exports for sub-utilities
253######################################################################
254
Brian Anderson6e654562011-10-02 03:12:08255# Note that any variable that re-configure should pick up needs to be
256# exported
257
Graydon Hoared987b492011-05-03 06:37:52258export CFG_SRC_DIR
Graydon Hoaread954fc2011-07-23 19:26:47259export CFG_BUILD_DIR
Graydon Hoare1e03f002011-05-06 18:21:51260export CFG_VERSION
Brian Anderson6306c812011-09-29 19:21:58261export CFG_HOST_TRIPLE
Graydon Hoare6a4a85f2011-05-18 19:00:26262export CFG_LLVM_ROOT
Graydon Hoare0dc2aa32011-06-28 18:18:25263export CFG_ENABLE_MINGW_CROSS
Brian Anderson6e654562011-10-02 03:12:08264export CFG_PREFIX
Brian Anderson9e40e432012-01-11 01:45:03265export CFG_LIBDIR
Graydon Hoared987b492011-05-03 06:37:52266
Patrick Walton04f966f2011-05-05 01:28:30267######################################################################
268# Subprograms
269######################################################################
270
Graydon Hoared987b492011-05-03 06:37:52271######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41272# Per-stage targets and runner
273######################################################################
274
275define SREQ
Niko Matsakis9c12c7c2011-11-21 21:11:40276# $(1) is the stage number
277# $(2) is the target triple
Graydon Hoare766e29c2011-11-30 03:28:15278# $(3) is the host triple
Brian Andersoned106dd2011-09-30 19:08:51279
Brian Anderson38c67a42011-09-30 19:24:28280# Destinations of artifacts for the host compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40281HROOT$(1)_H_$(3) = $(3)/stage$(1)
282HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03283HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
Brian Anderson38c67a42011-09-30 19:24:28284
Brian Anderson9563c172011-10-01 02:00:19285# Destinations of artifacts for target architectures
Niko Matsakis9c12c7c2011-11-21 21:11:40286TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
287TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
Brian Anderson9e40e432012-01-11 01:45:03288TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
Brian Andersoned106dd2011-09-30 19:08:51289
Graydon Hoare447414f2011-12-06 00:46:37290# The name of the core and standard libraries used by rustc
Rafael Ávila de Espíndola88894b62011-07-20 20:02:36291ifdef CFG_DISABLE_SHAREDSTD
Graydon Hoare447414f2011-12-06 00:46:37292 HCORELIB_DEFAULT$(1)_H_$(3) = \
293 $$(HLIB$(1)_H_$(3))/libcore.rlib
294 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
295 $$(TLIB$(1)_T_$(2)_H_$(3))/libcore.rlib
Graydon Hoare4f826b32011-12-17 01:21:18296
Niko Matsakis9c12c7c2011-11-21 21:11:40297 HSTDLIB_DEFAULT$(1)_H_$(3) = \
298 $$(HLIB$(1)_H_$(3))/libstd.rlib
299 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
300 $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
Graydon Hoare4f826b32011-12-17 01:21:18301
302 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
303 $$(HLIB$(1)_H_$(3))/librustc.rlib
304 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
305 $$(TLIB$(1)_T_$(2)_H_$(3))/librustc.rlib
Brian Andersonf634eb22011-09-30 23:11:47306else
Graydon Hoare447414f2011-12-06 00:46:37307 HCORELIB_DEFAULT$(1)_H_$(3) = \
308 $$(HLIB$(1)_H_$(3))/$(CFG_CORELIB)
309 TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
310 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB)
Graydon Hoare4f826b32011-12-17 01:21:18311
Niko Matsakis9c12c7c2011-11-21 21:11:40312 HSTDLIB_DEFAULT$(1)_H_$(3) = \
313 $$(HLIB$(1)_H_$(3))/$(CFG_STDLIB)
314 TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3) = \
315 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB)
Graydon Hoare4f826b32011-12-17 01:21:18316
317 HLIBRUSTC_DEFAULT$(1)_H_$(3) = \
318 $$(HLIB$(1)_H_$(3))/$(CFG_LIBRUSTC)
319 TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3) = \
320 $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC)
Brian Andersonf634eb22011-09-30 23:11:47321endif
322
Brian Anderson6e654562011-10-02 03:12:08323# Preqrequisites for using the stageN compiler
Niko Matsakis9c12c7c2011-11-21 21:11:40324HSREQ$(1)_H_$(3) = \
325 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
326 $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \
327 $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \
Graydon Hoare447414f2011-12-06 00:46:37328 $$(HCORELIB_DEFAULT$(1)_H_$(3)) \
Niko Matsakis9c12c7c2011-11-21 21:11:40329 $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
Graydon Hoare4f826b32011-12-17 01:21:18330 $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
Niko Matsakis5ce33ce2011-11-29 20:42:05331 $$(MKFILE_DEPS)
Brian Anderson6e654562011-10-02 03:12:08332
333# Prerequisites for using the stageN compiler to build target artifacts
Niko Matsakis9c12c7c2011-11-21 21:11:40334TSREQ$(1)_T_$(2)_H_$(3) = \
335 $$(HSREQ$(1)_H_$(3)) \
336 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME) \
337 $$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.bc \
338 $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
Brian Anderson6e654562011-10-02 03:12:08339
340# Prerequisites for complete stageN targets
Niko Matsakis9c12c7c2011-11-21 21:11:40341SREQ$(1)_T_$(2)_H_$(3) = \
342 $$(TSREQ$(1)_T_$(2)_H_$(3)) \
Graydon Hoare447414f2011-12-06 00:46:37343 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
Graydon Hoare4f826b32011-12-17 01:21:18344 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB) \
345 $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
Graydon Hoarefafb42e2011-07-15 23:12:41346
Brian Andersone3d3aaa2011-08-26 18:11:49347ifeq ($(1),0)
348# Don't run the the stage0 compiler under valgrind - that ship has sailed
349CFG_VALGRIND_COMPILE$(1) =
350else
351CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
352endif
353
Niko Matsakis9c12c7c2011-11-21 21:11:40354STAGE$(1)_T_$(2)_H_$(3) := \
355 $$(Q)$$(call CFG_RUN_TARG,$(1), \
356 $$(CFG_VALGRIND_COMPILE$(1)) \
357 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
358 $$(CFG_RUSTC_FLAGS) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37359
Niko Matsakis9c12c7c2011-11-21 21:11:40360PERF_STAGE$(1)_T_$(2)_H_$(3) := \
361 $$(Q)$$(call CFG_RUN_TARG,$(1), \
362 $$(CFG_PERF_TOOL) \
363 $$(HBIN$(1)_H_$(3))/rustc$$(X) \
364 $$(CFG_RUSTC_FLAGS) --target=$(2))
Brian Anderson7dbce102011-09-29 19:06:37365
Graydon Hoarefafb42e2011-07-15 23:12:41366endef
367
Niko Matsakis9c12c7c2011-11-21 21:11:40368$(foreach build,$(CFG_TARGET_TRIPLES), \
369 $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
370 $(eval $(foreach stage,$(STAGES), \
371 $(eval $(call SREQ,$(stage),$(target),$(build))))))))
Graydon Hoarefafb42e2011-07-15 23:12:41372
373######################################################################
Niko Matsakis3bbfe512011-12-03 00:04:27374# rustc-H-targets
375#
376# Builds a functional Rustc for the given host.
377######################################################################
378
Niko Matsakis15d60322011-12-06 22:02:03379define DEF_RUSTC_STAGE_TARGET
380# $(1) == architecture
381# $(2) == stage
382
383rustc-stage$(2)-H-$(1): \
384 $$(foreach target,$$(CFG_TARGET_TRIPLES), \
385 $$(SREQ$(2)_T_$$(target)_H_$(1)))
386
387endef
388
389$(foreach host,$(CFG_TARGET_TRIPLES), \
390 $(eval $(foreach stage,1 2 3, \
391 $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
392
Niko Matsakisc28ada02011-12-09 16:16:04393rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
394rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
395rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
396
Niko Matsakis3bbfe512011-12-03 00:04:27397define DEF_RUSTC_TARGET
398# $(1) == architecture
399
Haitao Li394a80c2012-01-16 05:42:03400rustc-H-$(1): rustc-stage2-H-$(1)
Niko Matsakis3bbfe512011-12-03 00:04:27401endef
402
403$(foreach host,$(CFG_TARGET_TRIPLES), \
404 $(eval $(call DEF_RUSTC_TARGET,$(host))))
405
Niko Matsakis68c62722011-12-13 04:28:35406rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
407rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
408rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
409rustc: rustc-H-$(CFG_HOST_TRIPLE)
410
Niko Matsakis49349292011-12-03 00:11:35411rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
Niko Matsakis3bbfe512011-12-03 00:04:27412
413######################################################################
Graydon Hoarefafb42e2011-07-15 23:12:41414# Entrypoint rule
Graydon Hoare4c2245d2011-03-18 06:51:45415######################################################################
416
Brian Andersonc9b14cc2011-12-13 20:02:17417.DEFAULT_GOAL := all
418
Graydon Hoareae784df2011-05-14 00:00:43419ifneq ($(CFG_IN_TRANSITION),)
420
Graydon Hoare9ac29482011-05-16 22:14:58421CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43422CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
423CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
Graydon Hoare9ac29482011-05-16 22:14:58424CFG_INFO := $(info cfg:)
Graydon Hoareae784df2011-05-14 00:00:43425
Brian Anderson6e654562011-10-02 03:12:08426all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) $(DOCS)
Brian Andersonb0560962011-09-30 23:15:02427
Graydon Hoareae784df2011-05-14 00:00:43428else
Brian Anderson86ed9052011-09-30 03:27:28429
Niko Matsakis9c12c7c2011-11-21 21:11:40430TSREQS := \
431 $(foreach target,$(CFG_TARGET_TRIPLES), \
432 $(SREQ3_T_$(target)_H_$(CFG_HOST_TRIPLE)))
433FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
Graydon Hoared1fd7d42011-12-01 19:31:29434CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
Graydon Hoare51a92742011-12-21 02:27:27435RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
Brian Anderson86ed9052011-09-30 03:27:28436
Graydon Hoare51a92742011-12-21 02:27:27437all: rustc $(GENERATED) $(DOCS) $(FUZZ) $(CARGO) $(RUSTDOC)
Brian Anderson6e654562011-10-02 03:12:08438
Graydon Hoareae784df2011-05-14 00:00:43439endif
440
Graydon Hoare10f33602011-03-25 17:29:45441
442######################################################################
443# Re-configuration
444######################################################################
445
Brian Anderson8d7863f2011-11-29 01:50:23446ifndef CFG_DISABLE_MANAGE_SUBMODULES
Brian Anderson0e150112011-11-01 01:19:40447# This is a pretty expensive operation but I don't see any way to avoid it
Brian Anderson143f8782011-11-26 04:00:48448NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
Brian Anderson8d7863f2011-11-29 01:50:23449else
450NEED_GIT_RECONFIG=0
451endif
Brian Anderson0e150112011-11-01 01:19:40452
453ifeq ($(NEED_GIT_RECONFIG),0)
454else
455# If the submodules have changed then always execute config.mk
456.PHONY: config.mk
457endif
458
Graydon Hoareae784df2011-05-14 00:00:43459config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
Graydon Hoare10f33602011-03-25 17:29:45460 @$(call E, cfg: reconfiguring)
Graydon Hoaredf8161d2011-06-30 20:41:20461 $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
Graydon Hoare10f33602011-03-25 17:29:45462
463
Graydon Hoaree961f532011-03-21 18:23:19464######################################################################
Graydon Hoare79ba3152011-06-25 19:23:27465# Primary-target makefiles
Graydon Hoaree961f532011-03-21 18:23:19466######################################################################
467
Brian Anderson6e654562011-10-02 03:12:08468include $(CFG_SRC_DIR)/mk/target.mk
469include $(CFG_SRC_DIR)/mk/host.mk
Michael Sullivanb01ecb12011-07-21 18:58:01470include $(CFG_SRC_DIR)/mk/stage0.mk
Graydon Hoare40624e32011-05-01 20:18:52471include $(CFG_SRC_DIR)/mk/rt.mk
472include $(CFG_SRC_DIR)/mk/rustllvm.mk
Graydon Hoare40624e32011-05-01 20:18:52473include $(CFG_SRC_DIR)/mk/autodep.mk
Brian Anderson3a6f3cf2011-10-03 00:28:59474include $(CFG_SRC_DIR)/mk/tools.mk
Graydon Hoare79ba3152011-06-25 19:23:27475include $(CFG_SRC_DIR)/mk/docs.mk
Brian Andersonf96f1692011-11-01 00:34:31476include $(CFG_SRC_DIR)/mk/llvm.mk
Graydon Hoare79ba3152011-06-25 19:23:27477
Graydon Hoare79ba3152011-06-25 19:23:27478######################################################################
479# Secondary makefiles, conditionalized for speed
480######################################################################
481
Graydon Hoaredf8161d2011-06-30 20:41:20482ifneq ($(strip $(findstring dist,$(MAKECMDGOALS)) \
483 $(findstring check,$(MAKECMDGOALS)) \
484 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoare39151f22011-07-13 22:44:09485 $(findstring tidy,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20486 $(findstring clean,$(MAKECMDGOALS))),)
487 CFG_INFO := $(info cfg: including dist rules)
Graydon Hoare79ba3152011-06-25 19:23:27488 include $(CFG_SRC_DIR)/mk/dist.mk
489endif
490
Graydon Hoaredf8161d2011-06-30 20:41:20491ifneq ($(strip $(findstring snap,$(MAKECMDGOALS)) \
492 $(findstring clean,$(MAKECMDGOALS))),)
493 CFG_INFO := $(info cfg: including snap rules)
Graydon Hoare79ba3152011-06-25 19:23:27494 include $(CFG_SRC_DIR)/mk/snap.mk
495endif
496
497ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20498 CFG_INFO := $(info cfg: including reformat rules)
Graydon Hoare79ba3152011-06-25 19:23:27499 include $(CFG_SRC_DIR)/mk/pp.mk
500endif
501
Graydon Hoaredf8161d2011-06-30 20:41:20502ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
503 $(findstring test,$(MAKECMDGOALS)) \
Graydon Hoared5b2d622011-09-13 22:06:21504 $(findstring perf,$(MAKECMDGOALS)) \
Graydon Hoaredf8161d2011-06-30 20:41:20505 $(findstring tidy,$(MAKECMDGOALS))),)
506 CFG_INFO := $(info cfg: including test rules)
Graydon Hoare79ba3152011-06-25 19:23:27507 include $(CFG_SRC_DIR)/mk/tests.mk
Graydon Hoare79ba3152011-06-25 19:23:27508endif
509
Graydon Hoared5b2d622011-09-13 22:06:21510ifneq ($(findstring perf,$(MAKECMDGOALS)),)
511 CFG_INFO := $(info cfg: including perf rules)
512 include $(CFG_SRC_DIR)/mk/perf.mk
513endif
514
Graydon Hoare79ba3152011-06-25 19:23:27515ifneq ($(findstring clean,$(MAKECMDGOALS)),)
Graydon Hoaredf8161d2011-06-30 20:41:20516 CFG_INFO := $(info cfg: including clean rules)
Graydon Hoare79ba3152011-06-25 19:23:27517 include $(CFG_SRC_DIR)/mk/clean.mk
Michael Sullivanb01ecb12011-07-21 18:58:01518endif
Brian Anderson9563c172011-10-01 02:00:19519
520ifneq ($(findstring install,$(MAKECMDGOALS)),)
521 CFG_INFO := $(info cfg: including install rules)
522 include $(CFG_SRC_DIR)/mk/install.mk
Niko Matsakise1c470c2011-10-12 19:10:21523endif
524
525ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
526 $(findstring TAGS.vi,$(MAKECMDGOALS))),)
527 CFG_INFO := $(info cfg: including ctags rules)
528 include $(CFG_SRC_DIR)/mk/ctags.mk
529endif