2012-12-11 02:32:48 +01:00
|
|
|
# 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.
|
|
|
|
|
2013-05-25 08:05:31 +02:00
|
|
|
# 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
|
2014-03-26 03:23:45 +01:00
|
|
|
export CFG_COMPILER_HOST_TRIPLE
|
2013-05-25 08:05:31 +02:00
|
|
|
|
2015-08-11 01:09:21 +02:00
|
|
|
# Used as defaults for the runtime ar and cc tools
|
|
|
|
export CFG_DEFAULT_LINKER
|
|
|
|
export CFG_DEFAULT_AR
|
|
|
|
|
2014-01-25 04:27:22 +01:00
|
|
|
# Macro that generates the full list of dependencies for a crate at a particular
|
|
|
|
# stage/target/host tuple.
|
|
|
|
#
|
|
|
|
# $(1) - stage
|
|
|
|
# $(2) - target
|
|
|
|
# $(3) - host
|
|
|
|
# $(4) crate
|
|
|
|
define RUST_CRATE_FULLDEPS
|
2014-07-23 06:37:05 +02:00
|
|
|
CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4) := \
|
|
|
|
$$(CRATEFILE_$(4)) \
|
|
|
|
$$(RSINPUTS_$(4)) \
|
2016-02-08 19:57:41 +01:00
|
|
|
$$(foreach dep,$$(RUST_DEPS_$(4)_T_$(2)), \
|
2014-07-23 06:37:05 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
|
|
|
|
$$(foreach dep,$$(NATIVE_DEPS_$(4)), \
|
2015-04-22 00:42:05 +02:00
|
|
|
$$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),$$(dep))) \
|
|
|
|
$$(foreach dep,$$(NATIVE_DEPS_$(4)_T_$(2)), \
|
2015-08-11 23:31:23 +02:00
|
|
|
$$(RT_OUTPUT_DIR_$(2))/$$(dep))
|
2014-01-25 04:27:22 +01:00
|
|
|
endef
|
|
|
|
|
2014-07-23 06:37:05 +02:00
|
|
|
$(foreach host,$(CFG_HOST), \
|
|
|
|
$(foreach target,$(CFG_TARGET), \
|
|
|
|
$(foreach stage,$(STAGES), \
|
|
|
|
$(foreach crate,$(CRATES), \
|
2014-01-25 04:27:22 +01:00
|
|
|
$(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
|
|
|
|
|
|
|
|
# RUST_TARGET_STAGE_N template: This defines how target artifacts are built
|
|
|
|
# for all stage/target architecture combinations. This is one giant rule which
|
|
|
|
# works as follows:
|
|
|
|
#
|
|
|
|
# 1. The immediate dependencies are the rust source files
|
|
|
|
# 2. Each rust crate dependency is listed (based on their stamp files),
|
|
|
|
# as well as all native dependencies (listed in RT_OUTPUT_DIR)
|
2015-07-27 22:41:35 +02:00
|
|
|
# 3. The stage (n-1) compiler is required through the TSREQ dependency
|
2014-01-25 04:27:22 +01:00
|
|
|
# 4. When actually executing the rule, the first thing we do is to clean out
|
|
|
|
# old libs and rlibs via the REMOVE_ALL_OLD_GLOB_MATCHES macro
|
|
|
|
# 5. Finally, we get around to building the actual crate. It's just one
|
|
|
|
# "small" invocation of the previous stage rustc. We use -L to
|
|
|
|
# RT_OUTPUT_DIR so all the native dependencies are picked up.
|
|
|
|
# Additionally, we pass in the llvm dir so rustc can link against it.
|
|
|
|
# 6. Some cleanup is done (listing what was just built) if verbose is turned
|
|
|
|
# on.
|
|
|
|
#
|
2011-11-21 22:11:40 +01:00
|
|
|
# $(1) is the stage
|
|
|
|
# $(2) is the target triple
|
|
|
|
# $(3) is the host triple
|
2014-01-25 04:27:22 +01:00
|
|
|
# $(4) is the crate name
|
|
|
|
define RUST_TARGET_STAGE_N
|
|
|
|
|
2014-03-26 03:23:45 +01:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): CFG_COMPILER_HOST_TRIPLE = $(2)
|
2014-07-23 06:37:05 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
|
|
|
|
$$(CRATEFILE_$(4)) \
|
|
|
|
$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
|
2015-03-17 05:13:36 +01:00
|
|
|
$$(LLVM_CONFIG_$(2)) \
|
2014-07-23 06:37:05 +02:00
|
|
|
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
|
2014-01-25 04:27:22 +01:00
|
|
|
| $$(TLIB$(1)_T_$(2)_H_$(3))/
|
2014-05-21 07:14:38 +02:00
|
|
|
@$$(call E, rustc: $$(@D)/lib$(4))
|
2015-03-03 15:11:01 +01:00
|
|
|
@touch $$@.start_time
|
2014-07-23 06:45:08 +02:00
|
|
|
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
|
2014-01-25 04:27:22 +01:00
|
|
|
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
|
2014-07-23 06:45:08 +02:00
|
|
|
$$(call REMOVE_ALL_OLD_GLOB_MATCHES, \
|
2014-01-25 04:27:22 +01:00
|
|
|
$$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
|
2015-05-11 21:30:47 +02:00
|
|
|
$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
|
2014-11-26 00:28:49 +01:00
|
|
|
$$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) \
|
2014-11-03 08:02:53 +01:00
|
|
|
$$(RUST_LIB_FLAGS_ST$(1)) \
|
2014-01-25 04:27:22 +01:00
|
|
|
-L "$$(RT_OUTPUT_DIR_$(2))" \
|
2015-03-13 03:24:59 +01:00
|
|
|
$$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
|
2015-03-12 12:09:12 +01:00
|
|
|
$$(LLVM_STDCPP_RUSTFLAGS_$(2)) \
|
2014-06-14 08:23:31 +02:00
|
|
|
$$(RUSTFLAGS_$(4)) \
|
2015-08-19 00:02:14 +02:00
|
|
|
$$(RUSTFLAGS$(1)_$(4)) \
|
2015-07-29 02:19:08 +02:00
|
|
|
$$(RUSTFLAGS$(1)_$(4)_T_$(2)) \
|
2014-07-01 16:57:07 +02:00
|
|
|
--out-dir $$(@D) \
|
2014-07-09 19:57:01 +02:00
|
|
|
-C extra-filename=-$$(CFG_FILENAME_EXTRA) \
|
2016-03-28 18:19:25 +02:00
|
|
|
-C metadata=$$(CFG_FILENAME_EXTRA) \
|
2014-07-01 16:57:07 +02:00
|
|
|
$$<
|
2015-03-03 15:11:01 +01:00
|
|
|
@touch -r $$@.start_time $$@ && rm $$@.start_time
|
2014-07-23 06:45:08 +02:00
|
|
|
$$(call LIST_ALL_OLD_GLOB_MATCHES, \
|
2014-01-25 04:27:22 +01:00
|
|
|
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))
|
2014-07-23 06:45:08 +02:00
|
|
|
$$(call LIST_ALL_OLD_GLOB_MATCHES, \
|
2014-01-25 04:27:22 +01:00
|
|
|
$$(dir $$@)$$(call CFG_RLIB_GLOB,$(4)))
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Macro for building any tool as part of the rust compilation process. Each
|
|
|
|
# tool is defined in crates.mk with a list of library dependencies as well as
|
|
|
|
# the source file for the tool. Building each tool will also be passed '--cfg
|
|
|
|
# <tool>' for usage in driver.rs
|
|
|
|
#
|
|
|
|
# This build rule is similar to the one found above, just tweaked for
|
|
|
|
# locations and things.
|
|
|
|
#
|
|
|
|
# $(1) - stage
|
|
|
|
# $(2) - target triple
|
|
|
|
# $(3) - host triple
|
|
|
|
# $(4) - name of the tool being built
|
|
|
|
define TARGET_TOOL
|
|
|
|
|
2014-07-23 06:37:05 +02:00
|
|
|
$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
|
|
|
|
$$(TOOL_SOURCE_$(4)) \
|
|
|
|
$$(TOOL_INPUTS_$(4)) \
|
|
|
|
$$(foreach dep,$$(TOOL_DEPS_$(4)), \
|
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(dep)) \
|
|
|
|
$$(TSREQ$(1)_T_$(2)_H_$(3)) \
|
2014-11-18 22:32:03 +01:00
|
|
|
| $$(TBIN$(1)_T_$(2)_H_$(3))/
|
2014-05-21 07:14:38 +02:00
|
|
|
@$$(call E, rustc: $$@)
|
2015-11-11 20:16:17 +01:00
|
|
|
$$(STAGE$(1)_T_$(2)_H_$(3)) \
|
2015-08-22 06:43:56 +02:00
|
|
|
$$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
|
2015-11-11 20:16:17 +01:00
|
|
|
-o $$@ $$< --cfg $(4)
|
2014-01-25 04:27:22 +01:00
|
|
|
|
|
|
|
endef
|
2011-10-02 05:12:08 +02:00
|
|
|
|
2015-10-18 23:32:50 +02:00
|
|
|
# Macro for building runtime startup/shutdown object files;
|
|
|
|
# these are Rust's equivalent of crti.o, crtn.o
|
|
|
|
#
|
|
|
|
# $(1) - stage
|
|
|
|
# $(2) - target triple
|
|
|
|
# $(3) - host triple
|
2015-10-21 08:08:00 +02:00
|
|
|
# $(4) - object basename
|
2015-10-18 23:32:50 +02:00
|
|
|
define TARGET_RUSTRT_STARTUP_OBJ
|
|
|
|
|
2015-10-21 08:08:00 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o: \
|
2015-10-18 23:32:50 +02:00
|
|
|
$(S)src/rtstartup/$(4).rs \
|
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.core \
|
2016-02-02 08:27:04 +01:00
|
|
|
$$(HSREQ$(1)_T_$(2)_H_$(3)) \
|
2015-10-18 23:32:50 +02:00
|
|
|
| $$(TBIN$(1)_T_$(2)_H_$(3))/
|
|
|
|
@$$(call E, rustc: $$@)
|
|
|
|
$$(STAGE$(1)_T_$(2)_H_$(3)) --emit=obj -o $$@ $$<
|
|
|
|
|
2016-02-02 08:27:04 +01:00
|
|
|
ifeq ($$(CFG_RUSTRT_HAS_STARTUP_OBJS_$(2)), 1)
|
2015-10-18 23:32:50 +02:00
|
|
|
# Add dependencies on Rust startup objects to all crates that depend on core.
|
|
|
|
# This ensures that they are built after core (since they depend on it),
|
|
|
|
# but before everything else (since they are needed for linking dylib crates).
|
2016-02-08 19:57:41 +01:00
|
|
|
$$(foreach crate, $$(TARGET_CRATES_$(2)), \
|
2015-10-18 23:32:50 +02:00
|
|
|
$$(if $$(findstring core,$$(DEPS_$$(crate))), \
|
2015-10-21 08:08:00 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate))) : $$(TLIB$(1)_T_$(2)_H_$(3))/$(4).o
|
2015-12-08 14:56:22 +01:00
|
|
|
endif
|
2015-10-21 08:08:00 +02:00
|
|
|
|
2015-10-18 23:32:50 +02:00
|
|
|
endef
|
|
|
|
|
2014-01-25 04:27:22 +01:00
|
|
|
# Every recipe in RUST_TARGET_STAGE_N outputs to $$(TLIB$(1)_T_$(2)_H_$(3),
|
2013-09-01 00:53:56 +02:00
|
|
|
# a directory that can be cleaned out during the middle of a run of
|
|
|
|
# the get-snapshot.py script. Therefore, every recipe needs to have
|
|
|
|
# an order-only dependency either on $(SNAPSHOT_RUSTC_POST_CLEANUP) or
|
|
|
|
# on $$(TSREQ$(1)_T_$(2)_H_$(3)), to ensure that no products will be
|
|
|
|
# put into the target area until after the get-snapshot.py script has
|
|
|
|
# had its chance to clean it out; otherwise the other products will be
|
2015-03-28 16:09:51 +01:00
|
|
|
# inadvertently included in the clean out.
|
2013-10-21 11:18:21 +02:00
|
|
|
SNAPSHOT_RUSTC_POST_CLEANUP=$(HBIN0_H_$(CFG_BUILD))/rustc$(X_$(CFG_BUILD))
|
2013-09-26 23:56:53 +02:00
|
|
|
|
2014-01-25 04:27:22 +01:00
|
|
|
define TARGET_HOST_RULES
|
2011-11-29 02:23:13 +01:00
|
|
|
|
2016-04-13 20:18:35 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/: $$(SNAPSHOT_RUSTC_POST_CLEANUP)
|
|
|
|
mkdir -p $$@
|
|
|
|
|
|
|
|
$$(TBIN$(1)_T_$(2)_H_$(3))/: $$(SNAPSHOT_RUSTC_POST_CLEANUP)
|
2013-05-04 10:57:56 +02:00
|
|
|
mkdir -p $$@
|
2013-05-03 18:53:47 +02:00
|
|
|
|
2015-04-22 00:42:05 +02:00
|
|
|
$$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
|
2016-04-13 20:18:35 +02:00
|
|
|
$$(SNAPSHOT_RUSTC_POST_CLEANUP) \
|
|
|
|
| $$(TLIB$(1)_T_$(2)_H_$(3))/
|
2015-05-11 23:14:11 +02:00
|
|
|
@$$(call E, cp: $$@)
|
|
|
|
$$(Q)cp $$< $$@
|
2012-05-22 20:40:46 +02:00
|
|
|
endef
|
|
|
|
|
2014-07-23 06:37:05 +02:00
|
|
|
$(foreach source,$(CFG_HOST), \
|
|
|
|
$(foreach target,$(CFG_TARGET), \
|
|
|
|
$(eval $(call TARGET_HOST_RULES,0,$(target),$(source))) \
|
|
|
|
$(eval $(call TARGET_HOST_RULES,1,$(target),$(source))) \
|
|
|
|
$(eval $(call TARGET_HOST_RULES,2,$(target),$(source))) \
|
2014-01-25 04:27:22 +01:00
|
|
|
$(eval $(call TARGET_HOST_RULES,3,$(target),$(source)))))
|
|
|
|
|
|
|
|
# In principle, each host can build each target for both libs and tools
|
2014-07-23 06:37:05 +02:00
|
|
|
$(foreach crate,$(CRATES), \
|
|
|
|
$(foreach source,$(CFG_HOST), \
|
|
|
|
$(foreach target,$(CFG_TARGET), \
|
|
|
|
$(eval $(call RUST_TARGET_STAGE_N,0,$(target),$(source),$(crate))) \
|
|
|
|
$(eval $(call RUST_TARGET_STAGE_N,1,$(target),$(source),$(crate))) \
|
|
|
|
$(eval $(call RUST_TARGET_STAGE_N,2,$(target),$(source),$(crate))) \
|
2014-01-25 04:27:22 +01:00
|
|
|
$(eval $(call RUST_TARGET_STAGE_N,3,$(target),$(source),$(crate))))))
|
|
|
|
|
2014-07-23 06:37:05 +02:00
|
|
|
$(foreach host,$(CFG_HOST), \
|
|
|
|
$(foreach target,$(CFG_TARGET), \
|
|
|
|
$(foreach stage,$(STAGES), \
|
|
|
|
$(foreach tool,$(TOOLS), \
|
2014-01-25 04:27:22 +01:00
|
|
|
$(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))
|
2015-10-18 23:32:50 +02:00
|
|
|
|
|
|
|
$(foreach host,$(CFG_HOST), \
|
|
|
|
$(foreach target,$(CFG_TARGET), \
|
|
|
|
$(foreach stage,$(STAGES), \
|
2015-11-13 21:01:07 +01:00
|
|
|
$(foreach obj,rsbegin rsend, \
|
|
|
|
$(eval $(call TARGET_RUSTRT_STARTUP_OBJ,$(stage),$(target),$(host),$(obj)))))))
|