Skip to content

Commit

Permalink
mk: Split target triples into bulid triple + host triples + target tr…
Browse files Browse the repository at this point in the history
…iples

For cross compiling to targets that don't want to build a compiler
  • Loading branch information
brson committed Feb 22, 2013
1 parent e0767bf commit 15c0c35
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 139 deletions.
56 changes: 35 additions & 21 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ include config.mk
ALL_OBJ_FILES :=

MKFILE_DEPS := config.stamp $(call rwildcard,$(CFG_SRC_DIR)mk/,*)
NON_HOST_TRIPLES = $(filter-out $(CFG_HOST_TRIPLE),$(CFG_TARGET_TRIPLES))
NON_BUILD_HOST_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_HOST_TRIPLES))
NON_BUILD_TARGET_TRIPLES = $(filter-out $(CFG_BUILD_TRIPLE),$(CFG_TARGET_TRIPLES))

ifneq ($(MAKE_RESTARTS),)
CFG_INFO := $(info cfg: make restarts: $(MAKE_RESTARTS))
endif

CFG_INFO := $(info cfg: shell host triple $(CFG_HOST_TRIPLE))
CFG_INFO := $(info cfg: build triple $(CFG_BUILD_TRIPLE))
CFG_INFO := $(info cfg: host triples $(CFG_HOST_TRIPLES))
CFG_INFO := $(info cfg: target triples $(CFG_TARGET_TRIPLES))

ifneq ($(wildcard $(NON_HOST_TRIPLES)),)
CFG_INFO := $(info cfg: non host triples $(NON_HOST_TRIPLES))
ifneq ($(wildcard $(NON_BUILD_HOST_TRIPLES)),)
CFG_INFO := $(info cfg: non-build host triples $(NON_BUILD_HOST_TRIPLES))
endif
ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
endif

CFG_RUSTC_FLAGS := $(RUSTFLAGS)
Expand Down Expand Up @@ -272,8 +278,8 @@ LLC_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llc$$(X)

endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_LLVM_VARS,$(target))))
$(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(call DEF_LLVM_VARS,$(host))))

######################################################################
# Exports for sub-utilities
Expand All @@ -285,7 +291,7 @@ $(foreach target,$(CFG_TARGET_TRIPLES), \
export CFG_SRC_DIR
export CFG_BUILD_DIR
export CFG_VERSION
export CFG_HOST_TRIPLE
export CFG_BUILD_TRIPLE
export CFG_LLVM_ROOT
export CFG_ENABLE_MINGW_CROSS
export CFG_PREFIX
Expand Down Expand Up @@ -409,7 +415,7 @@ CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
# if you're building a cross config, the host->* parts are
# effectively stage1, since it uses the just-built stage0.
ifeq ($(1),0)
ifneq ($(strip $(CFG_HOST_TRIPLE)),$(strip $(3)))
ifneq ($(strip $(CFG_BUILD_TRIPLE)),$(strip $(3)))
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
endif
endif
Expand All @@ -430,7 +436,7 @@ PERF_STAGE$(1)_T_$(2)_H_$(3) := \

endef

$(foreach build,$(CFG_TARGET_TRIPLES), \
$(foreach build,$(CFG_HOST_TRIPLES), \
$(eval $(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(foreach stage,$(STAGES), \
$(eval $(call SREQ,$(stage),$(target),$(build))))))))
Expand All @@ -451,13 +457,13 @@ rustc-stage$(2)-H-$(1): \

endef

$(foreach host,$(CFG_TARGET_TRIPLES), \
$(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(foreach stage,1 2 3, \
$(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))

rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)

define DEF_RUSTC_TARGET
# $(1) == architecture
Expand All @@ -468,12 +474,12 @@ endef
$(foreach host,$(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_RUSTC_TARGET,$(host))))

rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
rustc: rustc-H-$(CFG_HOST_TRIPLE)
rustc-stage1: rustc-stage1-H-$(CFG_BUILD_TRIPLE)
rustc-stage2: rustc-stage2-H-$(CFG_BUILD_TRIPLE)
rustc-stage3: rustc-stage3-H-$(CFG_BUILD_TRIPLE)
rustc: rustc-H-$(CFG_BUILD_TRIPLE)

rustc-H-all: $(foreach host,$(CFG_TARGET_TRIPLES),rustc-H-$(host))
rustc-H-all: $(foreach host,$(CFG_HOST_TRIPLES),rustc-H-$(host))

######################################################################
# Entrypoint rule
Expand All @@ -489,19 +495,27 @@ CFG_INFO := $(info cfg: *** stage2 and later will not be built ***)
CFG_INFO := $(info cfg:)

#XXX This is surely busted
all: $(SREQ1$(CFG_HOST_TRIPLE)) $(GENERATED) docs
all: $(SREQ1$(CFG_BUILD_TRIPLE)) $(GENERATED) docs

else

define ALL_TARGET_N
ifneq ($$(findstring $(1),$$(CFG_HOST_TRIPLES)),)
# This is a host
all-target-$(1)-host-$(2): $$(CSREQ2_T_$(1)_H_$(2))
else
# This is a target only
all-target-$(1)-host-$(2): $$(SREQ2_T_$(1)_H_$(2))
endif
endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call ALL_TARGET_N,$(target),$(CFG_HOST_TRIPLE))))
$(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(call ALL_TARGET_N,$(target),$(host)))))

ALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
all-target-$(target)-host-$(CFG_HOST_TRIPLE))
$(foreach host,$(CFG_HOST_TRIPLES), \
all-target-$(target)-host-$(host)))

all: $(ALL_TARGET_RULES) $(GENERATED) docs

Expand Down
23 changes: 11 additions & 12 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ then
fi


DEFAULT_HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
DEFAULT_BUILD_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"

CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
CFG_BUILD_DIR="$(pwd)/"
Expand Down Expand Up @@ -346,8 +346,9 @@ opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-
valopt prefix "/usr/local" "set installation prefix"
valopt local-rust-root "/usr/local" "set prefix for local rust binary"
valopt llvm-root "" "set LLVM root"
valopt host-triple "${DEFAULT_HOST_TRIPLE}" "LLVM host triple"
valopt target-triples "${CFG_HOST_TRIPLE}" "LLVM target triples"
valopt build-triple "${DEFAULT_BUILD_TRIPLE}" "LLVM build triple"
valopt host-triples "${CFG_BUILD_TRIPLE}" "LLVM host triples"
valopt target-triples "${CFG_HOST_TRIPLES}" "LLVM target triples"

# Validate Options
step_msg "validating $CFG_SELF args"
Expand Down Expand Up @@ -532,10 +533,6 @@ fi

CFG_PREFIX=${CFG_PREFIX%/}
CFG_TARGET_TRIPLES="$(echo $CFG_TARGET_TRIPLES | tr ',' ' ')"
case $CFG_TARGET_TRIPLES in
(*$CFG_HOST_TRIPLE*) ;;
(*) err "Host triple is not among the target triples." ;;
esac

if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
then
Expand All @@ -562,13 +559,13 @@ do
done

make_dir llvm
for t in $CFG_TARGET_TRIPLES
for t in $CFG_HOST_TRIPLES
do
make_dir llvm/$t
done

make_dir rustllvm
for t in $CFG_TARGET_TRIPLES
for t in $CFG_HOST_TRIPLES
do
make_dir rustllvm/$t
done
Expand All @@ -593,7 +590,7 @@ then
CFG_LIBDIR=bin
fi

for h in $CFG_TARGET_TRIPLES
for h in $CFG_HOST_TRIPLES
do
for t in $CFG_TARGET_TRIPLES
do
Expand Down Expand Up @@ -669,7 +666,7 @@ fi
# Configure llvm, only if necessary
step_msg "looking at LLVM"
CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
for t in $CFG_TARGET_TRIPLES
for t in $CFG_HOST_TRIPLES
do
do_reconfigure=1

Expand Down Expand Up @@ -819,6 +816,8 @@ putvar CFG_OSTYPE
putvar CFG_CPUTYPE
putvar CFG_CONFIGURE_ARGS
putvar CFG_PREFIX
putvar CFG_BUILD_TRIPLE
putvar CFG_HOST_TRIPLES
putvar CFG_TARGET_TRIPLES
putvar CFG_C_COMPILER
putvar CFG_LIBDIR
Expand Down Expand Up @@ -854,7 +853,7 @@ fi
putvar CFG_LLVM_ROOT
putvar CFG_LLVM_SRC_DIR

for t in $CFG_TARGET_TRIPLES
for t in $CFG_HOST_TRIPLES
do
CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
Expand Down
16 changes: 8 additions & 8 deletions mk/clean.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

CLEAN_STAGE_RULES = \
$(foreach stage, $(STAGES), \
$(foreach host, $(CFG_TARGET_TRIPLES), \
$(foreach host, $(CFG_HOST_TRIPLES), \
clean$(stage)_H_$(host) \
$(foreach target, $(CFG_TARGET_TRIPLES), \
clean$(stage)_T_$(target)_H_$(host))))
Expand All @@ -33,15 +33,15 @@ clean: clean-misc $(CLEAN_STAGE_RULES)

clean-misc:
@$(call E, cleaning)
$(Q)find rustllvm rt $(CFG_HOST_TRIPLE)/test \
$(Q)find rustllvm rt $(CFG_BUILD_TRIPLE)/test \
-name '*.[odasS]' -o \
-name '*.so' -o \
-name '*.dylib' -o \
-name '*.dll' -o \
-name '*.def' -o \
-name '*.bc' \
| xargs rm -f
$(Q)find rustllvm rt $(CFG_HOST_TRIPLE)\
$(Q)find rustllvm rt $(CFG_BUILD_TRIPLE)\
-name '*.dSYM' \
| xargs rm -Rf
$(Q)rm -f $(RUNTIME_OBJS) $(RUNTIME_DEF)
Expand Down Expand Up @@ -93,7 +93,7 @@ clean$(1)_H_$(2):

endef

$(foreach host, $(CFG_TARGET_TRIPLES), \
$(foreach host, $(CFG_HOST_TRIPLES), \
$(eval $(foreach stage, $(STAGES), \
$(eval $(call CLEAN_HOST_STAGE_N,$(stage),$(host))))))

Expand Down Expand Up @@ -127,12 +127,12 @@ clean$(1)_T_$(2)_H_$(3):
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/run_pass_stage* # For windows
endef

$(foreach host, $(CFG_TARGET_TRIPLES), \
$(foreach host, $(CFG_HOST_TRIPLES), \
$(eval $(foreach target, $(CFG_TARGET_TRIPLES), \
$(eval $(foreach stage, 0 1 2 3, \
$(eval $(call CLEAN_TARGET_STAGE_N,$(stage),$(target),$(host))))))))

define DEF_CLEAN_LLVM_TARGET
define DEF_CLEAN_LLVM_HOST
ifeq ($(CFG_LLVM_ROOT),)
clean-llvm$(1):
$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
Expand All @@ -142,5 +142,5 @@ clean-llvm$(1): ;
endif
endef

$(foreach target, $(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_CLEAN_LLVM_TARGET,$(target))))
$(foreach host, $(CFG_HOST_TRIPLES), \
$(eval $(call DEF_CLEAN_LLVM_HOST,$(host))))
2 changes: 1 addition & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ifeq ($(CFG_PANDOC),)
else

# The rustdoc executable
RUSTDOC = $(HBIN2_H_$(CFG_HOST_TRIPLE))/rustdoc$(X)
RUSTDOC = $(HBIN2_H_$(CFG_BUILD_TRIPLE))/rustdoc$(X)

# The library documenting macro
# $(1) - The output directory
Expand Down
2 changes: 1 addition & 1 deletion mk/host.mk
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_RUSTLLVM): \

endef

$(foreach t,$(CFG_TARGET_TRIPLES), \
$(foreach t,$(CFG_HOST_TRIPLES), \
$(eval $(call CP_HOST_STAGE_N,0,1,$(t),$(t))) \
$(eval $(call CP_HOST_STAGE_N,1,2,$(t),$(t))) \
$(eval $(call CP_HOST_STAGE_N,2,3,$(t),$(t))))
12 changes: 6 additions & 6 deletions mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ install-target-$(1)-host-$(2): $$(CSREQ$$(ISTAGE)_T_$(1)_H_$(2))
endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call INSTALL_TARGET_N,$(target),$(CFG_HOST_TRIPLE))))
$(eval $(call INSTALL_TARGET_N,$(target),$(CFG_BUILD_TRIPLE))))

INSTALL_TARGET_RULES = $(foreach target,$(CFG_TARGET_TRIPLES), \
install-target-$(target)-host-$(CFG_HOST_TRIPLE))
install-target-$(target)-host-$(CFG_BUILD_TRIPLE))

install: all install-host install-targets

# Shorthand for build/stageN/bin
HB = $(HBIN$(ISTAGE)_H_$(CFG_HOST_TRIPLE))
HB2 = $(HBIN2_H_$(CFG_HOST_TRIPLE))
HB = $(HBIN$(ISTAGE)_H_$(CFG_BUILD_TRIPLE))
HB2 = $(HBIN2_H_$(CFG_BUILD_TRIPLE))
# Shorthand for build/stageN/lib
HL = $(HLIB$(ISTAGE)_H_$(CFG_HOST_TRIPLE))
HL = $(HLIB$(ISTAGE)_H_$(CFG_BUILD_TRIPLE))
# Shorthand for the prefix bin directory
PHB = $(PREFIX_BIN)
# Shorthand for the prefix bin directory
PHL = $(PREFIX_LIB)

install-host: $(CSREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE))
install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_TRIPLE)_H_$(CFG_BUILD_TRIPLE))
$(Q)mkdir -p $(PREFIX_BIN)
$(Q)mkdir -p $(PREFIX_LIB)
$(Q)mkdir -p $(PREFIX_ROOT)/share/man/man1
Expand Down
4 changes: 2 additions & 2 deletions mk/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ endif

endef

$(foreach target,$(CFG_TARGET_TRIPLES), \
$(eval $(call DEF_LLVM_RULES,$(target))))
$(foreach host,$(CFG_HOST_TRIPLES), \
$(eval $(call DEF_LLVM_RULES,$(host))))
8 changes: 4 additions & 4 deletions mk/perf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@


ifdef CFG_PERF_TOOL
rustc-perf$(X): $(CFG_HOST_TRIPLE)/stage2/bin/rustc$(X)
rustc-perf$(X): $(CFG_BUILD_TRIPLE)/stage2/bin/rustc$(X)
@$(call E, perf compile: $@)
$(PERF_STAGE2_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE)) \
$(PERF_STAGE2_T_$(CFG_BUILD_TRIPLE)_H_$(CFG_BUILD_TRIPLE)) \
-o $@ $(COMPILER_CRATE) >rustc-perf.err 2>&1
$(Q)rm -f $(LIBRUSTC_GLOB)
else
rustc-perf$(X): $(CFG_HOST_TRIPLE)/stage2/bin/rustc$(X)
rustc-perf$(X): $(CFG_BUILD_TRIPLE)/stage2/bin/rustc$(X)
$(Q)touch $@
endif

perf: check-stage2-perf rustc-perf$(X)
$(Q)find $(CFG_HOST_TRIPLE)/test/perf -name \*.err | xargs cat
$(Q)find $(CFG_BUILD_TRIPLE)/test/perf -name \*.err | xargs cat
$(Q)cat rustc-perf.err
6 changes: 3 additions & 3 deletions mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ CFG_TESTLIB=$(CFG_BUILD_DIR)/$(2)/$(strip \
stage2/$(CFG_LIBDIR), \
$(if $(findstring stage3,$(1)), \
stage3/$(CFG_LIBDIR), \
)))))/rustc/$(CFG_HOST_TRIPLE)/$(CFG_LIBDIR)
)))))/rustc/$(CFG_BUILD_TRIPLE)/$(CFG_LIBDIR)

ifdef CFG_UNIXY
CFG_INFO := $(info cfg: unix-y environment)
Expand Down Expand Up @@ -200,7 +200,7 @@ else
CFG_LDPATH :=
CFG_RUN=$(2)
endif
CFG_RUN_TARG=$(call CFG_RUN,$(HLIB$(1)_H_$(CFG_HOST_TRIPLE)),$(2))
CFG_RUN_TARG=$(call CFG_RUN,$(HLIB$(1)_H_$(CFG_BUILD_TRIPLE)),$(2))
CFG_RUN_TEST=$(call CFG_RUN,$(call CFG_TESTLIB,$(1),$(3)),$(1))
CFG_LIBUV_LINK_FLAGS=-lWs2_32 -lpsapi -liphlpapi

Expand Down Expand Up @@ -318,7 +318,7 @@ endif
# .cfi pseudo-ops on mac
define CFG_MAKE_ASSEMBLER
CFG_ASSEMBLE_$(1)=$$(CPP) $$(CFG_DEPEND_FLAGS) $$(2) | \
$$(LLVM_MC_$$(CFG_HOST_TRIPLE)) \
$$(LLVM_MC_$$(CFG_BUILD_TRIPLE)) \
-assemble \
-filetype=obj \
-triple=$(1) \
Expand Down
4 changes: 2 additions & 2 deletions mk/pp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ else
"no-reformat\|xfail-pretty\|xfail-test")
endif

reformat: $(SREQ1$(CFG_HOST_TRIPLE))
reformat: $(SREQ1$(CFG_BUILD_TRIPLE))
@$(call E, reformat [stage1]: $@)
for i in $(PP_INPUTS_FILTERED); \
do $(call CFG_RUN_TARG,1,$(CFG_HOST_TRIPLE)/stage1/rustc$(X)) \
do $(call CFG_RUN_TARG,1,$(CFG_BUILD_TRIPLE)/stage1/rustc$(X)) \
--pretty normal $$i >$$i.tmp; \
if [ $$? -ne 0 ]; \
then echo failed to print $$i; rm $$i.tmp; \
Expand Down
Loading

0 comments on commit 15c0c35

Please sign in to comment.