changeset 1812:acaa88463c0c draft

Add CROSS_COMPILER_PATH and CC_PREFIX knobs.
author Rob Landley <rob@landley.net>
date Thu, 12 Nov 2015 07:55:05 -0600
parents f326dbd73bee
children db11c049b66b
files build.sh config host-tools.sh native-compiler.sh root-filesystem.sh sources/functions.sh sources/sections/bash.build sources/sections/binutils.build sources/sections/distcc.build sources/sections/gcc.sh sources/sections/make.build sources/sections/musl.build sources/sections/toybox.build sources/sections/uClibc++.build sources/sections/uClibc.build
diffstat 15 files changed, 46 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/build.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -112,7 +112,7 @@
 
 # Do we need to build the simple cross compiler?
 
-if not_already simple-cross-compiler
+if [ -z "$CROSS_COMPILER_PATH" ] && not_already simple-cross-compiler
 then
   # If we need to build cross compiler, assume root filesystem is stale.
 
@@ -125,7 +125,8 @@
 # canadian cross.  (It's more powerful than we need here, but if you're going
 # to use the cross compiler in other contexts this is probably what you want.)
 
-if [ ! -z "$CROSS_COMPILER_HOST" ] && not_already cross-compiler
+if [ -z "$CROSS_COMPILER_PATH" ] && [ ! -z "$CROSS_COMPILER_HOST" ] &&
+  not_already cross-compiler
 then
   zap root-filesystem native-compiler system-image
 
@@ -159,7 +160,8 @@
 
 # Not trying to build nommu native compilers for the moment.
 
-if ! grep -q ELF2FLT sources/targets/"$ARCH" && not_already native-compiler
+if [ -z "$CROSS_COMPILER_PATH" ] && ! grep -q ELF2FLT sources/targets/"$ARCH" &&
+  not_already native-compiler
 then
   zap system-image
 
--- a/config	Thu Nov 12 07:54:10 2015 -0600
+++ b/config	Thu Nov 12 07:55:05 2015 -0600
@@ -147,3 +147,8 @@
 # to this to add extra debug info to their binaries. (Use with SKIP_STRIP)
 
 # export CFLAGS="-g -pipe"
+
+# If you don't want to build cross compilers, supply path to existing one.
+
+# export CROSS_COMPILER_PATH=/path/to/cross-compiler/bin
+# export CC_PREFIX=thingy-
--- a/host-tools.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/host-tools.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -195,7 +195,7 @@
   cleanup
 fi
 
-# Squashfs is the default packaging option.
+# Squashfs is the default toolchain packaging option.
 
 if [ ! -f "${STAGE_DIR}"/mksquashfs ]
 then
--- a/native-compiler.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/native-compiler.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -12,7 +12,7 @@
 source sources/include.sh && load_target "$1" || exit 1
 check_for_base_arch || exit 0
 
-check_prerequisite "${ARCH}-cc"
+check_prerequisite "${CC_PREFIX}cc"
 
 [ -z "$HOST_ARCH" ] && HOST_ARCH="$ARCH" && STAGE_DIR="$STAGE_DIR/usr" ||
   check_prerequisite "${HOST_ARCH}-cc"
--- a/root-filesystem.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/root-filesystem.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -9,7 +9,7 @@
 source sources/include.sh || exit 1
 load_target "$1"
 check_for_base_arch || exit 0
-check_prerequisite "${ARCH}-cc"
+check_prerequisite "${CC_PREFIX}cc"
 
 # Source control isn't good at storing empty directories, so create
 # directory layout and apply permissions changes.
--- a/sources/functions.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/functions.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -8,6 +8,15 @@
 {
   local i
 
+  if [ ! -z "$CROSS_COMPILER_PATH" ]
+  then
+    [ -z "$CC_PREFIX" ] &&
+      echo "CROSS_COMPILER_PATH without CC_PREFIX" >&2 &&
+      dienow
+    echo -n "$CROSS_COMPILER_PATH:"
+    return
+  fi
+
   # Output cross it if exists, else simple.  If neither exists, output simple.
 
   for i in "$BUILD"/{,simple-}cross-compiler-"$1/bin"
@@ -70,7 +79,8 @@
   [ ! -z "$HOST_ARCH" ] && [ "$HOST_ARCH" != "$ARCH" ] &&
     PATH="$(cc_path "$HOST_ARCH")$PATH"
 
-  DO_CROSS="CROSS_COMPILE=${ARCH}-"
+  export_if_blank CC_PREFIX="${ARCH}-"
+  DO_CROSS="CROSS_COMPILE=$CC_PREFIX"
 
   return 0
 }
--- a/sources/sections/bash.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/bash.build	Thu Nov 12 07:55:05 2015 -0600
@@ -1,7 +1,7 @@
 # wire around some tests ./configure can't run when cross-compiling.
 echo -e "ac_cv_func_setvbuf_reversed=no\nbash_cv_sys_named_pipes=yes\nbash_cv_have_mbstate_t=yes\nbash_cv_getenv_redef=no\nac_cv_func_bindtextdomain=nyet" > config.cache &&
-LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${ARCH}-cc" RANLIB="${ARCH}-ranlib" \
-  ./configure --prefix="$STAGE_DIR" \
+LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${CC_PREFIX}cc" \
+  RANLIB="${CC_PREFIX}ranlib" ./configure --prefix="$STAGE_DIR" \
   --build="${CROSS_HOST}" --host="${CROSS_TARGET}" --cache-file=config.cache \
   --without-bash-malloc --disable-readline &&
 # note: doesn't work with -j
--- a/sources/sections/binutils.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/binutils.build	Thu Nov 12 07:55:05 2015 -0600
@@ -7,7 +7,6 @@
 
 function configure_binutils()
 {
-#  AR=ar AS=as LD=ld NM=nm OBJDUMP=objdump OBJCOPY=objcopy \
     "$CURSRC/configure" --prefix="$STAGE_DIR" "$@" --target="$CROSS_TARGET" \
     --disable-nls --disable-shared --disable-multilib --disable-werror \
     --with-lib-path=lib --program-prefix="$TOOLCHAIN_PREFIX" $BINUTILS_FLAGS
--- a/sources/sections/distcc.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/distcc.build	Thu Nov 12 07:55:05 2015 -0600
@@ -1,5 +1,5 @@
 rsync_cv_HAVE_C99_VSNPRINTF=yes \
-LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${ARCH}-cc" ./configure \
+LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${CC_PREFIX}cc" ./configure \
   --host="${CROSS_TARGET}" --prefix="$STAGE_DIR" --bindir="$STAGE_DIR/distcc" \
   --with-included-popt --disable-Werror &&
 make -j $CPUS &&
--- a/sources/sections/gcc.sh	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/gcc.sh	Thu Nov 12 07:55:05 2015 -0600
@@ -47,7 +47,7 @@
   # have a chicken and egg problem otherwise.  What would you have compiled
   # that C library _with_?)
 
-  AR_FOR_TARGET="${ARCH}-ar" configure_gcc \
+  AR_FOR_TARGET="${CC_PREFIX}ar" configure_gcc \
     --disable-threads --disable-shared --host="$CROSS_HOST"
 else
   # Canadian cross a compiler to run on $HOST_ARCH as its host and output
@@ -59,15 +59,15 @@
   [ -z "$ELF2FLT" ] && X=--enable-shared || X=--disable-shared
   CC="${HOST_ARCH}-cc" AR="${HOST_ARCH}-ar" AS="${HOST_ARCH}-as" \
     LD="${HOST_ARCH}-ld" NM="${HOST_ARCH}-nm" \
-    CC_FOR_TARGET="${ARCH}-cc" AR_FOR_TARGET="${ARCH}-ar" \
-    NM_FOR_TARGET="${ARCH}-nm" GCC_FOR_TARGET="${ARCH}-cc" \
-    AS_FOR_TARGET="${ARCH}-as" LD_FOR_TARGET="${ARCH}-ld" \
-    CXX_FOR_TARGET="${ARCH}-c++" \
-    ac_cv_path_AR_FOR_TARGET="${ARCH}-ar" \
-    ac_cv_path_RANLIB_FOR_TARGET="${ARCH}-ranlib" \
-    ac_cv_path_NM_FOR_TARGET="${ARCH}-nm" \
-    ac_cv_path_AS_FOR_TARGET="${ARCH}-as" \
-    ac_cv_path_LD_FOR_TARGET="${ARCH}-ld" \
+    CC_FOR_TARGET="${CC_PREFIX}cc" AR_FOR_TARGET="${CC_PREFIX}ar" \
+    NM_FOR_TARGET="${CC_PREFIX}nm" GCC_FOR_TARGET="${CC_PREFIX}cc" \
+    AS_FOR_TARGET="${CC_PREFIX}as" LD_FOR_TARGET="${CC_PREFIX}ld" \
+    CXX_FOR_TARGET="${CC_PREFIX}c++" \
+    ac_cv_path_AR_FOR_TARGET="${CC_PREFIX}ar" \
+    ac_cv_path_RANLIB_FOR_TARGET="${CC_PREFIX}ranlib" \
+    ac_cv_path_NM_FOR_TARGET="${CC_PREFIX}nm" \
+    ac_cv_path_AS_FOR_TARGET="${CC_PREFIX}as" \
+    ac_cv_path_LD_FOR_TARGET="${CC_PREFIX}ld" \
     configure_gcc --enable-threads=posix $X \
       --build="$CROSS_HOST" --host="${CROSS_TARGET/unknown-elf/walrus-elf}"
 fi
--- a/sources/sections/make.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/make.build	Thu Nov 12 07:55:05 2015 -0600
@@ -1,4 +1,4 @@
-LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${ARCH}-cc" ./configure \
+LDFLAGS="$STATIC_FLAGS $LDFLAGS" CC="${CC_PREFIX}cc" ./configure \
   --prefix="$STAGE_DIR" --build="${CROSS_HOST}" --host="${CROSS_TARGET}" &&
 make -j $CPUS &&
 make -j $CPUS install
--- a/sources/sections/musl.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/musl.build	Thu Nov 12 07:55:05 2015 -0600
@@ -1,7 +1,7 @@
 # Build and install musl
 
-CC= CROSS_COMPILE=${ARCH}- ./configure --prefix=/ &&
-DESTDIR="$STAGE_DIR" make -j $CPUS CROSS_COMPILE=${ARCH}- all install &&
+CC= $DO_CROSS ./configure --prefix=/ &&
+DESTDIR="$STAGE_DIR" make -j $CPUS $DO_CROSS all install &&
 echo '#define __MUSL__' >> "$STAGE_DIR"/include/features.h &&
 ln -s libc.so "$STAGE_DIR/lib/ld-musl.so.0"
 
--- a/sources/sections/toybox.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/toybox.build	Thu Nov 12 07:55:05 2015 -0600
@@ -1,6 +1,8 @@
 # Build toybox statically by default, but don't statically link against
 # glibc (during host-tools.sh build) because glibc is buggy and can't combine
-# --static with --gc-sections. See http://blah for details
+# --static with --gc-sections. See
+# http://elinux.org/images/2/2d/ELC2010-gc-sections_Denys_Vlasenko.pdf
+# for details
 
 # Build toybox
 
@@ -8,7 +10,7 @@
   $( [ -z "$BUSYBOX" ] && echo install$([ -z "$ARCH" ] && echo _flat) )
 do
   PREFIX="$STAGE_DIR" CFLAGS="$CFLAGS $STATIC_FLAGS" CC= STRIP= \
-    CROSS_COMPILE=${ARCH:+${ARCH}-} make -j $CPUS $VERBOSITY $i || dienow
+    make -j $CPUS $VERBOSITY $DO_CROSS $i || dienow
 done
 cp .config "$WORK"/config-toybox || dienow
 
--- a/sources/sections/uClibc++.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/uClibc++.build	Thu Nov 12 07:55:05 2015 -0600
@@ -8,7 +8,7 @@
   sed -i 's/.*\(BUILD_ONLY_STATIC_LIB\).*/\1=y/' .config || dienow
 fi
 CROSS= make oldconfig &&
-CROSS="$ARCH"- make &&
+CROSS="$CC_PREFIX" make &&
 CROSS= make install PREFIX="$STAGE_DIR/c++" &&
 
 # Move libraries somewhere useful.
--- a/sources/sections/uClibc.build	Thu Nov 12 07:54:10 2015 -0600
+++ b/sources/sections/uClibc.build	Thu Nov 12 07:55:05 2015 -0600
@@ -9,7 +9,7 @@
 
 make_uClibc()
 {
-  make -j $CPUS $VERBOSITY CROSS="${ARCH}-" \
+  make -j $CPUS $VERBOSITY $DO_CROSS \
     UCLIBC_LDSO_NAME=ld-uClibc KERNEL_HEADERS="$STAGE_DIR/include" \
     PREFIX="$STAGE_DIR/" RUNTIME_PREFIX=/ DEVEL_PREFIX=/ $1
 }