mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Parameterize the LLVM build over the target triples
This commit is contained in:
parent
a4e1a438f6
commit
4b6585c924
36
Makefile.in
36
Makefile.in
@ -196,19 +196,31 @@ COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/comp/, \
|
||||
# LLVM macros
|
||||
######################################################################
|
||||
|
||||
# Any rules that depend on LLVM should depend on LLVM_CONFIG
|
||||
LLVM_CONFIG:=$(CFG_LLVM_INST_DIR)/bin/llvm-config
|
||||
LLVM_VERSION=$(shell "$(LLVM_CONFIG)" --version)
|
||||
LLVM_BINDIR=$(shell "$(LLVM_CONFIG)" --bindir)
|
||||
LLVM_INCDIR=$(shell "$(LLVM_CONFIG)" --includedir)
|
||||
LLVM_LIBDIR=$(shell "$(LLVM_CONFIG)" --libdir)
|
||||
LLVM_LIBS=$(shell "$(LLVM_CONFIG)" --libs)
|
||||
LLVM_LDFLAGS=$(shell "$(LLVM_CONFIG)" --ldflags)
|
||||
LLVM_CXXFLAGS=$(shell "$(LLVM_CONFIG)" --cxxflags)
|
||||
LLVM_HOST_TRIPLE=$(shell "$(LLVM_CONFIG)" --host-target)
|
||||
define DEF_LLVM_VARS
|
||||
# The configure script defines these variables with the target triples
|
||||
# separated by Z. This defines new ones with the expected format.
|
||||
CFG_LLVM_BUILD_DIR_$(1):=$$(CFG_LLVM_BUILD_DIR_$(subst -,_,$(1)))
|
||||
CFG_LLVM_INST_DIR_$(1):=$$(CFG_LLVM_INST_DIR_$(subst -,_,$(1)))
|
||||
|
||||
# Any rules that depend on LLVM should depend on LLVM_CONFIG
|
||||
LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config
|
||||
LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
|
||||
LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
|
||||
LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)
|
||||
LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
|
||||
LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs)
|
||||
LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
|
||||
LLVM_CXXFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags)
|
||||
LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
|
||||
|
||||
LLVM_AS_$(1)=$$(LLVM_BINDIR_$(1))/llvm-as$$(X)
|
||||
LLC_$(1)=$$(LLVM_BINDIR_$(1))/llc$$(X)
|
||||
|
||||
endef
|
||||
|
||||
$(foreach target,$(CFG_TARGET_TRIPLES), \
|
||||
$(eval $(call DEF_LLVM_VARS,$(target))))
|
||||
|
||||
LLVM_AS=$(LLVM_BINDIR)/llvm-as$(X)
|
||||
LLC=$(LLVM_BINDIR)/llc$(X)
|
||||
|
||||
######################################################################
|
||||
# Exports for sub-utilities
|
||||
|
57
configure
vendored
57
configure
vendored
@ -372,12 +372,17 @@ for i in \
|
||||
nd nd/std \
|
||||
dl \
|
||||
test/run-pass test/run-fail test/compile-fail \
|
||||
test/bench test/perf test/pretty \
|
||||
llvm
|
||||
test/bench test/perf test/pretty
|
||||
do
|
||||
make_dir $i
|
||||
done
|
||||
|
||||
make_dir llvm
|
||||
for t in $CFG_TARGET_TRIPLES
|
||||
do
|
||||
make_dir llvm/$t
|
||||
done
|
||||
|
||||
make_dir rustllvm
|
||||
for t in $CFG_TARGET_TRIPLES
|
||||
do
|
||||
@ -446,18 +451,23 @@ msg
|
||||
|
||||
# Configure llvm. Here we go...
|
||||
CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm
|
||||
CFG_LLVM_BUILD_DIR=${CFG_BUILD_DIR}/llvm
|
||||
# Just use LLVM straight from its build directory to avoid 'make install' time
|
||||
CFG_LLVM_INST_DIR=${CFG_LLVM_BUILD_DIR}/Release+Asserts
|
||||
putvar CFG_LLVM_SRC_DIR
|
||||
|
||||
if [ -z $CFG_LLVM_ROOT ]
|
||||
then
|
||||
step_msg "configuring LLVM"
|
||||
for t in $CFG_TARGET_TRIPLES
|
||||
do
|
||||
if [ -z $CFG_LLVM_ROOT ]
|
||||
then
|
||||
step_msg "configuring LLVM for $t"
|
||||
|
||||
LLVM_BUILD_DIR=$CFG_BUILD_DIR/llvm/$t
|
||||
# Just use LLVM straight from its build directory to
|
||||
# avoid 'make install' time
|
||||
LLVM_INST_DIR=$LLVM_BUILD_DIR/Release+Asserts
|
||||
|
||||
LLVM_TARGETS="--enable-targets=x86,x86_64"
|
||||
LLVM_BUILD="--build=${CFG_HOST_TRIPLE}"
|
||||
LLVM_HOST="--host=${CFG_HOST_TRIPLE}"
|
||||
LLVM_TARGET="--target=${CFG_HOST_TRIPLE}"
|
||||
LLVM_BUILD="--build=$t"
|
||||
LLVM_HOST="--host=$t"
|
||||
LLVM_TARGET="--target=$t"
|
||||
LLVM_OPTS="--enable-optimized --disable-docs"
|
||||
|
||||
LLVM_CXX_32="g++ -m32"
|
||||
@ -490,18 +500,29 @@ then
|
||||
export CXXFLAGS
|
||||
export LDFLAGS
|
||||
|
||||
cd $CFG_LLVM_BUILD_DIR
|
||||
cd $LLVM_BUILD_DIR
|
||||
# FIXME: This won't work if CFG_SRC_DIR is absolute
|
||||
${CFG_BUILD_DIR}/${CFG_LLVM_SRC_DIR}/configure $LLVM_FLAGS
|
||||
cd $CFG_BUILD_DIR
|
||||
else
|
||||
else
|
||||
LLVM_BUILD_DIR=bogus
|
||||
# The user is using their own LLVM
|
||||
CFG_LLVM_INST_DIR=$CFG_LLVM_ROOT
|
||||
fi
|
||||
LLVM_INST_DIR=$CFG_LLVM_ROOT
|
||||
fi
|
||||
|
||||
putvar CFG_LLVM_SRC_DIR
|
||||
putvar CFG_LLVM_BUILD_DIR
|
||||
putvar CFG_LLVM_INST_DIR
|
||||
# Construct variables for LLVM build and install directories for
|
||||
# each target. These will be named
|
||||
# CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
|
||||
# target_triple will be converted to underscore, because bash
|
||||
# variables can't contain hyphens. The makefile will then have to
|
||||
# convert back.
|
||||
CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
|
||||
CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
|
||||
eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
|
||||
eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
|
||||
putvar $CFG_LLVM_BUILD_DIR
|
||||
putvar $CFG_LLVM_INST_DIR
|
||||
done
|
||||
|
||||
|
||||
# Munge any paths that appear in config.mk back to posix-y
|
||||
|
@ -14,11 +14,11 @@ rt/%.d: rt/%.cpp $(MKFILES)
|
||||
$(Q)rm -f $@.tmp.bak
|
||||
$(Q)mv $@.tmp $@
|
||||
|
||||
rustllvm/%.d: rustllvm/%.cpp $(MKFILES) $(LLVM_CONFIG)
|
||||
rustllvm/%.d: rustllvm/%.cpp $(MKFILES) $(LLVM_CONFIG_$(CFG_HOST_TRIPLE))
|
||||
@$(call E, dep: $@)
|
||||
$(Q)$(call CFG_DEPEND_C, $@ \
|
||||
$(subst $(S)src/,,$(patsubst %.cpp, %.o, $<)), \
|
||||
$(LLVM_CXXFLAGS) $(RUSTLLVM_INCS)) $< >$@.tmp
|
||||
$(LLVM_CXXFLAGS_$(CFG_HOST_TRIPLE)) $(RUSTLLVM_INCS)) $< >$@.tmp
|
||||
$(Q)$(CFG_PATH_MUNGE) $@.tmp
|
||||
$(Q)rm -f $@.tmp.bak
|
||||
$(Q)mv $@.tmp $@
|
||||
|
18
mk/llvm.mk
18
mk/llvm.mk
@ -2,6 +2,18 @@
|
||||
LLVM_DEPS:=$(wildcard $(addprefix $(CFG_LLVM_SRC_DIR)/, \
|
||||
* */*h */*/*h */*/*/*h */*cpp */*/*cpp */*/*/*cpp))
|
||||
|
||||
$(LLVM_CONFIG): $(LLVM_DEPS)
|
||||
@$(call E, make: llvm)
|
||||
$(Q)make -C $(CFG_LLVM_BUILD_DIR)
|
||||
define DEF_LLVM_RULES
|
||||
|
||||
# If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
|
||||
ifeq ($(CFG_LLVM_ROOT),)
|
||||
|
||||
$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS_$(1))
|
||||
@$$(call E, make: llvm)
|
||||
$$(Q)make -C $$(CFG_LLVM_BUILD_DIR_$(1))
|
||||
|
||||
endif
|
||||
|
||||
endef
|
||||
|
||||
$(foreach target,$(CFG_TARGET_TRIPLES), \
|
||||
$(eval $(call DEF_LLVM_RULES,$(target))))
|
@ -14,7 +14,7 @@ endif
|
||||
|
||||
RUSTLLVM_DEF_$(1) := rustllvm/rustllvm$$(CFG_DEF_SUFFIX)
|
||||
|
||||
RUSTLLVM_INCS_$(1) := -iquote $$(LLVM_INCDIR) \
|
||||
RUSTLLVM_INCS_$(1) = -iquote $$(LLVM_INCDIR_$(1)) \
|
||||
-iquote $$(S)src/rustllvm/include
|
||||
RUSTLLVM_OBJS_OBJS_$(1) := $$(RUSTLLVM_OBJS_CS_$(1):rustllvm/%.cpp=rustllvm/$(1)/%.o)
|
||||
|
||||
@ -22,13 +22,13 @@ rustllvm/$(1)/$(CFG_RUSTLLVM): $$(RUSTLLVM_OBJS_OBJS_$(1)) \
|
||||
$$(MKFILES) $$(RUSTLLVM_DEF_$(1))
|
||||
@$$(call E, link: $$@)
|
||||
$$(Q)$$(call CFG_LINK_C_$(1),$$@,$$(RUSTLLVM_OBJS_OBJS_$(1)) \
|
||||
$$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS) \
|
||||
$$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS_$(1)) \
|
||||
$$(CFG_GCCISH_POST_LIB_FLAGS) \
|
||||
$$(LLVM_LDFLAGS),$$(RUSTLLVM_DEF_$(1)),$$(CFG_RUSTLLVM))
|
||||
$$(LLVM_LDFLAGS_$(1)),$$(RUSTLLVM_DEF_$(1)),$$(CFG_RUSTLLVM))
|
||||
|
||||
rustllvm/$(1)/%.o: rustllvm/%.cpp $$(MKFILES) $$(LLVM_CONFIG)
|
||||
rustllvm/$(1)/%.o: rustllvm/%.cpp $$(MKFILES) $$(LLVM_CONFIG_$(1))
|
||||
@$$(call E, compile: $$@)
|
||||
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(LLVM_CXXFLAGS) $$(RUSTLLVM_INCS_$(1))) $$<
|
||||
$$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(LLVM_CXXFLAGS_$(1)) $$(RUSTLLVM_INCS_$(1))) $$<
|
||||
endef
|
||||
|
||||
# Instantiate template for all stages
|
||||
|
@ -13,9 +13,9 @@ $$(TARGET_LIB$(1)$(2))/intrinsics.ll: \
|
||||
$$(Q)sed s/@CFG_TARGET_TRIPLE@/$(2)/ $$< > $$@
|
||||
|
||||
$$(TARGET_LIB$(1)$(2))/intrinsics.bc: $$(TARGET_LIB$(1)$(2))/intrinsics.ll \
|
||||
$$(LLVM_CONFIG)
|
||||
$$(LLVM_CONFIG_$(2))
|
||||
@$$(call E, llvms-as: $$@)
|
||||
$$(Q)$$(LLVM_AS) -o $$@ $$<
|
||||
$$(Q)$$(LLVM_AS_$(2)) -o $$@ $$<
|
||||
|
||||
$$(TARGET_LIB$(1)$(2))/$$(CFG_STDLIB): \
|
||||
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
|
||||
|
Loading…
Reference in New Issue
Block a user