add support for canadian-cross builds, reorganize dirs to avoid clashes

cross (or native) compilers meant to be run on a host different from
the build environment can now be built by setting the HOST make
variable on the command line or in config.mak. this requires (for
building the target libraries) a cross toolchain for the same TARGET,
but that can run on the build system, to be present already in the
PATH. future enhancements may make it possible to automatically build
and use the needed toolchain.

leaving HOST blank produces a toolchain that runs on the build system
(host==build in gcc jargon), the same as before with NATIVE unset.

the NATIVE make variable is now obsolete but still supported; it
simply causes HOST to be set equal to TARGET (thus producing a native
toolchain for the target).

builds are now placed in build/$(HOST)/$(TARGET) when HOST is set, and
build/local/$(TARGET) when it's not, so that builds for the same
target but different host do not clobber each other.

default OUTPUT directory when HOST is set is now output-$(HOST). as
usual, multiple targets can safely go in the same output directory,
but toolchains for different hosts should not.
This commit is contained in:
Rich Felker 2017-06-10 19:47:23 -04:00
parent e83fe4b8ce
commit 40005d3ff6
2 changed files with 31 additions and 14 deletions

View File

@ -1,5 +1,4 @@
OUTPUT = $(CURDIR)/output
SOURCES = sources SOURCES = sources
CONFIG_SUB_REV = 3d5db9ebe860 CONFIG_SUB_REV = 3d5db9ebe860
@ -26,7 +25,19 @@ LINUX_SITE = https://cdn.kernel.org/pub/linux/kernel
DL_CMD = wget -c -O DL_CMD = wget -c -O
BUILD_DIR = build-$(TARGET) ifneq ($(NATIVE),)
HOST := $(TARGET)
endif
ifneq ($(HOST),)
BUILD_DIR = build/$(HOST)/$(TARGET)
OUTPUT = $(CURDIR)/output-$(HOST)
else
BUILD_DIR = build/local/$(TARGET)
OUTPUT = $(CURDIR)/output
endif
REL_TOP = ../../..
-include config.mak -include config.mak
@ -142,19 +153,21 @@ $(BUILD_DIR):
mkdir -p $@ mkdir -p $@
$(BUILD_DIR)/Makefile: | $(BUILD_DIR) $(BUILD_DIR)/Makefile: | $(BUILD_DIR)
ln -sf ../litecross/Makefile $@ ln -sf $(REL_TOP)/litecross/Makefile $@
$(BUILD_DIR)/config.mak: | $(BUILD_DIR) $(BUILD_DIR)/config.mak: | $(BUILD_DIR)
printf >$@ '%s\n' \ printf >$@ '%s\n' \
"MUSL_SRCDIR = ../musl-$(MUSL_VER)" \ "TARGET = $(TARGET)" \
"GCC_SRCDIR = ../gcc-$(GCC_VER)" \ "HOST = $(HOST)" \
"BINUTILS_SRCDIR = ../binutils-$(BINUTILS_VER)" \ "MUSL_SRCDIR = $(REL_TOP)/musl-$(MUSL_VER)" \
$(if $(GMP_VER),"GMP_SRCDIR = ../gmp-$(GMP_VER)") \ "GCC_SRCDIR = $(REL_TOP)/gcc-$(GCC_VER)" \
$(if $(MPC_VER),"MPC_SRCDIR = ../mpc-$(MPC_VER)") \ "BINUTILS_SRCDIR = $(REL_TOP)/binutils-$(BINUTILS_VER)" \
$(if $(MPFR_VER),"MPFR_SRCDIR = ../mpfr-$(MPFR_VER)") \ $(if $(GMP_VER),"GMP_SRCDIR = $(REL_TOP)/gmp-$(GMP_VER)") \
$(if $(ISL_VER),"ISL_SRCDIR = ../isl-$(ISL_VER)") \ $(if $(MPC_VER),"MPC_SRCDIR = $(REL_TOP)/mpc-$(MPC_VER)") \
$(if $(LINUX_VER),"LINUX_SRCDIR = ../linux-$(LINUX_VER)") \ $(if $(MPFR_VER),"MPFR_SRCDIR = $(REL_TOP)/mpfr-$(MPFR_VER)") \
"-include ../config.mak" $(if $(ISL_VER),"ISL_SRCDIR = $(REL_TOP)/isl-$(ISL_VER)") \
$(if $(LINUX_VER),"LINUX_SRCDIR = $(REL_TOP)/linux-$(LINUX_VER)") \
"-include $(REL_TOP)/config.mak"
all: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.mak all: | $(SRC_DIRS) $(BUILD_DIR) $(BUILD_DIR)/Makefile $(BUILD_DIR)/config.mak
cd $(BUILD_DIR) && $(MAKE) $@ cd $(BUILD_DIR) && $(MAKE) $@

View File

@ -66,7 +66,11 @@ FULL_TOOLCHAIN_CONFIG = --enable-languages=c,c++ \
FULL_MUSL_CONFIG = $(MUSL_CONFIG) \ FULL_MUSL_CONFIG = $(MUSL_CONFIG) \
--prefix= --host=$(TARGET) --prefix= --host=$(TARGET)
ifeq ($(NATIVE),) ifneq ($(NATIVE),)
HOST:=$(TARGET)
endif
ifeq ($(HOST),)
SYSROOT = /$(TARGET) SYSROOT = /$(TARGET)
FULL_TOOLCHAIN_CONFIG += --with-build-sysroot=$(CURDIR)/obj_sysroot FULL_TOOLCHAIN_CONFIG += --with-build-sysroot=$(CURDIR)/obj_sysroot
FULL_MUSL_CONFIG += CC="$(XGCC)" LIBCC="../obj_toolchain/$(TARGET)/libgcc/libgcc.a" FULL_MUSL_CONFIG += CC="$(XGCC)" LIBCC="../obj_toolchain/$(TARGET)/libgcc/libgcc.a"
@ -77,7 +81,7 @@ obj_toolchain/gcc/.lc_built: | obj_sysroot/usr obj_sysroot/lib64 obj_sysroot/inc
obj_toolchain/.lc_built: | obj_sysroot/.lc_libs obj_sysroot/.lc_headers obj_toolchain/.lc_built: | obj_sysroot/.lc_libs obj_sysroot/.lc_headers
else else
SYSROOT = / SYSROOT = /
FULL_TOOLCHAIN_CONFIG += --host=$(TARGET) FULL_TOOLCHAIN_CONFIG += --host=$(HOST)
MUSL_VARS = MUSL_VARS =
endif endif