changeset 363:80f520811ed6

Teach cross-compiler.sh how to produce static binaries when BUILD_STATIC=1
author Rob Landley <rob@landley.net>
date Thu, 10 Jul 2008 09:21:41 -0500
parents 06f29c81ac8e
children a9dfcdc8de35
files cross-compiler.sh include.sh
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cross-compiler.sh	Thu Jul 10 03:13:23 2008 -0500
+++ b/cross-compiler.sh	Thu Jul 10 09:21:41 2008 -0500
@@ -10,6 +10,8 @@
 # Orange
 echo -e "\e[33m"
 
+[ -z "$BUILD_STATIC" ] || STATIC_FLAGS='--static'
+
 # Build and install binutils
 
 setupfor binutils build-binutils &&
@@ -18,7 +20,7 @@
 	--disable-shared --disable-multilib --program-prefix="${ARCH}-" \
 	$BINUTILS_FLAGS &&
 make -j $CPUS configure-host &&
-make -j $CPUS &&
+make -j $CPUS CFLAGS="-O2 $STATIC_FLAGS" &&
 make -j $CPUS install &&
 cd .. &&
 mkdir -p "${CROSS}/include" &&
@@ -33,7 +35,7 @@
 	--prefix="${CROSS}" --host=${CROSS_HOST} --target=${CROSS_TARGET} \
 	--enable-languages=c --disable-threads --disable-multilib \
 	--disable-nls --disable-shared --program-prefix="${ARCH}-" &&
-make -j $CPUS all-gcc &&
+make -j $CPUS all-gcc LDFLAGS="$STATIC_FLAGS" &&
 make -j $CPUS install-gcc &&
 cd .. &&
 
@@ -49,13 +51,13 @@
 mv "${CROSS}"/lib/gcc/*/* "${CROSS}"/gcc/lib &&
 ln -s ${CROSS_TARGET} ${CROSS}/tools &&
 ln -sf ../../../../tools/bin/ld  ${CROSS}/libexec/gcc/*/*/collect2 &&
-rm -rf "${CROSS}"/{lib/gcc,gcc/lib/install-tools} &&
+rm -rf "${CROSS}"/{lib/gcc,{libexec/gcc,gcc/lib}/install-tools} &&
 
 # Build and install gcc wrapper script.
 
 cd "${CROSS}"/bin &&
 mv "${ARCH}-gcc" gcc-unwrapped &&
-$CC -Os -s "${SOURCES}"/toys/gcc-uClibc.c -o "${ARCH}-gcc"
+$CC $STATIC_FLAGS -Os -s "${SOURCES}"/toys/gcc-uClibc.c -o "${ARCH}-gcc"
 EOF
 
 # Run toolchain fixup and cleanup
@@ -88,6 +90,8 @@
 
 if [ -e /usr/include ]
 then
+  # Build $ARCH-readelf and $ARCH-ldd
+
   # "make utils" in uClibc is broken for cross compiling.  Either it creates a
   # target binary (which you can't run on the host), or it tries to link the
   # host binary against the target library, and use the target compiler flags
@@ -95,13 +99,17 @@
   # is to bypass the broken build entirely, and do it by hand.
   make CROSS= allnoconfig &&
   make CROSS= headers KERNEL_HEADERS=/usr/include &&
-  $CC -Os -s -I include utils/readelf.c -o "${CROSS}/bin/${ARCH}-readelf" &&
-  $CC -Os -s -I ldso/include utils/ldd.c -o "${CROSS}/bin/${ARCH}-ldd" &&
+  $CC $STATIC_FLAGS -Os -s -I include utils/readelf.c \
+      -o "${CROSS}/bin/${ARCH}-readelf" &&
+  $CC $STATIC_FLAGS -Os -s -I ldso/include utils/ldd.c \
+      -o "${CROSS}/bin/${ARCH}-ldd" &&
   make CROSS= distclean
 
   [ $? -ne 0 ] && dienow
 fi
 
+# Build and install the uClibc libraries.
+
 make CROSS= allnoconfig KCONFIG_ALLCONFIG="${WORK}"/miniconfig-uClibc &&
 # Can't use -j here, build is unstable.
 make CROSS="${ARCH}-" KERNEL_HEADERS="${CROSS}/include" PREFIX="${CROSS}/" \
--- a/include.sh	Thu Jul 10 03:13:23 2008 -0500
+++ b/include.sh	Thu Jul 10 09:21:41 2008 -0500
@@ -13,6 +13,10 @@
 
 # export RECORD_COMMANDS=1
 
+# If this is set, the cross-compiler stage is compiled with --static.
+
+# export BUILD_STATIC=1
+
 # What host compiler should we use?
 
 [ -z "$CC" ] && CC=gcc