[PATCH] Add --with-cross configure option to force -DCROSS_COMPILE behavior

Dan Kegel dkegel@ixiacom.com
Mon Jun 2 23:08:00 GMT 2003


When host != target, gcc's configure carefully avoids letting the
build environment leak into the generated toolchain.  This is good.
Unfortunately in the Linux From Scratch world, even though host = target,
we still need to avoid letting the build environment leak into the new toolchain.

(See http://archive.linuxfromscratch.org/mail-archives/lfs-support/2003/03/0269.html
for an example of a user running into trouble with this issue.
http://linuxfromscratch.org/~greg/pure_lfs.txt even recommends
patching gcc/Makefile.in to remove the call to fixinc.sh!)

I also had trouble with the current behavior when I was trying to
test a crossgcc build script.  (I only had x86's handy, but I wanted
the toolchain to be built with all the quirks of a cross-compiler,
and gcc's configure script wouldn't let me do it.)

Thus it would be handy to be able to build a cross compiler even though host = target.
Here is a small patch that adds a --with-cross option that does just that.
It's been lightly tested, in that configuring with --with-cross let me
build an x86 -> x86 cross-compiler, which I couldn't do before.
This is against gcc-3.3.  Comments welcome...
- Dan

2003-06-02  Dan Kegel  <dkegel at ixiacom.com>
	* configure.in: add --with-cross to force is_cross_compiler=yes
	* gcc/configure.in: add --with-cross to force is_cross_compiler=yes,
	  test is_cross_compiler instead of host =? target.

--- gcc-3.3/configure.in.old	Mon Jun  2 13:18:06 2003
+++ gcc-3.3/configure.in	Mon Jun  2 13:30:32 2003
@@ -103,9 +103,10 @@

  # per-target:

-# Define is_cross_compiler to save on calls to 'test'.
+# Define is_cross_compiler to let user force cross-compiler
+# with --with-cross even if host == target
  is_cross_compiler=
-if test x"${host}" = x"${target}" ; then
+if test x$with_cross != xyes && test x"${host}" = x"${target}" ; then
    is_cross_compiler=no
  else
    is_cross_compiler=yes
--- gcc-3.3/gcc/configure.in.old	Mon Jun  2 12:18:08 2003
+++ gcc-3.3/gcc/configure.in	Mon Jun  2 14:22:47 2003
@@ -125,6 +125,14 @@
  	[Define to enable the use of a default assembler.])
  fi

+AC_ARG_WITH(cross,
+[  --with-cross            build as if for a cross compiler even if host == target],
+[case "${withval}" in
+yes) 
is_cross_compiler=$withval ;;
+*) 
AC_MSG_ERROR(bad value ${withval} given for whether to build as if for a cross-compiler) ;;
+esac],
+is_cross_compiler=no)
+
  # With stabs
  AC_ARG_WITH(stabs,
  [  --with-stabs            arrange to use stabs instead of host debug format],
@@ -180,6 +188,10 @@
  # Determine the host, build, and target systems
  AC_CANONICAL_SYSTEM

+if test x$host != x$target; then
+  is_cross_compiler=yes
+fi
+
  # Set program_transform_name
  AC_ARG_PROGRAM

@@ -1186,7 +1198,7 @@
  CROSS=	 
				AC_SUBST(CROSS)
  ALL=all.internal	 
		AC_SUBST(ALL)
  SYSTEM_HEADER_DIR='$(NATIVE_SYSTEM_HEADER_DIR)'	AC_SUBST(SYSTEM_HEADER_DIR)
-if test x$host != x$target
+if test x$is_cross_compiler = xyes
  then
  	CROSS="-DCROSS_COMPILE"
  	ALL=all.cross
@@ -1206,7 +1218,7 @@
  # This prevents libgcc2 from containing any code which requires libc
  # support.
  inhibit_libc=
-if [test x$host != x$target] && [test x$with_headers = x]; then
+if [test x$is_cross_compiler = xyes] && [test x$with_headers = x]; then
         inhibit_libc=-Dinhibit_libc
  else
         if [test x$with_newlib = xyes]; then
@@ -1352,7 +1364,7 @@
  		   $test_prefix/$target_alias/bin/$target_alias/$gcc_version \
  		   $test_prefix/$target_alias/bin"

- 
if test x$host = x$target; then
+ 
if test x$is_cross_compiler = xno; then
  	    test_dirs="$test_dirs \
  		   /usr/libexec \
  		   /usr/ccs/gcc \
@@ -1448,7 +1460,7 @@
  		   $test_prefix/$target_alias/bin/$target_alias/$gcc_version \
  		   $test_prefix/$target_alias/bin"

- 
if test x$host = x$target; then
+ 
if test x$is_cross_compiler = xno; then
  	    test_dirs="$test_dirs \
  		   /usr/libexec \
  		   /usr/ccs/gcc \
@@ -2744,7 +2756,7 @@
  build_canonical=${build}
  host_canonical=${host}
  target_subdir=
-if test "${host}" != "${target}" ; then
+if test x$is_cross_compiler = xyes; then
      target_subdir=${target_alias}/
  fi
  AC_SUBST(build_canonical)
@@ -2802,7 +2814,7 @@
  slibdir="$with_slibdir",
  if test "${enable_version_specific_runtime_libs+set}" = set; then
    slibdir='$(libsubdir)'
-elif test "$host" != "$target"; then
+elif test x$is_cross_compiler = xyes; then
    slibdir='$(build_tooldir)/lib'
  else
    slibdir='$(libdir)'
@@ -2885,7 +2897,7 @@
  AC_SUBST_FILE(language_hooks)

  # Echo that links are built
-if test x$host = x$target
+if test x$is_cross_compiler = xno
  then
  	str1="native "
  else



More information about the Gcc-patches mailing list