]> git.lizzy.rs Git - rust.git/blob - Makefile.in
910f6b8a566917968dd866d0de6a0c777f70085d
[rust.git] / Makefile.in
1 # 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
34 # by rustc. In general, rust programs, even those compiled for the
35 # 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
45 STAGES = 0 1 2 3
46
47 ######################################################################
48 # Residual auto-configuration
49 ######################################################################
50
51 # Recursive wildcard function
52 # http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
53 rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
54   $(filter $(subst *,%,$2),$d))
55
56 include config.mk
57
58 MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
59 NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
60
61 ifneq ($(MAKE_RESTARTS),)
62 CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
63 endif
64
65 CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
66
67 ifneq ($(wildcard $(NON_HOST_TRIPLES)),)
68 CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
69 endif
70
71 ifdef CFG_DISABLE_OPTIMIZE
72   $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE))
73   CFG_RUSTC_FLAGS :=
74 else
75   CFG_RUSTC_FLAGS := -O
76 endif
77
78 ifdef SAVE_TEMPS
79   CFG_RUSTC_FLAGS += --save-temps
80 endif
81 ifdef ENFORCE_MUT_VARS
82   CFG_RUSTC_FLAGS += --enforce-mut-vars
83 endif
84 ifdef TIME_PASSES
85   CFG_RUSTC_FLAGS += --time-passes
86 endif
87 ifdef TIME_LLVM_PASSES
88   CFG_RUSTC_FLAGS += --time-llvm-passes
89 endif
90 ifdef DEBUG
91   CFG_RUSTC_FLAGS += -g
92 endif
93
94 # platform-specific auto-configuration
95 include $(CFG_SRC_DIR)mk/platform.mk
96
97 # Run the stage1/2 compilers under valgrind
98 ifdef VALGRIND_COMPILE
99   CFG_VALGRIND_COMPILE :=$(CFG_VALGRIND)
100 else
101   CFG_VALGRIND_COMPILE :=
102 endif
103
104 CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt)
105 CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm)
106 CFG_CORELIB :=$(call CFG_LIB_NAME,core)
107 CFG_STDLIB :=$(call CFG_LIB_NAME,std)
108 CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
109
110 STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
111 CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
112 LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
113 STDLIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,std)
114 CORELIB_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,core)
115 LIBRUSTC_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rustc)
116
117 # version-string calculation
118 CFG_GIT_DIR := $(CFG_SRC_DIR).git
119 CFG_RELEASE = 0.2
120 CFG_VERSION = $(CFG_RELEASE)
121
122 ifneq ($(wildcard $(CFG_GIT)),)
123 ifneq ($(wildcard $(CFG_GIT_DIR)),)
124     CFG_VERSION += $(shell git --git-dir=$(CFG_GIT_DIR) log -1 \
125                      --pretty=format:'(%h %ci)')
126 endif
127 endif
128
129 ifdef CFG_DISABLE_VALGRIND
130   $(info cfg: disabling valgrind (CFG_DISABLE_VALGRIND))
131   CFG_VALGRIND :=
132 endif
133 ifdef CFG_BAD_VALGRIND
134   $(info cfg: disabling valgrind due to its unreliability on this platform)
135   CFG_VALGRIND :=
136 endif
137
138
139 ######################################################################
140 # Target-and-rule "utility variables"
141 ######################################################################
142
143 ifdef VERBOSE
144   Q :=
145   E =
146 else
147   Q := @
148   E = echo $(1)
149 endif
150
151 S := $(CFG_SRC_DIR)
152 X := $(CFG_EXE_SUFFIX)
153
154 # Look in doc and src dirs.
155 VPATH := $(S)doc $(S)src
156
157 # "Source" files we generate in builddir along the way.
158 GENERATED :=
159
160 # Delete the built-in rules.
161 .SUFFIXES:
162 %:: %,v
163 %:: RCS/%,v
164 %:: RCS/%
165 %:: s.%
166 %:: SCCS/s.%
167
168 ######################################################################
169 # Core library variables
170 ######################################################################
171
172 CORELIB_CRATE := $(S)src/libcore/core.rc
173 CORELIB_INPUTS := $(wildcard $(addprefix $(S)src/libcore/,        \
174                                            core.rc *.rs */*.rs))
175
176 ######################################################################
177 # Standard library variables
178 ######################################################################
179
180 STDLIB_CRATE := $(S)src/libstd/std.rc
181 STDLIB_INPUTS := $(wildcard $(addprefix $(S)src/libstd/,          \
182                                           std.rc *.rs */*.rs))
183
184 ######################################################################
185 # rustc crate variables
186 ######################################################################
187
188 COMPILER_CRATE := $(S)src/rustc/rustc.rc
189 COMPILER_INPUTS := $(filter-out $(S)src/rustc/driver/rustc.rs,     \
190                        $(wildcard $(addprefix $(S)src/rustc/,      \
191                            rustc.rc *.rs */*.rs */*/*.rs)))
192
193 RUSTC_INPUTS := $(S)src/rustc/driver/rustc.rs
194
195 ######################################################################
196 # LLVM macros
197 ######################################################################
198
199 # FIXME: x86-ism
200 LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser
201
202 define 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.
205 CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
206 CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
207
208 # Any rules that depend on LLVM should depend on LLVM_CONFIG
209 LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X)
210 LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X)
211 LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
212 LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
213 LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
214 LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
215 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
216 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
217 # 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.
219 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
220 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
221
222 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X)
223 LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)
224
225 endef
226
227 $(foreach target,$(CFG_TARGET_TRIPLES), \
228  $(eval $(call DEF_LLVM_VARS,$(target))))
229
230 ######################################################################
231 # Exports for sub-utilities
232 ######################################################################
233
234 # Note that any variable that re-configure should pick up needs to be
235 # exported
236
237 export CFG_SRC_DIR
238 export CFG_BUILD_DIR
239 export CFG_VERSION
240 export CFG_HOST_TRIPLE
241 export CFG_LLVM_ROOT
242 export CFG_ENABLE_MINGW_CROSS
243 export CFG_PREFIX
244 export CFG_LIBDIR
245
246 ######################################################################
247 # Subprograms
248 ######################################################################
249
250 ######################################################################
251 # Per-stage targets and runner
252 ######################################################################
253
254 define SREQ
255 # $(1) is the stage number
256 # $(2) is the target triple
257 # $(3) is the host triple
258
259 # Destinations of artifacts for the host compiler
260 HROOT$(1)_H_$(3) = $(3)/stage$(1)
261 HBIN$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/bin
262 HLIB$(1)_H_$(3) = $$(HROOT$(1)_H_$(3))/$$(CFG_LIBDIR)
263
264 # Destinations of artifacts for target architectures
265 TROOT$(1)_T_$(2)_H_$(3) = $$(HLIB$(1)_H_$(3))/rustc/$(2)
266 TBIN$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/bin
267 TLIB$(1)_T_$(2)_H_$(3) = $$(TROOT$(1)_T_$(2)_H_$(3))/$$(CFG_LIBDIR)
268
269 # The name of the core and standard libraries used by rustc
270 ifdef CFG_DISABLE_SHAREDSTD
271   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
275
276   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
280
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
285 else
286   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)
290
291   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)
295
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)
300 endif
301
302 # Preqrequisites for using the stageN compiler
303 HSREQ$(1)_H_$(3) = \
304         $$(HBIN$(1)_H_$(3))/rustc$$(X) \
305         $$(HLIB$(1)_H_$(3))/$$(CFG_RUNTIME) \
306         $$(HLIB$(1)_H_$(3))/$$(CFG_RUSTLLVM) \
307         $$(HCORELIB_DEFAULT$(1)_H_$(3)) \
308         $$(HSTDLIB_DEFAULT$(1)_H_$(3)) \
309         $$(HLIBRUSTC_DEFAULT$(1)_H_$(3)) \
310         $$(MKFILE_DEPS)
311
312 # Prerequisites for using the stageN compiler to build target artifacts
313 TSREQ$(1)_T_$(2)_H_$(3) = \
314         $$(HSREQ$(1)_H_$(3)) \
315         $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME) \
316         $$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a
317
318 # Prerequisites for complete stageN targets
319 SREQ$(1)_T_$(2)_H_$(3) = \
320         $$(TSREQ$(1)_T_$(2)_H_$(3)) \
321         $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
322         $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB)  \
323         $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC)
324
325 ifeq ($(1),0)
326 # Don't run the the stage0 compiler under valgrind - that ship has sailed
327 CFG_VALGRIND_COMPILE$(1) =
328 else
329 CFG_VALGRIND_COMPILE$(1) = $$(CFG_VALGRIND_COMPILE)
330 endif
331
332 STAGE$(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))
337
338 PERF_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))
343
344 endef
345
346 $(foreach build,$(CFG_TARGET_TRIPLES), \
347  $(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
348   $(eval $(foreach stage,$(STAGES), \
349    $(eval $(call SREQ,$(stage),$(target),$(build))))))))
350
351 ######################################################################
352 # rustc-H-targets
353 #
354 # Builds a functional Rustc for the given host.
355 ######################################################################
356
357 define DEF_RUSTC_STAGE_TARGET
358 # $(1) == architecture
359 # $(2) == stage
360
361 rustc-stage$(2)-H-$(1):                                                 \
362         $$(foreach target,$$(CFG_TARGET_TRIPLES),       \
363                 $$(SREQ$(2)_T_$$(target)_H_$(1)))
364
365 endef
366
367 $(foreach host,$(CFG_TARGET_TRIPLES),                                                   \
368  $(eval $(foreach stage,1 2 3,                                                                  \
369   $(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
370
371 rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
372 rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
373 rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
374
375 define DEF_RUSTC_TARGET
376 # $(1) == architecture
377
378 rustc-H-$(1): rustc-stage2-H-$(1)
379 endef
380
381 $(foreach host,$(CFG_TARGET_TRIPLES),                   \
382  $(eval $(call DEF_RUSTC_TARGET,$(host))))
383
384 rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
385 rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
386 rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
387 rustc: rustc-H-$(CFG_HOST_TRIPLE)
388
389 rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
390
391 ######################################################################
392 # Entrypoint rule
393 ######################################################################
394
395 .DEFAULT_GOAL := all
396
397 ifneq ($(CFG_IN_TRANSITION),)
398
399 CFG_INFO := $(info cfg:)
400 CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***)
401 CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
402 CFG_INFO := $(info cfg:)
403
404 all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) docs
405
406 else
407
408 TSREQS :=                                                                                       \
409         $(foreach target,$(CFG_TARGET_TRIPLES),                 \
410                 $(SREQ3_T_$(target)_H_$(CFG_HOST_TRIPLE)))
411 FUZZ := $(HBIN3_H_$(CFG_HOST_TRIPLE))/fuzzer$(X)
412 CARGO := $(HBIN3_H_$(CFG_HOST_TRIPLE))/cargo$(X)
413 RUSTDOC := $(HBIN3_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
414
415 all: rustc $(GENERATED) docs $(FUZZ) $(CARGO) $(RUSTDOC)
416
417 endif
418
419
420 ######################################################################
421 # Re-configuration
422 ######################################################################
423
424 ifndef CFG_DISABLE_MANAGE_SUBMODULES
425 # This is a pretty expensive operation but I don't see any way to avoid it
426 NEED_GIT_RECONFIG=$(shell cd "$(CFG_SRC_DIR)" && "$(CFG_GIT)" submodule status | grep -c '^\(+\|-\)')
427 else
428 NEED_GIT_RECONFIG=0
429 endif
430
431 ifeq ($(NEED_GIT_RECONFIG),0)
432 else
433 # If the submodules have changed then always execute config.mk
434 .PHONY: config.stamp
435 endif
436
437 Makefile config.mk: config.stamp
438
439 config.stamp: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt
440         @$(call E, cfg: reconfiguring)
441         $(Q)$(S)configure $(CFG_CONFIGURE_ARGS)
442         $(Q)touch $@
443
444
445 ######################################################################
446 # Primary-target makefiles
447 ######################################################################
448
449 include $(CFG_SRC_DIR)mk/target.mk
450 include $(CFG_SRC_DIR)mk/host.mk
451 include $(CFG_SRC_DIR)mk/stage0.mk
452 include $(CFG_SRC_DIR)mk/rt.mk
453 include $(CFG_SRC_DIR)mk/rustllvm.mk
454 include $(CFG_SRC_DIR)mk/autodep.mk
455 include $(CFG_SRC_DIR)mk/tools.mk
456 include $(CFG_SRC_DIR)mk/docs.mk
457 include $(CFG_SRC_DIR)mk/llvm.mk
458
459 ######################################################################
460 # Secondary makefiles, conditionalized for speed
461 ######################################################################
462
463 ifneq ($(strip $(findstring dist,$(MAKECMDGOALS))   \
464                $(findstring check,$(MAKECMDGOALS))  \
465                $(findstring test,$(MAKECMDGOALS))   \
466                $(findstring tidy,$(MAKECMDGOALS))   \
467                $(findstring clean,$(MAKECMDGOALS))),)
468   CFG_INFO := $(info cfg: including dist rules)
469   include $(CFG_SRC_DIR)mk/dist.mk
470 endif
471
472 ifneq ($(strip $(findstring snap,$(MAKECMDGOALS))   \
473                $(findstring clean,$(MAKECMDGOALS))),)
474   CFG_INFO := $(info cfg: including snap rules)
475   include $(CFG_SRC_DIR)mk/snap.mk
476 endif
477
478 ifneq ($(findstring reformat,$(MAKECMDGOALS)),)
479   CFG_INFO := $(info cfg: including reformat rules)
480   include $(CFG_SRC_DIR)mk/pp.mk
481 endif
482
483 ifneq ($(strip $(findstring check,$(MAKECMDGOALS)) \
484                $(findstring test,$(MAKECMDGOALS))  \
485                $(findstring perf,$(MAKECMDGOALS))  \
486                $(findstring tidy,$(MAKECMDGOALS))),)
487   CFG_INFO := $(info cfg: including test rules)
488   include $(CFG_SRC_DIR)mk/tests.mk
489 endif
490
491 ifneq ($(findstring perf,$(MAKECMDGOALS)),)
492   CFG_INFO := $(info cfg: including perf rules)
493   include $(CFG_SRC_DIR)mk/perf.mk
494 endif
495
496 ifneq ($(findstring clean,$(MAKECMDGOALS)),)
497   CFG_INFO := $(info cfg: including clean rules)
498   include $(CFG_SRC_DIR)mk/clean.mk
499 endif
500
501 ifneq ($(findstring install,$(MAKECMDGOALS)),)
502   ifdef DESTDIR
503     CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR))
504     CFG_PREFIX:=$(DESTDIR)
505     export CFG_PREFIX
506   endif
507
508   CFG_INFO := $(info cfg: including install rules)
509   include $(CFG_SRC_DIR)mk/install.mk
510 endif
511
512 ifneq ($(strip $(findstring TAGS.emacs,$(MAKECMDGOALS)) \
513                $(findstring TAGS.vi,$(MAKECMDGOALS))),)
514   CFG_INFO := $(info cfg: including ctags rules)
515   include $(CFG_SRC_DIR)mk/ctags.mk
516 endif