changeset 1090:affef1edbdba

Cleanup "FROM_ARCH" mess. Rename FROM_ARCH->HOST_ARCH, make stage script responsible for setting HOST_ARCH (not includes.sh). Also, remove HOST_UTILS variable, only build uClibc utils for non-simple compilers and bypass uClibc's (weird) makefile for the utils directory.
author Rob Landley <rob@landley.net>
date Fri, 21 May 2010 22:26:25 -0500
parents b7efc55a3b09
children 83601c58062e
files build.sh native-compiler.sh simple-cross-compiler.sh sources/functions.sh sources/sections/binutils.build sources/sections/ccwrap.sh sources/sections/gcc.sh sources/sections/uClibc.build
diffstat 8 files changed, 50 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/build.sh	Fri May 21 22:25:10 2010 -0500
+++ b/build.sh	Fri May 21 22:26:25 2010 -0500
@@ -68,7 +68,7 @@
   # the host (to build the executables) and one for the target (to build
   # the libraries).
 
-  BUILD_STATIC=all FROM_ARCH="$STATIC_CC_HOST" STAGE_NAME=cross-compiler \
+  BUILD_STATIC=all HOST_ARCH="$STATIC_CC_HOST" STAGE_NAME=cross-compiler \
     ./native-compiler.sh "$ARCH" || exit 1
 
   if [ ! -z "$CROSS_SMOKE_TEST" ]
--- a/native-compiler.sh	Fri May 21 22:25:10 2010 -0500
+++ b/native-compiler.sh	Fri May 21 22:26:25 2010 -0500
@@ -12,12 +12,17 @@
 source sources/include.sh && read_arch_dir "$1" || exit 1
 check_for_base_arch || exit 0
 
-# Building a cross compiler requires _two_ existing simple compilers: one for
-# the host (to build the executables), and one for the target (to build
-# the libraries).  For native compilers both checks test for the same thing.
-
 check_prerequisite "${ARCH}-cc"
-check_prerequisite "${FROM_ARCH}-cc"
+if [ -z "$HOST_ARCH" ]
+then
+  # Build unprefixed native compiler
+  HOST_ARCH="$ARCH"
+else
+  # Build prefixed cross compiler via canadian cross.  Needs a host compiler
+  # to build the executables and a target compiler to build the libraries.
+  PROGRAM_PREFIX="$ARCH-"
+  check_prerequisite "${HOST_ARCH}-cc"
+fi
 
 mkdir -p "$STAGE_DIR/bin" || dienow
 
@@ -42,7 +47,7 @@
 # For a native compiler, build make, bash, and distcc.  (Yes, this is an old
 # version of Bash.  It's intentional.)
 
-if [ "$FROM_ARCH" == "$ARCH" ]
+if [ "$HOST_ARCH" == "$ARCH" ]
 then
   build_section make
   build_section bash
--- a/simple-cross-compiler.sh	Fri May 21 22:25:10 2010 -0500
+++ b/simple-cross-compiler.sh	Fri May 21 22:26:25 2010 -0500
@@ -26,20 +26,21 @@
 
 echo "=== Building $STAGE_NAME"
 
+export PROGRAM_PREFIX="${ARCH}-"
+
 # Build binutils, gcc, and ccwrap
 
-FROM_ARCH= PROGRAM_PREFIX="${ARCH}-" build_section binutils
-FROM_ARCH= PROGRAM_PREFIX="${ARCH}-" build_section gcc
-FROM_ARCH= PROGRAM_PREFIX="${ARCH}-" build_section ccwrap
+build_section binutils
+build_section gcc
+build_section ccwrap
 
 # Build C Library
 
 build_section linux-headers
-HOST_UTILS=1 build_section uClibc
+build_section uClibc
 
 cat > "${STAGE_DIR}"/README << EOF &&
-Cross compiler for $ARCH
-From http://impactlinux.com/fwl
+Cross compiler for $ARCH from http://aboriginal.impactlinux.com
 
 To use: Add the "bin" subdirectory to your \$PATH, and use "$ARCH-cc" as
 your compiler.
--- a/sources/functions.sh	Fri May 21 22:25:10 2010 -0500
+++ b/sources/functions.sh	Fri May 21 22:26:25 2010 -0500
@@ -4,12 +4,14 @@
 
 source sources/utility_functions.sh
 
-# Output the first cross compiler (static or basic) that's installed.
+# Output path to cross compiler.
 
 cc_path()
 {
   local i
 
+  # Output cross it if exists, else simple.  If neither exists, output simple.
+
   for i in "$BUILD"/{,simple-}cross-compiler-"$1/bin"
   do
     [ -e "$i/$1-cc" ] && break
@@ -46,29 +48,15 @@
   # during root-filesystem.sh, and the host compiler links binaries against the
   # wrong libc.)
   export_if_blank CROSS_HOST=`uname -m`-walrus-linux
-  if [ -z "$CROSS_TARGET" ]
-  then
-    export CROSS_TARGET=${ARCH}-unknown-linux
-  else
-    [ -z "$FROM_HOST" ] && FROM_HOST="${CROSS_TARGET}"
-  fi
-
-  # Override FROM_ARCH to perform a canadian cross in root-filesystem.sh
-
-  if [ -z "$FROM_ARCH" ]
-  then
-    FROM_ARCH="${ARCH}"
-  else
-    [ -z "$PROGRAM_PREFIX" ] && PROGRAM_PREFIX="${ARCH}-"
-  fi
-  export_if_blank FROM_HOST="${FROM_ARCH}-thingy-linux"
+  export_if_blank CROSS_TARGET=${ARCH}-unknown-linux
 
   # Setup directories and add the cross compiler to the start of the path.
 
   STAGE_DIR="$BUILD/${STAGE_NAME}-${ARCH_NAME}"
 
   export PATH="$(cc_path "$ARCH")$PATH"
-  [ "$FROM_ARCH" != "$ARCH" ] && PATH="$(cc_path "$FROM_ARCH")$PATH"
+  [ ! -z "$HOST_ARCH" ] && [ "$HOST_ARCH" != "$ARCH" ] &&
+    PATH="$(cc_path "$HOST_ARCH")$PATH"
 
   DO_CROSS="CROSS_COMPILE=${ARCH}-"
 
--- a/sources/sections/binutils.build	Fri May 21 22:25:10 2010 -0500
+++ b/sources/sections/binutils.build	Fri May 21 22:26:25 2010 -0500
@@ -9,7 +9,7 @@
   [ $? -ne 0 ] && dienow
 }
 
-if [ -z "$FROM_ARCH" ]
+if [ -z "$HOST_ARCH" ]
 then
   # Create a simple cross compiler, from this host to target $ARCH.
   # This has no prerequisites.
@@ -19,13 +19,14 @@
   AR=ar AS=as LD=ld NM=nm OBJDUMP=objdump OBJCOPY=objcopy configure_binutils
 else
   # Canadian cross for an arbitrary host/target.  The new compiler will run
-  # on $FROM_ARCH as its host, and build executables for $ARCH as its target.
+  # on $HOST_ARCH as its host, and build executables for $ARCH as its target.
   # (Use host==target to produce a native compiler.)  Doing this requires
-  # existing host ($FROM_ARCH) _and_ target ($ARCH) cross compilers as
+  # existing host ($HOST_ARCH) _and_ target ($ARCH) cross compilers as
   # prerequisites.
 
-  AR="${FROM_ARCH}-ar" CC="${FROM_ARCH}-cc" configure_binutils \
-    --build="$CROSS_HOST" --host="$FROM_HOST" 
+
+  AR="${HOST_ARCH}-ar" CC="${HOST_ARCH}-cc" configure_binutils \
+    --build="$CROSS_HOST" --host="$CROSS_TARGET"
 fi
 
 # Now that it's configured, build and install binutils
--- a/sources/sections/ccwrap.sh	Fri May 21 22:25:10 2010 -0500
+++ b/sources/sections/ccwrap.sh	Fri May 21 22:26:25 2010 -0500
@@ -2,12 +2,12 @@
 
 # Which compiler do we build the wrapper with, and should it be static?
 
-if [ -z "$FROM_ARCH" ] || [ "$BUILD_STATIC" == none ]
+if [ -z "$HOST_ARCH" ] || [ "$BUILD_STATIC" == none ]
 then
   TEMP="$CC"
   STATIC_FLAGS=
 else
-  TEMP="${FROM_ARCH}-cc"
+  TEMP="${HOST_ARCH}-cc"
   STATIC_FLAGS=--static
 fi
 
--- a/sources/sections/gcc.sh	Fri May 21 22:25:10 2010 -0500
+++ b/sources/sections/gcc.sh	Fri May 21 22:26:25 2010 -0500
@@ -25,7 +25,7 @@
   ln -s "$(which ${CC_FOR_TARGET:-cc})" gcc/xgcc || dienow
 }
 
-if [ -z "$FROM_ARCH" ]
+if [ -z "$HOST_ARCH" ]
 then
   # Produce a standard host->target cross compiler, which does not include
   # thread support or libgcc_s.so to make it depend on the host less.
@@ -38,14 +38,14 @@
   AR_FOR_TARGET="${ARCH}-ar" configure_gcc \
     --disable-threads --disable-shared --host="$CROSS_HOST"
 else
-  # Canadian cross a compiler to run on $FROM_ARCH as its host and output
+  # Canadian cross a compiler to run on $HOST_ARCH as its host and output
   # binaries for $ARCH as its target.
 
   # GCC has some deep assumptions here, which are wrong.  Lots of redundant
   # corrections are required to make it stop.
 
-  CC="${FROM_ARCH}-cc" AR="${FROM_ARCH}-ar" AS="${FROM_ARCH}-as" \
-    LD="${FROM_ARCH}-ld" NM="${FROM_ARCH}-nm" \
+  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" \
@@ -66,7 +66,7 @@
 
 mkdir -p "$STAGE_DIR"/cc/lib || dienow
 
-if [ ! -z "$FROM_ARCH" ]
+if [ ! -z "$HOST_ARCH" ]
 then
   # We also need to beat libsupc++ out of gcc (which uClibc++ needs to build).
   # But don't want to build the whole of libstdc++-v3 because
--- a/sources/sections/uClibc.build	Fri May 21 22:25:10 2010 -0500
+++ b/sources/sections/uClibc.build	Fri May 21 22:26:25 2010 -0500
@@ -2,9 +2,9 @@
 
 make_uClibc()
 {
- make -j $CPUS $VERBOSITY CROSS="${ARCH}-" \
-  UCLIBC_LDSO_NAME=ld-uClibc KERNEL_HEADERS="$STAGE_DIR/include" \
-  PREFIX="$STAGE_DIR/" RUNTIME_PREFIX=/ DEVEL_PREFIX=/ $1
+  make -j $CPUS $VERBOSITY CROSS="${ARCH}-" \
+    UCLIBC_LDSO_NAME=ld-uClibc KERNEL_HEADERS="$STAGE_DIR/include" \
+    PREFIX="$STAGE_DIR/" RUNTIME_PREFIX=/ DEVEL_PREFIX=/ $1
 }
 
 # Configure
@@ -27,27 +27,16 @@
 cp .config "$STAGE_DIR/src/config-uClibc" &&
 make_uClibc install || dienow
 
-# Do we need host or target versions of ldd and such?
+# Build ldd and friends
 
-if [ ! -z "$HOST_UTILS" ]
+if [ ! -z "$HOST_ARCH" ]
 then
-  make_uClibc hostutils || dienow
+  # The uClibc utils/Makefile.in is crazy.  There's no way to specify a prefix,
+  # or to pass in --static via CFLAGS.  Just build 'em by hand.
 
-  for i in $(cd utils; ls *.host | sed 's/\.host//')
-  do
-    cp utils/"$i".host "$STAGE_DIR/bin/$ARCH-$i" || dienow
-  done
-else
-  make_uClibc install_utils || dienow
-
-  # There's no way to specify a prefix for the uClibc utils; rename by hand.
-
-  if [ ! -z "$PROGRAM_PREFIX" ]
-  then
-    mv "${STAGE_DIR}"/{sbin,bin}/ldconfig || dienow
-    for i in ldd readelf ldconfig
-    do
-      mv "$STAGE_DIR/bin/"{"$i","${PROGRAM_PREFIX}$i"}
-    done
-  fi
+  "$ARCH-cc" utils/ldd.c -o "$STAGE_DIR/bin/${PROGRAM_PREFIX}ldd" --static \
+    -I ldso/include -DBUILDING_LINKAGE &&
+  "$ARCH-cc" utils/ldconfig.c utils/chroot_realpath.c \
+    -o "$STAGE_DIR/bin/${PROGRAM_PREFIX}ldconfig" --static -I ldso/include \
+    -DUCLIBC_RUNTIME_PREFIX='"/"' -DBUILDING_LINKAGE || dienow
 fi