Эх сурвалжийг харах

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.
Rich Felker 7 жил өмнө
parent
commit
40005d3ff6
2 өөрчлөгдсөн 31 нэмэгдсэн , 14 устгасан
  1. 25 12
      Makefile
  2. 6 2
      litecross/Makefile

+ 25 - 12
Makefile

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

+ 6 - 2
litecross/Makefile

@@ -66,7 +66,11 @@ FULL_TOOLCHAIN_CONFIG = --enable-languages=c,c++ \
 FULL_MUSL_CONFIG = $(MUSL_CONFIG) \
 	--prefix= --host=$(TARGET)
 
-ifeq ($(NATIVE),)
+ifneq ($(NATIVE),)
+HOST:=$(TARGET)
+endif
+
+ifeq ($(HOST),)
 SYSROOT = /$(TARGET)
 FULL_TOOLCHAIN_CONFIG += --with-build-sysroot=$(CURDIR)/obj_sysroot
 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
 else
 SYSROOT = /
-FULL_TOOLCHAIN_CONFIG += --host=$(TARGET)
+FULL_TOOLCHAIN_CONFIG += --host=$(HOST)
 MUSL_VARS = 
 endif