PATCH: --with-build-sysroot, et. al.

Mark Mitchell mark@codesourcery.com
Sun Jul 24 19:40:00 GMT 2005


[DJ, search for "DJ" below for an RFA.]
 
This patch has several components, but they are all in service of one
problem.  In particular, when building a cross-compiler, you often
want to build the compiler to be installed on the end-user's system in
one place (which I'll call $installdir), but, on *your* system, you
want to build and install in another place (which I'll call $builddir).
The usual way to do this is to configure with "--prefix=$installdir"
-- but then do "make install prefix=$builddir" on your system.

Life gets a little complicated when you're also building libraries
whose sysroot lives within the installation prefix.  Then, you want to
add "--sysroot=$installdir/something" so that all the relocatable
sysroot stuff works correctly.  However, when you're building the
compiler, things fall over, because (for example) fixincludes then
wants to check that $installdir/something/usr/include exists -- and it
doesn't, because the headers are in $builddir/something/usr/include
instead. 

This patch does several things to fix this problem:

1. There is now a --sysroot option to GCC.  This is a superset of
   -isysroot; it also passes --sysroot on to the linker, if the linker
   supports that option.  This is the key part of the patch; by
   passing --sysroot to the compiler you can explicitly tell it where
   to find the libraries and headers.

   While working on this, I documented -isysroot as well. 

2. I added a --with-build-sysroot option that causes the Makefiles to
   automatically pass --sysroot option in {C,CXX}FLAGS_FOR_TARGET, and
   to set SYSTEM_HEADER_DIR appropriately.  (Though it does *not* set
   CROSS_SYTEM_HEADER_DIR, because that is a propertly of the
   $installdir, not the $buildir.)  Dan Jacobowitz noticed that 
   gcc/Makefile.in is not using CFLAGS_FOR_TARGET when building libgcc
   and crtstuff; that's fixed as well.

3. gcc/Makefile.in should not complain about a missing include
   directory when -Dinhibit_libc is in use; that tells us that we are
   supposed to be building without headers.  This part of the patch is
   not addressing the core problem, but it's a bug I ran into while
   experimenting with this stuff.

I'm planning on checking in (1), (3), and the gcc parts of (2) after
allowing 24 hours for objections.  DJ, I'll not check in the toplevel
parts of (2) without your approval.

Dan Jacobowitz deserves credit for some of the ideas in this patch,
though none of the blame, as I wrote all the code.  Joseph Myers and
Richard Sandiford also made useful suggestions.

Tested on x86_64-unknown-linux-gnu (as an ordinary build), and in some
CodeSourcery-specific configurations that use --with-build-sysroot.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-07-24  Mark Mitchell  <mark@codesourcery.com>

	* Makefile.tpl (SYSROOT_CFLAGS_FOR_TARGET): New variable.
	(CFLAGS_FOR_TARGET): Use it.
	(CXXFLAGS_FOR_TARGET): Likewise.
	* Makefile.in: Regenerated.
	* configure.in (--with-build-sysroot): New option.
	* configure: Regenerated.

2005-07-24  Mark Mitchell  <mark@codesourcery.com>

	* gcc.c (option_map): Add --sysroot.
	(process_command): Handle --sysroot.
	(display_help): Document it.
	* doc/cppopts.tex (-isysroot): Document.
	* doc/invoke.texi (--sysroot): Document.

	* Makefile.in (inhibit_libc): New variable.
	(INHIBIT_LIBC_CFLAGS): Likewise.
	(LIBGCC2_CFLAGS): Include
	$(INHIBIT_LIBC_CFLAGS).
	(CRTSTUFF_CFLAGS): Include $(INHIBIT_LIBC_CFLAGS).
	($(T)crtbegin.o): Do not use @inhibit_libc@.
	($(T)crtend.o): Likewise.
	($(T)crtbeginS.o): Do not use @inhibit_libc@.
	($(T)crtendS.o): Likewise.
	($(T)crtbeginT.o): Do not use @inhibit_libc@.
	($(T)crtendT.o): Likewise.
	(stmp-fixinc): Do not complain about missing headers if
	inhibit_libc.
	* configure.ac (inhibit_libc): Set it to true/false.
	(--with-build-sysroot): New option.  Use it to set
	SYSTEM_HEADER_DIR. 
	* configure: Regenerated.

Index: Makefile.tpl
===================================================================
RCS file: /cvs/gcc/gcc/Makefile.tpl,v
retrieving revision 1.136
diff -c -5 -p -r1.136 Makefile.tpl
*** Makefile.tpl	16 Jul 2005 02:30:51 -0000	1.136
--- Makefile.tpl	24 Jul 2005 19:08:49 -0000
*************** USUAL_AS_FOR_TARGET = ` \
*** 363,377 ****
        echo $(CONFIGURED_AS_FOR_TARGET) ; \
      fi; \
    fi`
  
  CC_FOR_TARGET = @CC_FOR_TARGET@
  # During gcc bootstrap, if we use some random cc for stage1 then
  # CFLAGS will be just -g.  We want to ensure that TARGET libraries
  # (which we know are built with gcc) are built with optimizations so
  # prepend -O2 when setting CFLAGS_FOR_TARGET.
! CFLAGS_FOR_TARGET = -O2 $(CFLAGS)
  # If GCC_FOR_TARGET is not overriden on the command line, then this
  # variable is passed down to the gcc Makefile, where it is used to
  # build libgcc2.a.  We define it here so that it can itself be
  # overridden on the command line.
  GCC_FOR_TARGET=@GCC_FOR_TARGET@
--- 363,378 ----
        echo $(CONFIGURED_AS_FOR_TARGET) ; \
      fi; \
    fi`
  
  CC_FOR_TARGET = @CC_FOR_TARGET@
+ SYSROOT_CFLAGS_FOR_TARGET = @SYSROOT_CFLAGS_FOR_TARGET@
  # During gcc bootstrap, if we use some random cc for stage1 then
  # CFLAGS will be just -g.  We want to ensure that TARGET libraries
  # (which we know are built with gcc) are built with optimizations so
  # prepend -O2 when setting CFLAGS_FOR_TARGET.
! CFLAGS_FOR_TARGET = -O2 $(CFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
  # If GCC_FOR_TARGET is not overriden on the command line, then this
  # variable is passed down to the gcc Makefile, where it is used to
  # build libgcc2.a.  We define it here so that it can itself be
  # overridden on the command line.
  GCC_FOR_TARGET=@GCC_FOR_TARGET@
*************** LIBCFLAGS_FOR_TARGET = $(CFLAGS_FOR_TARG
*** 381,391 ****
  
  CXX_FOR_TARGET = @CXX_FOR_TARGET@
  RAW_CXX_FOR_TARGET = @RAW_CXX_FOR_TARGET@
  CXX_FOR_TARGET_FOR_RECURSIVE_MAKE = @CXX_FOR_TARGET_FOR_RECURSIVE_MAKE@
  RAW_CXX_FOR_TARGET_FOR_RECURSIVE_MAKE = @RAW_CXX_FOR_TARGET_FOR_RECURSIVE_MAKE@
! CXXFLAGS_FOR_TARGET = $(CXXFLAGS)
  LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
  
  DLLTOOL_FOR_TARGET=@DLLTOOL_FOR_TARGET@
  CONFIGURED_DLLTOOL_FOR_TARGET=@CONFIGURED_DLLTOOL_FOR_TARGET@
  USUAL_DLLTOOL_FOR_TARGET = ` \
--- 382,392 ----
  
  CXX_FOR_TARGET = @CXX_FOR_TARGET@
  RAW_CXX_FOR_TARGET = @RAW_CXX_FOR_TARGET@
  CXX_FOR_TARGET_FOR_RECURSIVE_MAKE = @CXX_FOR_TARGET_FOR_RECURSIVE_MAKE@
  RAW_CXX_FOR_TARGET_FOR_RECURSIVE_MAKE = @RAW_CXX_FOR_TARGET_FOR_RECURSIVE_MAKE@
! CXXFLAGS_FOR_TARGET = $(CXXFLAGS) $(SYSROOT_CFLAGS_FOR_TARGET)
  LIBCXXFLAGS_FOR_TARGET = $(CXXFLAGS_FOR_TARGET) -fno-implicit-templates
  
  DLLTOOL_FOR_TARGET=@DLLTOOL_FOR_TARGET@
  CONFIGURED_DLLTOOL_FOR_TARGET=@CONFIGURED_DLLTOOL_FOR_TARGET@
  USUAL_DLLTOOL_FOR_TARGET = ` \
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/configure.in,v
retrieving revision 1.360
diff -c -5 -p -r1.360 configure.in
*** configure.in	16 Jul 2005 02:30:52 -0000	1.360
--- configure.in	24 Jul 2005 19:08:50 -0000
*************** case "$host" in
*** 1403,1412 ****
--- 1403,1421 ----
      enable_gdbtk=no ;;
  esac
  
  copy_dirs=
  
+ AC_ARG_WITH([build-sysroot], 
+   [  --with-build-sysroot=sysroot
+                           use sysroot as the system root during the build],
+   [if test x"$withval" != x ; then
+      SYSROOT_CFLAGS_FOR_TARGET="--sysroot=$withval"
+    fi],
+   [SYSROOT_CFLAGS_FOR_TARGET=])
+ AC_SUBST(SYSROOT_CFLAGS_FOR_TARGET)
+ 
  # Handle --with-headers=XXX.  If the value is not "yes", the contents of
  # the named directory are copied to $(tooldir)/sys-include.
  if test x"${with_headers}" != x && test x"${with_headers}" != xno ; then
    if test x${is_cross_compiler} = xno ; then
      echo 1>&2 '***' --with-headers is only supported when cross compiling
Index: gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1526
diff -c -5 -p -r1.1526 Makefile.in
*** gcc/Makefile.in	21 Jul 2005 07:24:01 -0000	1.1526
--- gcc/Makefile.in	24 Jul 2005 19:08:50 -0000
*************** UNWIND_H = $(srcdir)/unwind-generic.h
*** 323,333 ****
  GCC_FOR_TARGET = $(STAGE_CC_WRAPPER) ./xgcc -B./ -B$(build_tooldir)/bin/ -isystem $(build_tooldir)/include -isystem $(build_tooldir)/sys-include -L$(objdir)/../ld
  
  # This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET.
  # It omits XCFLAGS, and specifies -B./.
  # It also specifies -isystem ./include to find, e.g., stddef.h.
! GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(LOOSE_WARN) -Wold-style-definition $($@-warn) -isystem ./include $(TCFLAGS)
  
  # ---------------------------------------------------
  # Programs which produce files for the target machine
  # ---------------------------------------------------
  
--- 323,333 ----
  GCC_FOR_TARGET = $(STAGE_CC_WRAPPER) ./xgcc -B./ -B$(build_tooldir)/bin/ -isystem $(build_tooldir)/include -isystem $(build_tooldir)/sys-include -L$(objdir)/../ld
  
  # This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET.
  # It omits XCFLAGS, and specifies -B./.
  # It also specifies -isystem ./include to find, e.g., stddef.h.
! GCC_CFLAGS=$(CFLAGS_FOR_TARGET) $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(LOOSE_WARN) -Wold-style-definition $($@-warn) -isystem ./include $(TCFLAGS)
  
  # ---------------------------------------------------
  # Programs which produce files for the target machine
  # ---------------------------------------------------
  
*************** GGC_LIB=
*** 509,524 ****
  # libgcc.a may be built directly or via stmp-multilib,
  # and installed likewise.  Overridden by t-fragment.
  LIBGCC = libgcc.a
  INSTALL_LIBGCC = install-libgcc
  
  # Options to use when compiling libgcc2.a.
  #
  LIBGCC2_DEBUG_CFLAGS = -g
  LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) \
  		 $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) \
! 		 -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED @inhibit_libc@
  
  # Additional options to use when compiling libgcc2.a.
  # Some targets override this to -isystem include
  LIBGCC2_INCLUDES =
  
--- 509,532 ----
  # libgcc.a may be built directly or via stmp-multilib,
  # and installed likewise.  Overridden by t-fragment.
  LIBGCC = libgcc.a
  INSTALL_LIBGCC = install-libgcc
  
+ # "true" if the target C library headers are unavailable; "false"
+ # otherwise.
+ inhibit_libc = @inhibit_libc@
+ ifeq ($(inhibit_libc),true)
+ INHIBIT_LIBC_CFLAGS = -Dinhibit_libc
+ endif
+ 
  # Options to use when compiling libgcc2.a.
  #
  LIBGCC2_DEBUG_CFLAGS = -g
  LIBGCC2_CFLAGS = -O2 $(LIBGCC2_INCLUDES) $(GCC_CFLAGS) $(TARGET_LIBGCC2_CFLAGS) \
  		 $(LIBGCC2_DEBUG_CFLAGS) $(GTHREAD_FLAGS) \
! 		 -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
! 		 $(INHIBIT_LIBC_CFLAGS)
  
  # Additional options to use when compiling libgcc2.a.
  # Some targets override this to -isystem include
  LIBGCC2_INCLUDES =
  
*************** LIBGCC2_INCLUDES =
*** 526,536 ****
  TARGET_LIBGCC2_CFLAGS =
  
  # Options to use when compiling crtbegin/end.
  CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
    -finhibit-size-directive -fno-inline-functions -fno-exceptions \
!   -fno-zero-initialized-in-bss -fno-unit-at-a-time
  
  # Additional sources to handle exceptions; overridden by targets as needed.
  LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde.c \
     $(srcdir)/unwind-sjlj.c $(srcdir)/gthr-gnat.c $(srcdir)/unwind-c.c
  LIB2ADDEHSTATIC = $(LIB2ADDEH)
--- 534,545 ----
  TARGET_LIBGCC2_CFLAGS =
  
  # Options to use when compiling crtbegin/end.
  CRTSTUFF_CFLAGS = -O2 $(GCC_CFLAGS) $(INCLUDES) $(MULTILIB_CFLAGS) -g0 \
    -finhibit-size-directive -fno-inline-functions -fno-exceptions \
!   -fno-zero-initialized-in-bss -fno-unit-at-a-time \
!   $(INHIBIT_LIBC_CFLAGS)
  
  # Additional sources to handle exceptions; overridden by targets as needed.
  LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/unwind-dw2-fde.c \
     $(srcdir)/unwind-sjlj.c $(srcdir)/gthr-gnat.c $(srcdir)/unwind-c.c
  LIB2ADDEHSTATIC = $(LIB2ADDEH)
*************** stmp-multilib: $(LIBGCC_DEPS)
*** 1391,1427 ****
  # linked using GCC on systems using COFF or ELF, for the sake of C++
  # constructors.
  $(T)crtbegin.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  @inhibit_libc@ -c $(srcdir)/crtstuff.c -DCRT_BEGIN \
  	  -o $(T)crtbegin$(objext)
  
  $(T)crtend.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  @inhibit_libc@ -c $(srcdir)/crtstuff.c -DCRT_END \
  	  -o $(T)crtend$(objext)
  
  # These are versions of crtbegin and crtend for shared libraries.
  $(T)crtbeginS.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS_S) \
! 	  @inhibit_libc@ -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFS_O \
  	  -o $(T)crtbeginS$(objext)
  
  $(T)crtendS.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS_S) \
! 	  @inhibit_libc@ -c $(srcdir)/crtstuff.c -DCRT_END -DCRTSTUFFS_O \
  	  -o $(T)crtendS$(objext)
  
  # This is a version of crtbegin for -static links.
  $(T)crtbeginT.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  @inhibit_libc@ -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O \
  	  -o $(T)crtbeginT$(objext)
  
  # Compile the start modules crt0.o and mcrt0.o that are linked with
  # every program
  crt0.o: s-crt0 ; @true
--- 1400,1436 ----
  # linked using GCC on systems using COFF or ELF, for the sake of C++
  # constructors.
  $(T)crtbegin.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN \
  	  -o $(T)crtbegin$(objext)
  
  $(T)crtend.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  -c $(srcdir)/crtstuff.c -DCRT_END \
  	  -o $(T)crtend$(objext)
  
  # These are versions of crtbegin and crtend for shared libraries.
  $(T)crtbeginS.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS_S) \
! 	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFS_O \
  	  -o $(T)crtbeginS$(objext)
  
  $(T)crtendS.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS_S) \
! 	  -c $(srcdir)/crtstuff.c -DCRT_END -DCRTSTUFFS_O \
  	  -o $(T)crtendS$(objext)
  
  # This is a version of crtbegin for -static links.
  $(T)crtbeginT.o: crtstuff.c $(GCC_PASSES) $(TCONFIG_H) auto-host.h \
    gbl-ctors.h stmp-int-hdrs tsystem.h coretypes.h $(TM_H)
  	$(GCC_FOR_TARGET) $(CRTSTUFF_CFLAGS) $(CRTSTUFF_T_CFLAGS) \
! 	  -c $(srcdir)/crtstuff.c -DCRT_BEGIN -DCRTSTUFFT_O \
  	  -o $(T)crtbeginT$(objext)
  
  # Compile the start modules crt0.o and mcrt0.o that are linked with
  # every program
  crt0.o: s-crt0 ; @true
*************** s-macro_list : $(GCC_PASSES) 
*** 3135,3145 ****
  
  # Build fixed copies of system files.
  stmp-fixinc: gsyslimits.h macro_list \
    $(build_objdir)/fixincludes/fixincl \
    $(build_objdir)/fixincludes/fixinc.sh
! 	@if test ! -d ${SYSTEM_HEADER_DIR}; then \
  	  echo The directory that should contain system headers does not exist: >&2 ; \
  	  echo "  ${SYSTEM_HEADER_DIR}" >&2 ; \
  	  if test "x${SYSTEM_HEADER_DIR}" = "x${gcc_tooldir}/sys-include"; \
  	  then sleep 1; else exit 1; fi; \
  	fi
--- 3144,3154 ----
  
  # Build fixed copies of system files.
  stmp-fixinc: gsyslimits.h macro_list \
    $(build_objdir)/fixincludes/fixincl \
    $(build_objdir)/fixincludes/fixinc.sh
! 	@if ! $(inhibit_libc) && test ! -d ${SYSTEM_HEADER_DIR}; then \
  	  echo The directory that should contain system headers does not exist: >&2 ; \
  	  echo "  ${SYSTEM_HEADER_DIR}" >&2 ; \
  	  if test "x${SYSTEM_HEADER_DIR}" = "x${gcc_tooldir}/sys-include"; \
  	  then sleep 1; else exit 1; fi; \
  	fi
Index: gcc/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.ac,v
retrieving revision 2.122
diff -c -5 -p -r2.122 configure.ac
*** gcc/configure.ac	8 Jul 2005 05:50:44 -0000	2.122
--- gcc/configure.ac	24 Jul 2005 19:08:50 -0000
*************** AC_ARG_ENABLE(shared,
*** 663,683 ****
      ;;
    esac
  ], [enable_shared=yes])
  AC_SUBST(enable_shared)
  
  AC_ARG_WITH(sysroot,
  [  --with-sysroot[=DIR] Search for usr/lib, usr/include, et al, within DIR.],
  [
   case ${with_sysroot} in
   yes) TARGET_SYSTEM_ROOT='${exec_prefix}/${target_noncanonical}/sys-root' ;;
   *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
   esac
     
   TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
   CROSS_SYSTEM_HEADER_DIR='$(TARGET_SYSTEM_ROOT)$(NATIVE_SYSTEM_HEADER_DIR)'
! 
   if test "x$exec_prefix" = xNONE; then
    if test "x$prefix" = xNONE; then
     test_prefix=/usr/local
    else
     test_prefix=$prefix
--- 663,692 ----
      ;;
    esac
  ], [enable_shared=yes])
  AC_SUBST(enable_shared)
  
+ AC_ARG_WITH(build-sysroot, 
+   [  --with-build-sysroot=sysroot
+                           use sysroot as the system root during the build])
+ 
  AC_ARG_WITH(sysroot,
  [  --with-sysroot[=DIR] Search for usr/lib, usr/include, et al, within DIR.],
  [
   case ${with_sysroot} in
   yes) TARGET_SYSTEM_ROOT='${exec_prefix}/${target_noncanonical}/sys-root' ;;
   *) TARGET_SYSTEM_ROOT=$with_sysroot ;;
   esac
     
   TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"'
   CROSS_SYSTEM_HEADER_DIR='$(TARGET_SYSTEM_ROOT)$(NATIVE_SYSTEM_HEADER_DIR)'
!  if test "x$with_build_sysroot" != x; then
!    build_system_header_dir=$with_build_sysroot'$(NATIVE_SYSTEM_HEADER_DIR)'
!  else
!    build_system_header_dir='$(CROSS_SYSTEM_HEADER_DIR)'
!  fi
!  
   if test "x$exec_prefix" = xNONE; then
    if test "x$prefix" = xNONE; then
     test_prefix=/usr/local
    else
     test_prefix=$prefix
*************** ALL=all.internal				AC_SUBST(ALL)
*** 1625,1635 ****
  SYSTEM_HEADER_DIR='$(NATIVE_SYSTEM_HEADER_DIR)'	AC_SUBST(SYSTEM_HEADER_DIR)
  if test x$host != x$target
  then
  	CROSS="-DCROSS_COMPILE"
  	ALL=all.cross
! 	SYSTEM_HEADER_DIR='$(CROSS_SYSTEM_HEADER_DIR)'
  	case "$host","$target" in
  	# Darwin crosses can use the host system's libraries and headers,
  	# because of the fat library support.  Of course, it must be the
  	# same version of Darwin on both sides.  Allow the user to
  	# just say --target=foo-darwin without a version number to mean
--- 1634,1644 ----
  SYSTEM_HEADER_DIR='$(NATIVE_SYSTEM_HEADER_DIR)'	AC_SUBST(SYSTEM_HEADER_DIR)
  if test x$host != x$target
  then
  	CROSS="-DCROSS_COMPILE"
  	ALL=all.cross
! 	SYSTEM_HEADER_DIR=$build_system_header_dir
  	case "$host","$target" in
  	# Darwin crosses can use the host system's libraries and headers,
  	# because of the fat library support.  Of course, it must be the
  	# same version of Darwin on both sides.  Allow the user to
  	# just say --target=foo-darwin without a version number to mean
*************** fi
*** 1659,1673 ****
  
  # If this is using newlib, without having the headers available now,
  # then define inhibit_libc in LIBGCC2_CFLAGS.
  # This prevents libgcc2 from containing any code which requires libc
  # support.
! inhibit_libc=
  if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
         test x$with_newlib = xyes ; } &&
       { test "x$with_headers" = x || test "x$with_headers" = xno ; } ; then
!        inhibit_libc=-Dinhibit_libc
  fi
  AC_SUBST(inhibit_libc)
  
  # When building gcc with a cross-compiler, we need to adjust things so
  # that the generator programs are still built with the native compiler.
--- 1668,1682 ----
  
  # If this is using newlib, without having the headers available now,
  # then define inhibit_libc in LIBGCC2_CFLAGS.
  # This prevents libgcc2 from containing any code which requires libc
  # support.
! inhibit_libc=false
  if { { test x$host != x$target && test "x$with_sysroot" = x ; } ||
         test x$with_newlib = xyes ; } &&
       { test "x$with_headers" = x || test "x$with_headers" = xno ; } ; then
!        inhibit_libc=true
  fi
  AC_SUBST(inhibit_libc)
  
  # When building gcc with a cross-compiler, we need to adjust things so
  # that the generator programs are still built with the native compiler.
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.467
diff -c -5 -p -r1.467 gcc.c
*** gcc/gcc.c	17 Jul 2005 02:28:56 -0000	1.467
--- gcc/gcc.c	24 Jul 2005 19:08:50 -0000
*************** static const struct option_map option_ma
*** 1118,1127 ****
--- 1118,1128 ----
     {"--silent", "-q", 0},
     {"--specs", "-specs=", "aj"},
     {"--static", "-static", 0},
     {"--std", "-std=", "aj"},
     {"--symbolic", "-symbolic", 0},
+    {"--sysroot", "--sysroot=", "aj"}, 
     {"--time", "-time", 0},
     {"--trace-includes", "-H", 0},
     {"--traditional", "-traditional", 0},
     {"--traditional-cpp", "-traditional-cpp", 0},
     {"--trigraphs", "-trigraphs", 0},
*************** display_help (void)
*** 3062,3071 ****
--- 3063,3075 ----
    fputs (_("  -save-temps              Do not delete intermediate files\n"), stdout);
    fputs (_("  -pipe                    Use pipes rather than intermediate files\n"), stdout);
    fputs (_("  -time                    Time the execution of each subprocess\n"), stdout);
    fputs (_("  -specs=<file>            Override built-in specs with the contents of <file>\n"), stdout);
    fputs (_("  -std=<standard>          Assume that the input sources are for <standard>\n"), stdout);
+   fputs (_("\
+   --sysroot=<directory>    Use <directory> as the root directory for headers\n\
+                            for headers and libraries\n"), stdout);
    fputs (_("  -B <directory>           Add <directory> to the compiler's search paths\n"), stdout);
    fputs (_("  -b <machine>             Run gcc for target <machine>, if installed\n"), stdout);
    fputs (_("  -V <version>             Run gcc version number <version>, if installed\n"), stdout);
    fputs (_("  -v                       Display the programs invoked by the compiler\n"), stdout);
    fputs (_("  -###                     Like -v but options quoted and commands not executed\n"), stdout);
*************** warranty; not even for MERCHANTABILITY o
*** 3924,3933 ****
--- 3928,3942 ----
  	;
        else if (! strcmp (argv[i], "-ftarget-help"))
  	;
        else if (! strcmp (argv[i], "-fhelp"))
  	;
+       else if (! strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")))
+ 	{
+ 	  target_system_root = argv[i] + strlen ("--sysroot=");
+ 	  target_system_root_changed = 1;
+ 	}
        else if (argv[i][0] == '+' && argv[i][1] == 'e')
  	{
  	  /* Compensate for the +e options to the C++ front-end;
  	     they're there simply for cfront call-compatibility.  We do
  	     some magic in default_compilers to pass them down properly.
Index: gcc/doc/cppopts.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cppopts.texi,v
retrieving revision 1.41
diff -c -5 -p -r1.41 cppopts.texi
*** gcc/doc/cppopts.texi	18 Mar 2005 15:24:28 -0000	1.41
--- gcc/doc/cppopts.texi	24 Jul 2005 19:08:50 -0000
*************** final @samp{/}.
*** 476,485 ****
--- 476,490 ----
  Append @var{dir} to the prefix specified previously with
  @option{-iprefix}, and add the resulting directory to the include search
  path.  @option{-iwithprefixbefore} puts it in the same place @option{-I}
  would; @option{-iwithprefix} puts it where @option{-idirafter} would.
  
+ @item -isysroot @var{dir}
+ @opindex isysroot
+ This option is like the @option{--sysroot} option, but applies only to
+ header files.  See the @option{--sysroot} option for more information.
+ 
  @item -isystem @var{dir}
  @opindex isystem
  Search @var{dir} for header files, after all directories specified by
  @option{-I} but before the standard system directories.  Mark it
  as a system directory, so that it gets the same special treatment as
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.653
diff -c -5 -p -r1.653 invoke.texi
*** gcc/doc/invoke.texi	21 Jul 2005 07:24:14 -0000	1.653
--- gcc/doc/invoke.texi	24 Jul 2005 19:08:51 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 347,356 ****
--- 347,357 ----
  -D@var{macro}@r{[}=@var{defn}@r{]}  -E  -H @gol
  -idirafter @var{dir} @gol
  -include @var{file}  -imacros @var{file} @gol
  -iprefix @var{file}  -iwithprefix @var{dir} @gol
  -iwithprefixbefore @var{dir}  -isystem @var{dir} @gol
+ -isysroot @var{dir} @gol
  -M  -MM  -MF  -MG  -MP  -MQ  -MT  -nostdinc  @gol
  -P  -fworking-directory  -remap @gol
  -trigraphs  -undef  -U@var{macro}  -Wp,@var{option} @gol
  -Xpreprocessor @var{option}}
  
*************** Objective-C and Objective-C++ Dialects}.
*** 366,376 ****
  -Wl,@var{option}  -Xlinker @var{option} @gol
  -u @var{symbol}}
  
  @item Directory Options
  @xref{Directory Options,,Options for Directory Search}.
! @gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  -L@var{dir}  -specs=@var{file}  -I-}
  
  @item Target Options
  @c I wrote this xref this way to avoid overfull hbox. -- rms
  @xref{Target Options}.
  @gccoptlist{-V @var{version}  -b @var{machine}}
--- 367,378 ----
  -Wl,@var{option}  -Xlinker @var{option} @gol
  -u @var{symbol}}
  
  @item Directory Options
  @xref{Directory Options,,Options for Directory Search}.
! @gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  -L@var{dir}
! -specs=@var{file}  -I- --sysroot=@var{dir}}
  
  @item Target Options
  @c I wrote this xref this way to avoid overfull hbox. -- rms
  @xref{Target Options}.
  @gccoptlist{-V @var{version}  -b @var{machine}}
*************** file, in order to override the defaults 
*** 6370,6379 ****
--- 6372,6397 ----
  program uses when determining what switches to pass to @file{cc1},
  @file{cc1plus}, @file{as}, @file{ld}, etc.  More than one
  @option{-specs=@var{file}} can be specified on the command line, and they
  are processed in order, from left to right.
  
+ @item --sysroot=@var{dir}
+ @opindex sysroot
+ Use @var{dir} as the logical root directory for headers and libraries.
+ For example, if the compiler would normally search for headers in
+ @file{/usr/include} and libraries in @file{/usr/lib}, it will instead
+ search @file{@var{dir}/usr/include} and @file{@var{dir}/usr/lib}.  
+ 
+ If you use both this option and the @option{-isysroot} option, then
+ the @option{--sysroot} option will apply to libraries, but the
+ @option{-isysroot} option will apply to header files.
+ 
+ The GNU linker (beginning with version 2.16) has the necessary support
+ for this option.  If your linker does not support this option, the
+ header file aspect of @option{--sysroot} will still work, but the
+ library aspect will not.
+ 
  @item -I-
  @opindex I-
  This option has been deprecated.  Please use @option{-iquote} instead for
  @option{-I} directories before the @option{-I-} and remove the @option{-I-}.
  Any directories you specify with @option{-I} options before the @option{-I-}



More information about the Gcc-patches mailing list