rust/mk/target.mk

130 lines
5.1 KiB
Makefile
Raw Normal View History

# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# This is the compile-time target-triple for the compiler. For the compiler at
# runtime, this should be considered the host-triple. More explanation for why
# this exists can be found on issue #2400
export CFG_COMPILER_TRIPLE
# The standard libraries should be held up to a higher standard than any old
# code, make sure that these common warnings are denied by default. These can
# be overridden during development temporarily. For stage0, we allow all these
# to suppress warnings which may be bugs in stage0 (should be fixed in stage1+)
WFLAGS_ST0 = -A warnings
WFLAGS_ST1 = -D warnings
WFLAGS_ST2 = -D warnings
# TARGET_STAGE_N template: This defines how target artifacts are built
2011-11-21 22:11:40 +01:00
# for all stage/target architecture combinations. The arguments:
# $(1) is the stage
# $(2) is the target triple
# $(3) is the host triple
define TARGET_STAGE_N
2011-11-21 22:11:40 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/libmorestack.a: \
rt/$(2)/stage$(1)/arch/$$(HOST_$(2))/libmorestack.a \
2013-08-31 21:44:50 +02:00
| $$(TLIB$(1)_T_$(2)_H_$(3))/ \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
2013-02-27 06:53:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME_$(2)): \
rt/$(2)/stage$(1)/$(CFG_RUNTIME_$(2)) \
2013-08-31 21:44:50 +02:00
| $$(TLIB$(1)_T_$(2)_H_$(3))/ \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)): \
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
2012-03-22 23:27:35 +01:00
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(STDLIB_GLOB_$(2)),$$(notdir $$@))
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(STDLIB_GLOB_$(2)),$$(notdir $$@))
2012-03-22 23:27:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)): \
$$(EXTRALIB_CRATE) $$(EXTRALIB_INPUTS) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(EXTRALIB_GLOB_$(2)),$$(notdir $$@))
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(EXTRALIB_GLOB_$(2)),$$(notdir $$@))
2013-02-27 06:53:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)): \
$$(LIBSYNTAX_CRATE) $$(LIBSYNTAX_INPUTS) \
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
$$(TEXTRALIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@))
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) $(BORROWCK) --out-dir $$(@D) $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBSYNTAX_GLOB_$(2)),$$(notdir $$@))
# Only build the compiler for host triples
ifneq ($$(findstring $(2),$$(CFG_HOST_TRIPLES)),)
2013-02-27 06:53:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM_$(3)): \
rustllvm/$(2)/$(CFG_RUSTLLVM_$(3)) \
2013-08-31 21:44:50 +02:00
| $$(TLIB$(1)_T_$(2)_H_$(3))/ \
$(HBIN0_H_$(CFG_BUILD_TRIPLE))/rustc$(X_$(CFG_BUILD_TRIPLE))
@$$(call E, cp: $$@)
$$(Q)cp $$< $$@
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): CFG_COMPILER_TRIPLE = $(2)
2013-02-27 06:53:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)): \
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
Add dependence arc from running rustc to its libraries. This commit fixes some oversights in the Makefile where rustc could be invoked without some of its dependencies yet in place. (I encountered the problem in practice; its not just theoretical.) As written in Makefile.in, $(STAGE$(1)_T_$(2)_H_$(3)) is the way one writes an invocation of rustc where $(1) is the stage number $(2) is the target triple $(3) is the host triple. (Other uses of the macro may plug in actual values or different parameters in for those three formal parameters.) When you have invocations of $(STAGE...), you need to make sure that its dependences are satisfied; otherwise, if someone is using `make -jN` for certain (large-ish) `N`, one can encounter situations where GNU make attempts to invoke `rustc` before it has actually copied some of its libraries into place, such as libmorestack.a, which causes a link failure when the rustc invocation attempts to link in those libraries. In this case, the main prerequisite to add is TSREQ$(1)_T_$(2)_H_$(3), which is described in Makefile.in as "Prerequisites for using the stageN compiler to build target artifacts" ---- In addition to adding the extra dependences on TSREQ..., I also replaced occurrences of the pattern: TSREQ$(1)_T_$(2)_H_$(3) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) with: SREQ$(1)_T_$(2)_H_$(3) which is equivalent to the above, as defined in Makefile.in ---- Finally, for the cases where TSREQ was missing in tests.mk, I went ahead and put in a dependence on SREQ rather than just TSREQ, since it was not clear to me how one could expect to compile those cases without stdlib and extralib. (It could well be that I should have gone ahead and done the same in other cases where I saw TSREQ was missing, and put SREQ in those cases as well. But this seemed like a good measure for now, without needing to tax my understanding of the overall makefile infrastructure much further.)
2013-07-16 08:05:18 +02:00
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
2013-02-27 06:53:35 +01:00
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBSYNTAX_$(3)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM_$(3)) \
| $$(TLIB$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(call REMOVE_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(WFLAGS_ST$(1)) --out-dir $$(@D) $$< && touch $$@
$$(call LIST_ALL_OLD_GLOB_MATCHES_EXCEPT,$$(dir $$@),$(LIBRUSTC_GLOB_$(2)),$$(notdir $$@))
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(3)): \
$$(DRIVER_CRATE) \
Add dependence arc from running rustc to its libraries. This commit fixes some oversights in the Makefile where rustc could be invoked without some of its dependencies yet in place. (I encountered the problem in practice; its not just theoretical.) As written in Makefile.in, $(STAGE$(1)_T_$(2)_H_$(3)) is the way one writes an invocation of rustc where $(1) is the stage number $(2) is the target triple $(3) is the host triple. (Other uses of the macro may plug in actual values or different parameters in for those three formal parameters.) When you have invocations of $(STAGE...), you need to make sure that its dependences are satisfied; otherwise, if someone is using `make -jN` for certain (large-ish) `N`, one can encounter situations where GNU make attempts to invoke `rustc` before it has actually copied some of its libraries into place, such as libmorestack.a, which causes a link failure when the rustc invocation attempts to link in those libraries. In this case, the main prerequisite to add is TSREQ$(1)_T_$(2)_H_$(3), which is described in Makefile.in as "Prerequisites for using the stageN compiler to build target artifacts" ---- In addition to adding the extra dependences on TSREQ..., I also replaced occurrences of the pattern: TSREQ$(1)_T_$(2)_H_$(3) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB_$(2)) $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_EXTRALIB_$(2)) with: SREQ$(1)_T_$(2)_H_$(3) which is equivalent to the above, as defined in Makefile.in ---- Finally, for the cases where TSREQ was missing in tests.mk, I went ahead and put in a dependence on SREQ rather than just TSREQ, since it was not clear to me how one could expect to compile those cases without stdlib and extralib. (It could well be that I should have gone ahead and done the same in other cases where I saw TSREQ was missing, and put SREQ in those cases as well. But this seemed like a good measure for now, without needing to tax my understanding of the overall makefile infrastructure much further.)
2013-07-16 08:05:18 +02:00
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC_$(3)) \
| $$(TBIN$(1)_T_$(2)_H_$(3))/
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) --cfg rustc -o $$@ $$<
ifdef CFG_ENABLE_PAX_FLAGS
@$$(call E, apply PaX flags: $$@)
@"$(CFG_PAXCTL)" -cm "$$@"
endif
endif
$$(TBIN$(1)_T_$(2)_H_$(3))/:
mkdir -p $$@
ifneq ($(CFG_LIBDIR),bin)
$$(TLIB$(1)_T_$(2)_H_$(3))/:
mkdir -p $$@
endif
endef
# In principle, each host can build each target:
$(foreach source,$(CFG_HOST_TRIPLES), \
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call TARGET_STAGE_N,0,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,1,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,2,$(target),$(source))) \
$(eval $(call TARGET_STAGE_N,3,$(target),$(source)))))