public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Updates to --with-sysroot support
@ 2002-11-04  8:56 Daniel Jacobowitz
  2002-11-04  9:08 ` Jason R Thorpe
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-04  8:56 UTC (permalink / raw)
  To: gcc-patches; +Cc: Alexandre Oliva, Geoff Keating

I spent a couple days working with this and finally found a solution for
(most of) my concerns.  This patch:

 - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
   If -iprefix was used to change the compiler prefix, then first the
   standard include directories which begin with the prefix were searched
   (using the relocated prefix); then all directories were searched in order
   (using the original prefix).  This means that -iprefix'd versions of
   GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
   would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
   I changed this so that the order is preserved, and unrelocated versions
   are not searched.  This means that people who were using -iprefix and
   still expecting to get GCC's <stddef.h> et al. from the normal location
   are out of luck; they'll have to specify that path as an -isystem
   explicitly.  I think this change is correct but I'd like a second
   opinion.

 - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
   one's a little more arguable but I think it's appropriate.  The sysrooted
   compiler should work like a system compiler inside of $sysroot; searching
   $prefix/include defeats that.
   I need this in my local setups but I won't be heartbroken if it's
   considered wrong for the FSF tree :)

 - Searches prefixed versions of LOCAL_INCLUDE_DIR, SYSTEM_INCLUDE_DIR,
   and STANDARD_INCLUDE_DIR.

 - Relocates those prefixed directories by passing -isysroot to cc1 to
   override the normal prefix.

 - Fixes a bug in make_relative_path; it only worked if exec_prefix was the
   same as or inside of prefix, which generally worked for exec_prefix
   but won't now that we use this function for the sysroot too.

With this and some -rpath-link's, I can build a complete relocatable sysroot
compiler without having to specify the sysroot via $gcc_tooldir.  How's it
look?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-11-04  Daniel Jacobowitz  <drow@mvista.com>

	* Makefile.in (PREPROCESSOR_DEFINES): Add
	@TARGET_SYSTEM_ROOT_DEFINE@.
	* configure.in (PREFIX_INCLUDE_DIR): Don't define if $with_sysroot
	is specified.
	* configure: Regenerated.
	* cppdefault.h: Use native include paths if TARGET_SYSTEM_ROOT is
	defined.
	(struct default_include): Add add_sysroot field.
	(cpp_SYSROOT): Declare.
	* cppdefault.c (cpp_include_defaults): Fill in add_sysroot
	field.
	(cpp_SYSROOT): New variable.
	* cppinit.c (cpp_create_reader): Initialize
	CPP_OPTION (pfile, sysroot).
	(init_standard_includes): Handle add_sysroot.  Do not
	add unrelocated copies of relocated directories.
	(COMMAND_LINE_OPTIONS): Add -isysroot.
	(cpp_handle_option): Handle -isysroot.
	* cpplib.h (struct cpp_options): Add sysroot member.
	* gcc.c (The Specs Language): Update description of %I.
	(target_system_root_changed): New variable.
	(make_relative_prefix): Add DIR_UP components up to bin_num instead
	of n.
	(process_command): Set target_system_root_changed.
	(do_spec_1): Add -isysroot to %I.
	* doc/invoke.texi (Spec Files): Update description of %I.

Index: gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.939.2.12
diff -u -p -r1.939.2.12 Makefile.in
--- gcc/Makefile.in	28 Oct 2002 19:46:59 -0000	1.939.2.12
+++ gcc/Makefile.in	4 Nov 2002 16:14:27 -0000
@@ -2180,7 +2180,8 @@ PREPROCESSOR_DEFINES = \
   -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
   -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
-  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\"
+  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
+  @TARGET_SYSTEM_ROOT_DEFINE@
 
 LIBCPP_OBJS =	cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpptrad.o \
 		cpphash.o cpperror.o cppinit.o cppdefault.o cppmain.o \
Index: gcc/configure
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure,v
retrieving revision 1.630.4.5
diff -u -p -r1.630.4.5 configure
--- gcc/configure	28 Oct 2002 19:47:02 -0000	1.630.4.5
+++ gcc/configure	4 Nov 2002 16:14:33 -0000
@@ -8077,7 +8077,8 @@ EOF
     ;;
 esac
 
-if test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
+if test x$with_sysroot = x \
+   && test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
   cat >> confdefs.h <<EOF
 #define PREFIX_INCLUDE_DIR "$prefix/include"
 EOF
@@ -8252,7 +8253,7 @@ fi
 
 
 echo $ac_n "checking whether to enable maintainer-specific portions of Makefiles""... $ac_c" 1>&6
-echo "configure:8256: checking whether to enable maintainer-specific portions of Makefiles" >&5
+echo "configure:8257: checking whether to enable maintainer-specific portions of Makefiles" >&5
     # Check whether --enable-maintainer-mode or --disable-maintainer-mode was given.
 if test "${enable_maintainer_mode+set}" = set; then
   enableval="$enable_maintainer_mode"
Index: gcc/configure.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.in,v
retrieving revision 1.617.4.5
diff -u -p -r1.617.4.5 configure.in
--- gcc/configure.in	28 Oct 2002 19:47:05 -0000	1.617.4.5
+++ gcc/configure.in	4 Nov 2002 16:14:35 -0000
@@ -2267,7 +2267,8 @@ case "$target" in
     ;;
 esac
 
-if test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
+if test x$with_sysroot = x \
+   && test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
   AC_DEFINE_UNQUOTED(PREFIX_INCLUDE_DIR, "$prefix/include")
 fi
 
Index: gcc/cppdefault.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppdefault.c,v
retrieving revision 1.4
diff -u -p -r1.4 cppdefault.c
--- gcc/cppdefault.c	29 Sep 2001 18:22:02 -0000	1.4
+++ gcc/cppdefault.c	4 Nov 2002 16:14:35 -0000
@@ -33,44 +33,44 @@ const struct default_include cpp_include
 = {
 #ifdef GPLUSPLUS_INCLUDE_DIR
     /* Pick up GNU C++ generic include files.  */
-    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
     /* Pick up GNU C++ target-dependent include files.  */
-    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
     /* Pick up GNU C++ backward and deprecated include files.  */
-    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef LOCAL_INCLUDE_DIR
     /* /usr/local/include comes before the fixincluded header files.  */
-    { LOCAL_INCLUDE_DIR, 0, 0, 1 },
+    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
 #endif
 #ifdef PREFIX_INCLUDE_DIR
-    { PREFIX_INCLUDE_DIR, 0, 0, 1 },
+    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0 },
 #endif
 #ifdef GCC_INCLUDE_DIR
     /* This is the dir for fixincludes and for gcc's private headers.  */
-    { GCC_INCLUDE_DIR, "GCC", 0, 0 },
+    { GCC_INCLUDE_DIR, "GCC", 0, 0, 0 },
 #endif
 #ifdef CROSS_INCLUDE_DIR
     /* One place the target system's headers might be.  */
-    { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
+    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0 },
 #endif
 #ifdef TOOL_INCLUDE_DIR
     /* Another place the target system's headers might be.  */
-    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
+    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0 },
 #endif
 #ifdef SYSTEM_INCLUDE_DIR
     /* Some systems have an extra dir of include files.  */
-    { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
+    { SYSTEM_INCLUDE_DIR, 0, 0, 0, 1 },
 #endif
 #ifdef STANDARD_INCLUDE_DIR
     /* /usr/include comes dead last.  */
-    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
+    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
 #endif
-    { 0, 0, 0, 0 }
+    { 0, 0, 0, 0, 0 }
   };
 #endif /* no INCLUDE_DEFAULTS */
 
@@ -80,4 +80,10 @@ const size_t cpp_GCC_INCLUDE_DIR_len = s
 #else
 const char cpp_GCC_INCLUDE_DIR[] = "";
 const size_t cpp_GCC_INCLUDE_DIR_len = 0;
+#endif
+
+#ifdef TARGET_SYSTEM_ROOT
+const char *cpp_SYSROOT = TARGET_SYSTEM_ROOT;
+#else
+const char *cpp_SYSROOT = "";
 #endif
Index: gcc/cppdefault.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppdefault.h,v
retrieving revision 1.6
diff -u -p -r1.6 cppdefault.h
--- gcc/cppdefault.h	16 May 2002 19:02:59 -0000	1.6
+++ gcc/cppdefault.h	4 Nov 2002 16:14:35 -0000
@@ -34,12 +34,12 @@ Foundation, 59 Temple Place - Suite 330,
 #define STANDARD_INCLUDE_COMPONENT 0
 #endif
 
-#ifdef CROSS_COMPILE
-#undef LOCAL_INCLUDE_DIR
-#undef SYSTEM_INCLUDE_DIR
-#undef STANDARD_INCLUDE_DIR
+#if defined (CROSS_COMPILE) && !defined (TARGET_SYSTEM_ROOT)
+# undef LOCAL_INCLUDE_DIR
+# undef SYSTEM_INCLUDE_DIR
+# undef STANDARD_INCLUDE_DIR
 #else
-#undef CROSS_INCLUDE_DIR
+# undef CROSS_INCLUDE_DIR
 #endif
 
 /* This is the default list of directories to search for include files.
@@ -61,10 +61,14 @@ struct default_include
   const int cxx_aware;		/* Includes in this directory don't need to
 				   be wrapped in extern "C" when compiling
 				   C++.  */
+  const int add_sysroot;	/* FNAME should be prefixed by
+				   cpp_SYSROOT.  */
 };
 
 extern const struct default_include cpp_include_defaults[];
 extern const char cpp_GCC_INCLUDE_DIR[];
 extern const size_t cpp_GCC_INCLUDE_DIR_len;
+
+extern const char *cpp_SYSROOT;
 
 #endif /* ! GCC_CPPDEFAULT_H */
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.260.2.3
diff -u -p -r1.260.2.3 cppinit.c
--- gcc/cppinit.c	15 Oct 2002 01:32:47 -0000	1.260.2.3
+++ gcc/cppinit.c	4 Nov 2002 16:14:36 -0000
@@ -530,6 +530,7 @@ cpp_create_reader (lang)
   CPP_OPTION (pfile, operator_names) = 1;
   CPP_OPTION (pfile, warn_endif_labels) = 1;
   CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
+  CPP_OPTION (pfile, sysroot) = cpp_SYSROOT;
 
   CPP_OPTION (pfile, pending) =
     (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
@@ -758,6 +759,8 @@ init_standard_includes (pfile)
   char *path;
   const struct default_include *p;
   const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
+  int default_len, specd_len;
+  char *default_prefix;
 
   /* Several environment variables may add to the include search path.
      CPATH specifies an additional list of directories to be searched
@@ -789,43 +792,19 @@ init_standard_includes (pfile)
 
   /* Search "translated" versions of GNU directories.
      These have /usr/local/lib/gcc... replaced by specd_prefix.  */
+  default_len = 0;
   if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
     {
       /* Remove the `include' from /usr/local/lib/gcc.../include.
 	 GCC_INCLUDE_DIR will always end in /include.  */
-      int default_len = cpp_GCC_INCLUDE_DIR_len;
-      char *default_prefix = (char *) alloca (default_len + 1);
-      int specd_len = strlen (specd_prefix);
+      default_len = cpp_GCC_INCLUDE_DIR_len;
+      default_prefix = (char *) alloca (default_len + 1);
+      specd_len = strlen (specd_prefix);
 
       memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
       default_prefix[default_len] = '\0';
-
-      for (p = cpp_include_defaults; p->fname; p++)
-	{
-	  /* Some standard dirs are only for C++.  */
-	  if (!p->cplusplus
-	      || (CPP_OPTION (pfile, cplusplus)
-		  && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
-	    {
-	      /* Does this dir start with the prefix?  */
-	      if (!strncmp (p->fname, default_prefix, default_len))
-		{
-		  /* Yes; change prefix and add to search list.  */
-		  int flen = strlen (p->fname);
-		  int this_len = specd_len + flen - default_len;
-		  char *str = (char *) xmalloc (this_len + 1);
-		  memcpy (str, specd_prefix, specd_len);
-		  memcpy (str + specd_len,
-			  p->fname + default_len,
-			  flen - default_len + 1);
-
-		  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
-		}
-	    }
-	}
     }
 
-  /* Search ordinary names for GNU include directories.  */
   for (p = cpp_include_defaults; p->fname; p++)
     {
       /* Some standard dirs are only for C++.  */
@@ -833,7 +812,30 @@ init_standard_includes (pfile)
 	  || (CPP_OPTION (pfile, cplusplus)
 	      && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
 	{
-	  char *str = update_path (p->fname, p->component);
+	  char *str;
+
+	  /* Should this dir start with the sysroot?  */
+	  if (p->add_sysroot && cpp_SYSROOT[0])
+	    str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL);
+
+	  /* Does this dir start with the prefix?  */
+	  else if (default_len
+		   && !strncmp (p->fname, default_prefix, default_len))
+	    {
+	      /* Yes; change prefix and add to search list.  */
+	      int flen = strlen (p->fname);
+	      int this_len = specd_len + flen - default_len;
+
+	      str = (char *) xmalloc (this_len + 1);
+	      memcpy (str, specd_prefix, specd_len);
+	      memcpy (str + specd_len,
+		      p->fname + default_len,
+		      flen - default_len + 1);
+	    }
+
+	  else
+	    str = update_path (p->fname, p->component);
+
 	  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
 	}
     }
@@ -1176,6 +1178,7 @@ new_pending_directive (pend, text, handl
   DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
   DEF_OPT("include",                  no_fil, OPT_include)                    \
   DEF_OPT("iprefix",                  no_pth, OPT_iprefix)                    \
+  DEF_OPT("isysroot",                 no_dir, OPT_isysroot)                   \
   DEF_OPT("isystem",                  no_dir, OPT_isystem)                    \
   DEF_OPT("iwithprefix",              no_dir, OPT_iwithprefix)                \
   DEF_OPT("iwithprefixbefore",        no_dir, OPT_iwithprefixbefore)
@@ -1318,6 +1321,10 @@ cpp_handle_option (pfile, argc, argv)
 	case OPT_iprefix:
 	  CPP_OPTION (pfile, include_prefix) = arg;
 	  CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
+	  break;
+
+	case OPT_isysroot:
+	  CPP_OPTION (pfile, sysroot) = arg;
 	  break;
 
 	case OPT_A:
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.234.4.2
diff -u -p -r1.234.4.2 cpplib.h
--- gcc/cpplib.h	1 Oct 2002 17:31:41 -0000	1.234.4.2
+++ gcc/cpplib.h	4 Nov 2002 16:14:37 -0000
@@ -240,6 +240,10 @@ struct cpp_options
   const char *include_prefix;
   unsigned int include_prefix_len;
 
+  /* Directory prefix for system include directories in the standard search
+     path.  */
+  const char *sysroot;
+
   /* The language we're preprocessing.  */
   enum c_lang lang;
 
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.336.4.10
diff -u -p -r1.336.4.10 gcc.c
--- gcc/gcc.c	21 Oct 2002 17:51:57 -0000	1.336.4.10
+++ gcc/gcc.c	4 Nov 2002 16:14:42 -0000
@@ -202,6 +202,10 @@ static int report_times;
 
 static const char *target_system_root = TARGET_SYSTEM_ROOT;
 
+/* Nonzero means pass the updated target_system_root to the compiler.  */
+
+static int target_system_root_changed;
+
 /* Nonzero means write "temp" files in source directory
    and use the source file's name in them, and don't delete them.  */
 
@@ -440,7 +444,9 @@ or with constant text in a single argume
  %P	like %p, but puts `__' before and after the name of each macro.
 	(Except macros that already have __.)
 	This is for ANSI C.
- %I	Substitute a -iprefix option made from GCC_EXEC_PREFIX.
+ %I	Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
+	(made from TARGET_SYSTEM_ROOT), and -isystem (made from COMPILER_PATH
+	and -B options) as necessary.
  %s     current argument is the name of a library or startup file of some sort.
         Search for that file in a standard list of directories
 	and substitute the full name found.
@@ -2525,7 +2531,7 @@ make_relative_prefix (progname, bin_pref
     obstack_grow (&obstack, prog_dirs[i], strlen (prog_dirs[i]));
 
   /* Now build up the ..'s.  */
-  for (i = common; i < n; i++)
+  for (i = common; i < bin_num; i++)
     {
       obstack_grow (&obstack, DIR_UP, sizeof (DIR_UP) - 1);
       obstack_1grow (&obstack, DIR_SEPARATOR);
@@ -3982,7 +3988,10 @@ warranty; not even for MERCHANTABILITY o
 					       standard_bindir_prefix,
 					       target_system_root);
       if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
-	target_system_root = tmp_prefix;
+	{
+	  target_system_root = tmp_prefix;
+	  target_system_root_changed = 1;
+	}
     }
 
   /* More prefixes are enabled in main, after we read the specs file
@@ -4878,6 +4887,15 @@ do_spec_1 (spec, inswitch, soft_matched_
 		  /* Make this a separate argument.  */
 		  do_spec_1 (" ", 0, NULL);
 		  do_spec_1 (gcc_exec_prefix, 1, NULL);
+		  do_spec_1 (" ", 0, NULL);
+		}
+
+	      if (target_system_root_changed)
+		{
+		  do_spec_1 ("-isysroot", 1, NULL);
+		  /* Make this a separate argument.  */
+		  do_spec_1 (" ", 0, NULL);
+		  do_spec_1 (target_system_root, 1, NULL);
 		  do_spec_1 (" ", 0, NULL);
 		}
 
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.175.2.7
diff -u -p -r1.175.2.7 invoke.texi
--- gcc/doc/invoke.texi	21 Oct 2002 17:53:01 -0000	1.175.2.7
+++ gcc/doc/invoke.texi	4 Nov 2002 16:37:17 -0000
@@ -4839,7 +4839,10 @@ predefined macro, except for macros that
 C@.
 
 @item %I
-Substitute a @option{-iprefix} option made from @env{GCC_EXEC_PREFIX}.
+Substitute any of @option{-iprefix} (made from @env{GCC_EXEC_PREFIX}),
+@option{-isysroot} (made from @env{TARGET_SYSTEM_ROOT}), and
+@option{-isystem} (made from @env{COMPILER_PATH} and @option{-B} options)
+as necessary.
 
 @item %s
 Current argument is the name of a library or startup file of some sort.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
@ 2002-11-04  9:08 ` Jason R Thorpe
  2002-11-04 10:26 ` Hans-Peter Nilsson
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 19+ messages in thread
From: Jason R Thorpe @ 2002-11-04  9:08 UTC (permalink / raw)
  To: gcc-patches, Alexandre Oliva, Geoff Keating

On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:

 >  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
 >    one's a little more arguable but I think it's appropriate.  The sysrooted
 >    compiler should work like a system compiler inside of $sysroot; searching
 >    $prefix/include defeats that.
 >    I need this in my local setups but I won't be heartbroken if it's
 >    considered wrong for the FSF tree :)

FWIW, I completely agree with this.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
  2002-11-04  9:08 ` Jason R Thorpe
@ 2002-11-04 10:26 ` Hans-Peter Nilsson
  2002-11-04 10:30   ` Daniel Jacobowitz
  2002-11-04 23:29 ` Zack Weinberg
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 19+ messages in thread
From: Hans-Peter Nilsson @ 2002-11-04 10:26 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gcc-patches

On Mon, 4 Nov 2002, Daniel Jacobowitz wrote:
>  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
>    one's a little more arguable but I think it's appropriate.  The sysrooted
>    compiler should work like a system compiler inside of $sysroot; searching
>    $prefix/include defeats that.
>    I need this in my local setups but I won't be heartbroken if it's
>    considered wrong for the FSF tree :)

I think it's right, because I want it!  FWIW.

brgds, H-P

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04 10:26 ` Hans-Peter Nilsson
@ 2002-11-04 10:30   ` Daniel Jacobowitz
  2002-11-06  9:07     ` Alexandre Oliva
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-04 10:30 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: gcc-patches

On Mon, Nov 04, 2002 at 01:26:46PM -0500, Hans-Peter Nilsson wrote:
> On Mon, 4 Nov 2002, Daniel Jacobowitz wrote:
> >  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
> >    one's a little more arguable but I think it's appropriate.  The sysrooted
> >    compiler should work like a system compiler inside of $sysroot; searching
> >    $prefix/include defeats that.
> >    I need this in my local setups but I won't be heartbroken if it's
> >    considered wrong for the FSF tree :)
> 
> I think it's right, because I want it!  FWIW.

I'd even extend it to say that cross compilers should not search
$prefix/include...  I don't know if there's a general convention about
this (BFD recently changed its behavior here, although I don't really
like the new behavior either) but I've always thought that since
$prefix/include and $prefix/bin and $prefix/lib are siblings,
$$prefix/include should be headers for the versions of things in
$prefix/lib.  Target headers belong in $prefix/$target_alias/include.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
  2002-11-04  9:08 ` Jason R Thorpe
  2002-11-04 10:26 ` Hans-Peter Nilsson
@ 2002-11-04 23:29 ` Zack Weinberg
  2002-11-05  6:30   ` Daniel Jacobowitz
  2002-11-05 10:51   ` Geoff Keating
  2002-11-06  9:15 ` Alexandre Oliva
  2002-11-12 11:40 ` Daniel Jacobowitz
  4 siblings, 2 replies; 19+ messages in thread
From: Zack Weinberg @ 2002-11-04 23:29 UTC (permalink / raw)
  To: gcc-patches, Alexandre Oliva, Geoff Keating

On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:
> I spent a couple days working with this and finally found a solution for
> (most of) my concerns.  This patch:
> 
>  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
>    If -iprefix was used to change the compiler prefix, then first the
>    standard include directories which begin with the prefix were searched
>    (using the relocated prefix); then all directories were searched in order
>    (using the original prefix).  This means that -iprefix'd versions of
>    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
>    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
>    I changed this so that the order is preserved, and unrelocated versions
>    are not searched.  This means that people who were using -iprefix and
>    still expecting to get GCC's <stddef.h> et al. from the normal location
>    are out of luck; they'll have to specify that path as an -isystem
>    explicitly.  I think this change is correct but I'd like a second
>    opinion.
> 
>  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
>    one's a little more arguable but I think it's appropriate.  The sysrooted
>    compiler should work like a system compiler inside of $sysroot; searching
>    $prefix/include defeats that.
>    I need this in my local setups but I won't be heartbroken if it's
>    considered wrong for the FSF tree :)

Just for the record, I like the sound of both these changes.

Am I correct in thinking that for a normal Unix native compiler, you
could set sysroot to "/usr" and get the expected behavior?  Or is it
prepended to $prefix?  Or what?

zw

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04 23:29 ` Zack Weinberg
@ 2002-11-05  6:30   ` Daniel Jacobowitz
  2002-11-05 10:51   ` Geoff Keating
  1 sibling, 0 replies; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-05  6:30 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: gcc-patches, Alexandre Oliva, Geoff Keating

On Mon, Nov 04, 2002 at 11:29:39PM -0800, Zack Weinberg wrote:
> On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:
> > I spent a couple days working with this and finally found a solution for
> > (most of) my concerns.  This patch:
> > 
> >  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
> >    If -iprefix was used to change the compiler prefix, then first the
> >    standard include directories which begin with the prefix were searched
> >    (using the relocated prefix); then all directories were searched in order
> >    (using the original prefix).  This means that -iprefix'd versions of
> >    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
> >    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
> >    I changed this so that the order is preserved, and unrelocated versions
> >    are not searched.  This means that people who were using -iprefix and
> >    still expecting to get GCC's <stddef.h> et al. from the normal location
> >    are out of luck; they'll have to specify that path as an -isystem
> >    explicitly.  I think this change is correct but I'd like a second
> >    opinion.
> > 
> >  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
> >    one's a little more arguable but I think it's appropriate.  The sysrooted
> >    compiler should work like a system compiler inside of $sysroot; searching
> >    $prefix/include defeats that.
> >    I need this in my local setups but I won't be heartbroken if it's
> >    considered wrong for the FSF tree :)
> 
> Just for the record, I like the sound of both these changes.
> 
> Am I correct in thinking that for a normal Unix native compiler, you
> could set sysroot to "/usr" and get the expected behavior?  Or is it
> prepended to $prefix?  Or what?

Well, right now I don't think it'll work correctly on a native
compiler.  I haven't tested it; I think the new bits will but some of
Alex's earlier bits won't, since neither of us was really designing for
that case.  The theory says you would set sysroot to "".  It is
prepended to things like STANDARD_INCLUDE_DIR, LOCAL_INCLUDE_DIR,
-rpath-link /lib, etc.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04 23:29 ` Zack Weinberg
  2002-11-05  6:30   ` Daniel Jacobowitz
@ 2002-11-05 10:51   ` Geoff Keating
  1 sibling, 0 replies; 19+ messages in thread
From: Geoff Keating @ 2002-11-05 10:51 UTC (permalink / raw)
  To: zack; +Cc: gcc-patches, aoliva

> Date: Mon, 4 Nov 2002 23:29:39 -0800
> From: Zack Weinberg <zack@codesourcery.com>

> Am I correct in thinking that for a normal Unix native compiler, you
> could set sysroot to "/usr" and get the expected behavior?  Or is it
> prepended to $prefix?  Or what?

You'd sysroot to '/'.

The idea is that for crosses, you can NFS-mount '/' on the target
system and point the sysroot at the place where it's mounted, and your
cross will have all the libraries and headers it needs.

-- 
- Geoffrey Keating <geoffk@geoffk.org>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04 10:30   ` Daniel Jacobowitz
@ 2002-11-06  9:07     ` Alexandre Oliva
  0 siblings, 0 replies; 19+ messages in thread
From: Alexandre Oliva @ 2002-11-06  9:07 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Hans-Peter Nilsson, gcc-patches

On Nov  4, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:

> On Mon, Nov 04, 2002 at 01:26:46PM -0500, Hans-Peter Nilsson wrote:
>> On Mon, 4 Nov 2002, Daniel Jacobowitz wrote:
>> >  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
>> >    one's a little more arguable but I think it's appropriate.  The sysrooted
>> >    compiler should work like a system compiler inside of $sysroot; searching
>> >    $prefix/include defeats that.
>> >    I need this in my local setups but I won't be heartbroken if it's
>> >    considered wrong for the FSF tree :)
>> 
>> I think it's right, because I want it!  FWIW.

> I'd even extend it to say that cross compilers should not search
> $prefix/include...

This sounds quite reasonable to me.  --includedir is supposed to be
for the host, not for the target (unless target==host), so it
shouldn't be used by a cross compiler.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
                   ` (2 preceding siblings ...)
  2002-11-04 23:29 ` Zack Weinberg
@ 2002-11-06  9:15 ` Alexandre Oliva
  2002-11-06  9:30   ` Daniel Jacobowitz
  2002-11-12 11:40 ` Daniel Jacobowitz
  4 siblings, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2002-11-06  9:15 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gcc-patches, Geoff Keating

On Nov  4, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:

>  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
>    If -iprefix was used to change the compiler prefix, then first the
>    standard include directories which begin with the prefix were searched
>    (using the relocated prefix); then all directories were searched in order
>    (using the original prefix).  This means that -iprefix'd versions of
>    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
>    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.

Oops, indeed :-)

>    I changed this so that the order is preserved, and unrelocated versions
>    are not searched.

I'm not sure like the second part.  Couldn't it break compiles within
the build tree, or at least disrupt the build-tree staging area that
we've been discussing about.  Ideally, I think we should search the
original pathname, just let the relocated one be searched first, but I
don't have a strong opinion on this, and could be easily convinced
that it's a bad idea.  In fact, I've almost managed to convince myself
of it :-)

>  - Searches prefixed versions of LOCAL_INCLUDE_DIR, SYSTEM_INCLUDE_DIR,
>    and STANDARD_INCLUDE_DIR.

>  - Relocates those prefixed directories by passing -isysroot to cc1 to
>    override the normal prefix.

Yay!

>  - Fixes a bug in make_relative_path; it only worked if exec_prefix was the
>    same as or inside of prefix, which generally worked for exec_prefix
>    but won't now that we use this function for the sysroot too.

Excellent.

> With this and some -rpath-link's, I can build a complete relocatable sysroot
> compiler without having to specify the sysroot via $gcc_tooldir.  How's it
> look?

> 	* doc/invoke.texi (Spec Files): Update description of %I.

If I understand your change to make_relative_path correctly, you may
want to tweak the part of the docs that says that --with-sysroot must
be a subdirectory of exec-prefix or gcc_tooldir, and arrange for the
top-level to no longer turn it into a gcc_tooldir-relative reference
for relocatability.  In fact, I suspect a number of relocatability
issues may have become much simpler with this change.  So much so that
I fear there may be something that justified the libsubdir-based
references that both of us are missing :-(

Anyway, way to go, /me says!  No that I can approve this patch, but if
I could, I would :-)

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06  9:15 ` Alexandre Oliva
@ 2002-11-06  9:30   ` Daniel Jacobowitz
  2002-11-06 10:04     ` Alexandre Oliva
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-06  9:30 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, Geoff Keating

On Wed, Nov 06, 2002 at 03:15:00PM -0200, Alexandre Oliva wrote:
> On Nov  4, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:
> 
> >  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
> >    If -iprefix was used to change the compiler prefix, then first the
> >    standard include directories which begin with the prefix were searched
> >    (using the relocated prefix); then all directories were searched in order
> >    (using the original prefix).  This means that -iprefix'd versions of
> >    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
> >    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
> 
> Oops, indeed :-)
> 
> >    I changed this so that the order is preserved, and unrelocated versions
> >    are not searched.
> 
> I'm not sure like the second part.  Couldn't it break compiles within
> the build tree, or at least disrupt the build-tree staging area that
> we've been discussing about.  Ideally, I think we should search the
> original pathname, just let the relocated one be searched first, but I
> don't have a strong opinion on this, and could be easily convinced
> that it's a bad idea.  In fact, I've almost managed to convince myself
> of it :-)

Well, let me add a helping hand... :)  On my system, I may have several
versions of a product installed.  They're the same product, and they
normally install in the same place.  But for development purposes, I
keep them in separate places.

It's pretty important to me that one of my relocated compilers - no
matter what may be wrong with its installation, etc. - should not
search the original installation path.  Where it may find incompatible
versions of headers and libraries, and in general confuse me.

It can't affect compiles within the build tree; this is only applied to
the list of include directories in cpp_include_defaults.  None of those
are originally pointing into the build tree.

> >  - Searches prefixed versions of LOCAL_INCLUDE_DIR, SYSTEM_INCLUDE_DIR,
> >    and STANDARD_INCLUDE_DIR.
> 
> >  - Relocates those prefixed directories by passing -isysroot to cc1 to
> >    override the normal prefix.
> 
> Yay!
> 
> >  - Fixes a bug in make_relative_path; it only worked if exec_prefix was the
> >    same as or inside of prefix, which generally worked for exec_prefix
> >    but won't now that we use this function for the sysroot too.
> 
> Excellent.
> 
> > With this and some -rpath-link's, I can build a complete relocatable sysroot
> > compiler without having to specify the sysroot via $gcc_tooldir.  How's it
> > look?
> 
> > 	* doc/invoke.texi (Spec Files): Update description of %I.
> 
> If I understand your change to make_relative_path correctly, you may
> want to tweak the part of the docs that says that --with-sysroot must
> be a subdirectory of exec-prefix or gcc_tooldir, and arrange for the
> top-level to no longer turn it into a gcc_tooldir-relative reference
> for relocatability.  In fact, I suspect a number of relocatability
> issues may have become much simpler with this change.  So much so that
> I fear there may be something that justified the libsubdir-based
> references that both of us are missing :-(

Blech, I knew I forgot something.  Yes, here's the install.texi patch;
it deletes the unpleasant bit that got me started on this in the first
place, and documents the relocation.

You didn't commit the bits to turn it into a gcc_tooldir-relative
reference, did you?  Or rather, I noticed that you committed the
gcc/configure bits, but not the gcc/configure.in bits; and I think the
gcc/configure bits were the error.

> Anyway, way to go, /me says!  No that I can approve this patch, but if
> I could, I would :-)

So will someone else? :)

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-11-06  Daniel Jacobowitz  <drow@mvista.com>

	* install.texi (--with-sysroot): Update comment about
	relocation.

Index: install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.136.2.6
diff -u -p -r1.136.2.6 install.texi
--- install.texi	28 Oct 2002 19:48:54 -0000	1.136.2.6
+++ install.texi	6 Nov 2002 17:29:34 -0000
@@ -890,16 +890,9 @@ searched in there.  The specified direct
 install tree, unlike the options @option{--with-headers} and
 @option{--with-libs} that this option obsoletes.  The default value,
 in case @option{--with-sysroot} is not given an argument, is
-@option{$@{gcc_tooldir@}/sys-root}.  Starting the pathname with
-@option{$@{gcc_tooldir@}/}, in such a way that this variable is not
-expanded by the shell, but rather by the gcc Makefile, enables the
-target sysroot directory to be relocatable along with the entire
-install tree, but it will require the gcc tool directory to be created
-@emph{before} the build is started.  This directory, as well as its
-intermediate pathnames, can be easily created by running @command{make
-install-gcc-tooldir} the gcc build directory.  This is not done
-automatically to avoid touching the install tree without explicit
-permission.
+@option{$@{gcc_tooldir@}/sys-root}.  The system root path will be relocated
+along with the compiler's other search paths if the compiler's installation
+directory is moved.
 
 @item --with-headers
 @itemx --with-headers=@var{dir}

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06  9:30   ` Daniel Jacobowitz
@ 2002-11-06 10:04     ` Alexandre Oliva
  2002-11-06 10:14       ` Daniel Jacobowitz
  0 siblings, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2002-11-06 10:04 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gcc-patches, Geoff Keating

On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:

> It can't affect compiles within the build tree; this is only applied to
> the list of include directories in cpp_include_defaults.  None of those
> are originally pointing into the build tree.

Point is, when we run ./xgcc -B./, gcc takes ./ as bindir, and
tries to relocate everything else from that.

> Blech, I knew I forgot something.  Yes, here's the install.texi patch;
> it deletes the unpleasant bit that got me started on this in the first
> place, and documents the relocation.

Err...  So is it going to be relocated even if it's outside
exec_prefix or prefix.  I don't like this.

> You didn't commit the bits to turn it into a gcc_tooldir-relative
> reference, did you?

Doh.  Yes, indeed.  I just required --with-sysroot to start with
${gcc_tooldir} for it to be relocatable.

> Or rather, I noticed that you committed the gcc/configure bits, but
> not the gcc/configure.in bits; and I think the gcc/configure bits
> were the error.

Err...  I don't see that.  I seem to have checked in both
gcc/configure.in and gcc/configure, and one was generated from the
other, without the bits I didn't mean to check in.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06 10:04     ` Alexandre Oliva
@ 2002-11-06 10:14       ` Daniel Jacobowitz
  2002-11-06 12:49         ` Alexandre Oliva
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-06 10:14 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, Geoff Keating

On Wed, Nov 06, 2002 at 04:04:04PM -0200, Alexandre Oliva wrote:
> On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:
> 
> > It can't affect compiles within the build tree; this is only applied to
> > the list of include directories in cpp_include_defaults.  None of those
> > are originally pointing into the build tree.
> 
> Point is, when we run ./xgcc -B./, gcc takes ./ as bindir, and
> tries to relocate everything else from that.

But the only things it will relocate in this code are the in the
installed copy of $(gcc_tooldir).  Should we be searching that from
inside the build directory?  My hunch says no.

> > Blech, I knew I forgot something.  Yes, here's the install.texi patch;
> > it deletes the unpleasant bit that got me started on this in the first
> > place, and documents the relocation.
> 
> Err...  So is it going to be relocated even if it's outside
> exec_prefix or prefix.  I don't like this.

That's not changed by my patch: it will be relocated if the call to
make_relative_prefix you added succeeds.  If that's not what you wanted
in the first place then you should probably control it at that call
site...

My patch only changes include path handling; library search dirs work
exactly as they did before.

> > You didn't commit the bits to turn it into a gcc_tooldir-relative
> > reference, did you?
> 
> Doh.  Yes, indeed.  I just required --with-sysroot to start with
> ${gcc_tooldir} for it to be relocatable.
> 
> > Or rather, I noticed that you committed the gcc/configure bits, but
> > not the gcc/configure.in bits; and I think the gcc/configure bits
> > were the error.
> 
> Err...  I don't see that.  I seem to have checked in both
> gcc/configure.in and gcc/configure, and one was generated from the
> other, without the bits I didn't mean to check in.

Take a look at the diff between 1.630.4.3 and 1.630.4.4.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06 10:14       ` Daniel Jacobowitz
@ 2002-11-06 12:49         ` Alexandre Oliva
  2002-11-06 12:59           ` Daniel Jacobowitz
  0 siblings, 1 reply; 19+ messages in thread
From: Alexandre Oliva @ 2002-11-06 12:49 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gcc-patches, Geoff Keating

On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:

> On Wed, Nov 06, 2002 at 04:04:04PM -0200, Alexandre Oliva wrote:
>> On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:
>> 
>> > It can't affect compiles within the build tree; this is only applied to
>> > the list of include directories in cpp_include_defaults.  None of those
>> > are originally pointing into the build tree.
>> 
>> Point is, when we run ./xgcc -B./, gcc takes ./ as bindir, and
>> tries to relocate everything else from that.

> But the only things it will relocate in this code are the in the
> installed copy of $(gcc_tooldir).  Should we be searching that from
> inside the build directory?  My hunch says no.

Point is it will relocate ${prefix}/include into say ../include.

>> > Blech, I knew I forgot something.  Yes, here's the install.texi patch;
>> > it deletes the unpleasant bit that got me started on this in the first
>> > place, and documents the relocation.
>> 
>> Err...  So is it going to be relocated even if it's outside
>> exec_prefix or prefix.  I don't like this.

> That's not changed by my patch: it will be relocated if the call to
> make_relative_prefix you added succeeds.  If that's not what you wanted
> in the first place then you should probably control it at that call
> site...

I think make_relative_prefix used to prevent such relocations, and I
believe you've now made it more lax in what it accepts and tries to
relocate.  But then, I may be entirely wrong in this assumption.  If
so, I apologize.

>> Err...  I don't see that.  I seem to have checked in both
>> gcc/configure.in and gcc/configure, and one was generated from the
>> other, without the bits I didn't mean to check in.

> Take a look at the diff between 1.630.4.3 and 1.630.4.4.

Eeek.   Oh, well, looks like my mistake just went away when someone
rebuilt configure next time.  Sorry about that.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06 12:49         ` Alexandre Oliva
@ 2002-11-06 12:59           ` Daniel Jacobowitz
  2002-11-06 13:30             ` Alexandre Oliva
  0 siblings, 1 reply; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-06 12:59 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, Geoff Keating

On Wed, Nov 06, 2002 at 06:49:05PM -0200, Alexandre Oliva wrote:
> On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:
> 
> > On Wed, Nov 06, 2002 at 04:04:04PM -0200, Alexandre Oliva wrote:
> >> On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:
> >> 
> >> > It can't affect compiles within the build tree; this is only applied to
> >> > the list of include directories in cpp_include_defaults.  None of those
> >> > are originally pointing into the build tree.
> >> 
> >> Point is, when we run ./xgcc -B./, gcc takes ./ as bindir, and
> >> tries to relocate everything else from that.
> 
> > But the only things it will relocate in this code are the in the
> > installed copy of $(gcc_tooldir).  Should we be searching that from
> > inside the build directory?  My hunch says no.
> 
> Point is it will relocate ${prefix}/include into say ../include.

Nope.  ${prefix}/include isn't affected at all by my change.  There's
three sets of relocation going on right now and I'm not entirely sure
what one of them (the oldest I think) does, so I left it alone...

 - Sysrooting.
 - The -iprefix code, which I did change.  This only affects things
starting in $(gcc_tooldir).
 - The call to update_path() in prefix.c, which honors Windows registry
keys and then does black magic with other cases.

> 
> >> > Blech, I knew I forgot something.  Yes, here's the install.texi patch;
> >> > it deletes the unpleasant bit that got me started on this in the first
> >> > place, and documents the relocation.
> >> 
> >> Err...  So is it going to be relocated even if it's outside
> >> exec_prefix or prefix.  I don't like this.
> 
> > That's not changed by my patch: it will be relocated if the call to
> > make_relative_prefix you added succeeds.  If that's not what you wanted
> > in the first place then you should probably control it at that call
> > site...
> 
> I think make_relative_prefix used to prevent such relocations, and I
> believe you've now made it more lax in what it accepts and tries to
> relocate.  But then, I may be entirely wrong in this assumption.  If
> so, I apologize.

I didn't change the behavior of make_relative_prefix at all, except for
fixing the number of ".."'s it inserted in one case.  Does just what it
used to.  Which does mean that if you had:
  --prefix=/opt/a/b/c/d/e
  --with-sysroot=/opt/f
and you run:
  /baz/a/b/c/d/e/bin/gcc
It'll look in:
  /baz/f/usr/include

Of course, if you run:
  /baz/bin/gcc
It'll probably end up looking in /usr/include.  Ugh ugh ugh ugh ugh.  I
didn't introduce this but I suppose we should fix it!  Suggested
behavior?  Constrain relocation to if the sysroot starts with $prefix?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-06 12:59           ` Daniel Jacobowitz
@ 2002-11-06 13:30             ` Alexandre Oliva
  0 siblings, 0 replies; 19+ messages in thread
From: Alexandre Oliva @ 2002-11-06 13:30 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gcc-patches, Geoff Keating

On Nov  6, 2002, Daniel Jacobowitz <drow@mvista.com> wrote:

> On Wed, Nov 06, 2002 at 06:49:05PM -0200, Alexandre Oliva wrote:

>> Point is it will relocate ${prefix}/include into say ../include.

> Nope.  ${prefix}/include isn't affected at all by my change.

Note I'm not talking about include in particular.  ${exec_prefix}/foo
would be relocated to ../foo.  FWIW, I think I saw this happen to
${exec_prefix}/lib while working on sysroot, so perhaps I'm just
thinking your patch changes something that it actually doesn't.

> It'll probably end up looking in /usr/include.  Ugh ugh ugh ugh ugh.  I
> didn't introduce this but I suppose we should fix it!  Suggested
> behavior?  Constrain relocation to if the sysroot starts with $prefix?

Make it $exec_prefix and we have a deal :-)

Anyway, this was my main concern with your patch, because I *thought*
we only relocated stuff starting with $(exec_prefix)/$(libsubdir) and
your patch made it more lax.  Now I see it's not the case, so we can
fix this problem in a separate patch.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
                   ` (3 preceding siblings ...)
  2002-11-06  9:15 ` Alexandre Oliva
@ 2002-11-12 11:40 ` Daniel Jacobowitz
  2002-11-14 13:25   ` Daniel Jacobowitz
  2002-12-13 12:20   ` Neil Booth
  4 siblings, 2 replies; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-12 11:40 UTC (permalink / raw)
  To: gcc-patches, Alexandre Oliva, Geoff Keating

I'm resending this patch with a couple of additions; I think this
addresses all concerns.

On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:
> I spent a couple days working with this and finally found a solution for
> (most of) my concerns.  This patch:
> 
>  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
>    If -iprefix was used to change the compiler prefix, then first the
>    standard include directories which begin with the prefix were searched
>    (using the relocated prefix); then all directories were searched in order
>    (using the original prefix).  This means that -iprefix'd versions of
>    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
>    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
>    I changed this so that the order is preserved, and unrelocated versions
>    are not searched.  This means that people who were using -iprefix and
>    still expecting to get GCC's <stddef.h> et al. from the normal location
>    are out of luck; they'll have to specify that path as an -isystem
>    explicitly.  I think this change is correct but I'd like a second
>    opinion.

Neil and Zack seemed to agree with me on this one, whew.

>  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
>    one's a little more arguable but I think it's appropriate.  The sysrooted
>    compiler should work like a system compiler inside of $sysroot; searching
>    $prefix/include defeats that.
>    I need this in my local setups but I won't be heartbroken if it's
>    considered wrong for the FSF tree :)

Lots of support for this one.  In addition, we no longer define
PREFIX_INCLUDE_DIR for cross compilers.

>  - Searches prefixed versions of LOCAL_INCLUDE_DIR, SYSTEM_INCLUDE_DIR,
>    and STANDARD_INCLUDE_DIR.
> 
>  - Relocates those prefixed directories by passing -isysroot to cc1 to
>    override the normal prefix.
> 
>  - Fixes a bug in make_relative_path; it only worked if exec_prefix was the
>    same as or inside of prefix, which generally worked for exec_prefix
>    but won't now that we use this function for the sysroot too.
> 
> With this and some -rpath-link's, I can build a complete relocatable sysroot
> compiler without having to specify the sysroot via $gcc_tooldir.  How's it
> look?

And one last change, the sysroot is no longer relocated if it is
outside of $exec_prefix.  Documentation updated to match.

Is this OK for b-i-b?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-11-12  Daniel Jacobowitz  <drow@mvista.com>

	* Makefile.in (PREPROCESSOR_DEFINES): Add
	@TARGET_SYSTEM_ROOT_DEFINE@.
	* configure.in (PREFIX_INCLUDE_DIR): Don't define if $with_sysroot
	is specified or if building a cross compiler.
	(TARGET_SYSTEM_ROOT_DEFINE): Add TARGET_SYSTEM_ROOT_RELOCATABLE
	if the sysroot is under $exec_prefix.
	* configure: Regenerated.
	* cppdefault.h: Use native include paths if TARGET_SYSTEM_ROOT is
	defined.
	(struct default_include): Add add_sysroot field.
	(cpp_SYSROOT): Declare.
	* cppdefault.c (cpp_include_defaults): Fill in add_sysroot
	field.
	(cpp_SYSROOT): New variable.
	* cppinit.c (cpp_create_reader): Initialize
	CPP_OPTION (pfile, sysroot).
	(init_standard_includes): Handle add_sysroot.  Do not
	add unrelocated copies of relocated directories.
	(COMMAND_LINE_OPTIONS): Add -isysroot.
	(cpp_handle_option): Handle -isysroot.
	* cpplib.h (struct cpp_options): Add sysroot member.
	* gcc.c (The Specs Language): Update description of %I.
	(target_system_root_changed): New variable.
	(make_relative_prefix): Add DIR_UP components up to bin_num instead
	of n.
	(process_command): Conditionalize make_relative_prefix call
	on !VMS and TARGET_SYSTEM_ROOT_RELOCATABLE.  Set
	target_system_root_changed.
	(do_spec_1): Add -isysroot to %I.
	* doc/invoke.texi (Spec Files): Update description of %I.
	* doc/install.texi (--with-sysroot): Update comment about
	relocation.

Index: gcc/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.939.2.13
diff -u -p -r1.939.2.13 Makefile.in
--- gcc/Makefile.in	5 Nov 2002 19:11:50 -0000	1.939.2.13
+++ gcc/Makefile.in	12 Nov 2002 18:29:43 -0000
@@ -2180,7 +2180,8 @@ PREPROCESSOR_DEFINES = \
   -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
   -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
   -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
-  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\"
+  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
+  @TARGET_SYSTEM_ROOT_DEFINE@
 
 LIBCPP_OBJS =	cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpptrad.o \
 		cpphash.o cpperror.o cppinit.o cppdefault.o cppmain.o \
Index: gcc/configure.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/configure.in,v
retrieving revision 1.617.4.5
diff -u -p -r1.617.4.5 configure.in
--- gcc/configure.in	28 Oct 2002 19:47:05 -0000	1.617.4.5
+++ gcc/configure.in	12 Nov 2002 18:29:52 -0000
@@ -383,6 +383,22 @@ AC_ARG_WITH(sysroot,
    
  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
+  fi
+ else
+  test_prefix=$exec_prefix
+ fi
+ case ${TARGET_SYSTEM_ROOT} in
+ ${test_prefix}*)
+   t="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE"
+   TARGET_SYSTEM_ROOT_DEFINE="$t"
+   ;;
+ esac
 ], [
  TARGET_SYSTEM_ROOT=
  TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=0'
@@ -2267,7 +2283,8 @@ case "$target" in
     ;;
 esac
 
-if test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
+if test x$with_sysroot = x && x$host = x$target \
+   && test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
   AC_DEFINE_UNQUOTED(PREFIX_INCLUDE_DIR, "$prefix/include")
 fi
 
Index: gcc/cppdefault.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppdefault.c,v
retrieving revision 1.4
diff -u -p -r1.4 cppdefault.c
--- gcc/cppdefault.c	29 Sep 2001 18:22:02 -0000	1.4
+++ gcc/cppdefault.c	12 Nov 2002 18:29:52 -0000
@@ -33,44 +33,44 @@ const struct default_include cpp_include
 = {
 #ifdef GPLUSPLUS_INCLUDE_DIR
     /* Pick up GNU C++ generic include files.  */
-    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
     /* Pick up GNU C++ target-dependent include files.  */
-    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
     /* Pick up GNU C++ backward and deprecated include files.  */
-    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 },
+    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, 0 },
 #endif
 #ifdef LOCAL_INCLUDE_DIR
     /* /usr/local/include comes before the fixincluded header files.  */
-    { LOCAL_INCLUDE_DIR, 0, 0, 1 },
+    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
 #endif
 #ifdef PREFIX_INCLUDE_DIR
-    { PREFIX_INCLUDE_DIR, 0, 0, 1 },
+    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0 },
 #endif
 #ifdef GCC_INCLUDE_DIR
     /* This is the dir for fixincludes and for gcc's private headers.  */
-    { GCC_INCLUDE_DIR, "GCC", 0, 0 },
+    { GCC_INCLUDE_DIR, "GCC", 0, 0, 0 },
 #endif
 #ifdef CROSS_INCLUDE_DIR
     /* One place the target system's headers might be.  */
-    { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
+    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0 },
 #endif
 #ifdef TOOL_INCLUDE_DIR
     /* Another place the target system's headers might be.  */
-    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
+    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0 },
 #endif
 #ifdef SYSTEM_INCLUDE_DIR
     /* Some systems have an extra dir of include files.  */
-    { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
+    { SYSTEM_INCLUDE_DIR, 0, 0, 0, 1 },
 #endif
 #ifdef STANDARD_INCLUDE_DIR
     /* /usr/include comes dead last.  */
-    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
+    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
 #endif
-    { 0, 0, 0, 0 }
+    { 0, 0, 0, 0, 0 }
   };
 #endif /* no INCLUDE_DEFAULTS */
 
@@ -80,4 +80,10 @@ const size_t cpp_GCC_INCLUDE_DIR_len = s
 #else
 const char cpp_GCC_INCLUDE_DIR[] = "";
 const size_t cpp_GCC_INCLUDE_DIR_len = 0;
+#endif
+
+#ifdef TARGET_SYSTEM_ROOT
+const char *cpp_SYSROOT = TARGET_SYSTEM_ROOT;
+#else
+const char *cpp_SYSROOT = "";
 #endif
Index: gcc/cppdefault.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppdefault.h,v
retrieving revision 1.6
diff -u -p -r1.6 cppdefault.h
--- gcc/cppdefault.h	16 May 2002 19:02:59 -0000	1.6
+++ gcc/cppdefault.h	12 Nov 2002 18:29:52 -0000
@@ -34,12 +34,12 @@ Foundation, 59 Temple Place - Suite 330,
 #define STANDARD_INCLUDE_COMPONENT 0
 #endif
 
-#ifdef CROSS_COMPILE
-#undef LOCAL_INCLUDE_DIR
-#undef SYSTEM_INCLUDE_DIR
-#undef STANDARD_INCLUDE_DIR
+#if defined (CROSS_COMPILE) && !defined (TARGET_SYSTEM_ROOT)
+# undef LOCAL_INCLUDE_DIR
+# undef SYSTEM_INCLUDE_DIR
+# undef STANDARD_INCLUDE_DIR
 #else
-#undef CROSS_INCLUDE_DIR
+# undef CROSS_INCLUDE_DIR
 #endif
 
 /* This is the default list of directories to search for include files.
@@ -61,10 +61,14 @@ struct default_include
   const int cxx_aware;		/* Includes in this directory don't need to
 				   be wrapped in extern "C" when compiling
 				   C++.  */
+  const int add_sysroot;	/* FNAME should be prefixed by
+				   cpp_SYSROOT.  */
 };
 
 extern const struct default_include cpp_include_defaults[];
 extern const char cpp_GCC_INCLUDE_DIR[];
 extern const size_t cpp_GCC_INCLUDE_DIR_len;
+
+extern const char *cpp_SYSROOT;
 
 #endif /* ! GCC_CPPDEFAULT_H */
Index: gcc/cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.260.2.3
diff -u -p -r1.260.2.3 cppinit.c
--- gcc/cppinit.c	15 Oct 2002 01:32:47 -0000	1.260.2.3
+++ gcc/cppinit.c	12 Nov 2002 18:29:53 -0000
@@ -530,6 +530,7 @@ cpp_create_reader (lang)
   CPP_OPTION (pfile, operator_names) = 1;
   CPP_OPTION (pfile, warn_endif_labels) = 1;
   CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
+  CPP_OPTION (pfile, sysroot) = cpp_SYSROOT;
 
   CPP_OPTION (pfile, pending) =
     (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
@@ -758,6 +759,8 @@ init_standard_includes (pfile)
   char *path;
   const struct default_include *p;
   const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
+  int default_len, specd_len;
+  char *default_prefix;
 
   /* Several environment variables may add to the include search path.
      CPATH specifies an additional list of directories to be searched
@@ -789,43 +792,19 @@ init_standard_includes (pfile)
 
   /* Search "translated" versions of GNU directories.
      These have /usr/local/lib/gcc... replaced by specd_prefix.  */
+  default_len = 0;
   if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
     {
       /* Remove the `include' from /usr/local/lib/gcc.../include.
 	 GCC_INCLUDE_DIR will always end in /include.  */
-      int default_len = cpp_GCC_INCLUDE_DIR_len;
-      char *default_prefix = (char *) alloca (default_len + 1);
-      int specd_len = strlen (specd_prefix);
+      default_len = cpp_GCC_INCLUDE_DIR_len;
+      default_prefix = (char *) alloca (default_len + 1);
+      specd_len = strlen (specd_prefix);
 
       memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
       default_prefix[default_len] = '\0';
-
-      for (p = cpp_include_defaults; p->fname; p++)
-	{
-	  /* Some standard dirs are only for C++.  */
-	  if (!p->cplusplus
-	      || (CPP_OPTION (pfile, cplusplus)
-		  && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
-	    {
-	      /* Does this dir start with the prefix?  */
-	      if (!strncmp (p->fname, default_prefix, default_len))
-		{
-		  /* Yes; change prefix and add to search list.  */
-		  int flen = strlen (p->fname);
-		  int this_len = specd_len + flen - default_len;
-		  char *str = (char *) xmalloc (this_len + 1);
-		  memcpy (str, specd_prefix, specd_len);
-		  memcpy (str + specd_len,
-			  p->fname + default_len,
-			  flen - default_len + 1);
-
-		  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
-		}
-	    }
-	}
     }
 
-  /* Search ordinary names for GNU include directories.  */
   for (p = cpp_include_defaults; p->fname; p++)
     {
       /* Some standard dirs are only for C++.  */
@@ -833,7 +812,30 @@ init_standard_includes (pfile)
 	  || (CPP_OPTION (pfile, cplusplus)
 	      && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
 	{
-	  char *str = update_path (p->fname, p->component);
+	  char *str;
+
+	  /* Should this dir start with the sysroot?  */
+	  if (p->add_sysroot && cpp_SYSROOT[0])
+	    str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL);
+
+	  /* Does this dir start with the prefix?  */
+	  else if (default_len
+		   && !strncmp (p->fname, default_prefix, default_len))
+	    {
+	      /* Yes; change prefix and add to search list.  */
+	      int flen = strlen (p->fname);
+	      int this_len = specd_len + flen - default_len;
+
+	      str = (char *) xmalloc (this_len + 1);
+	      memcpy (str, specd_prefix, specd_len);
+	      memcpy (str + specd_len,
+		      p->fname + default_len,
+		      flen - default_len + 1);
+	    }
+
+	  else
+	    str = update_path (p->fname, p->component);
+
 	  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
 	}
     }
@@ -1176,6 +1178,7 @@ new_pending_directive (pend, text, handl
   DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
   DEF_OPT("include",                  no_fil, OPT_include)                    \
   DEF_OPT("iprefix",                  no_pth, OPT_iprefix)                    \
+  DEF_OPT("isysroot",                 no_dir, OPT_isysroot)                   \
   DEF_OPT("isystem",                  no_dir, OPT_isystem)                    \
   DEF_OPT("iwithprefix",              no_dir, OPT_iwithprefix)                \
   DEF_OPT("iwithprefixbefore",        no_dir, OPT_iwithprefixbefore)
@@ -1318,6 +1321,10 @@ cpp_handle_option (pfile, argc, argv)
 	case OPT_iprefix:
 	  CPP_OPTION (pfile, include_prefix) = arg;
 	  CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
+	  break;
+
+	case OPT_isysroot:
+	  CPP_OPTION (pfile, sysroot) = arg;
 	  break;
 
 	case OPT_A:
Index: gcc/cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.234.4.2
diff -u -p -r1.234.4.2 cpplib.h
--- gcc/cpplib.h	1 Oct 2002 17:31:41 -0000	1.234.4.2
+++ gcc/cpplib.h	12 Nov 2002 18:29:54 -0000
@@ -240,6 +240,10 @@ struct cpp_options
   const char *include_prefix;
   unsigned int include_prefix_len;
 
+  /* Directory prefix for system include directories in the standard search
+     path.  */
+  const char *sysroot;
+
   /* The language we're preprocessing.  */
   enum c_lang lang;
 
Index: gcc/gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.336.4.10
diff -u -p -r1.336.4.10 gcc.c
--- gcc/gcc.c	21 Oct 2002 17:51:57 -0000	1.336.4.10
+++ gcc/gcc.c	12 Nov 2002 18:29:59 -0000
@@ -202,6 +202,10 @@ static int report_times;
 
 static const char *target_system_root = TARGET_SYSTEM_ROOT;
 
+/* Nonzero means pass the updated target_system_root to the compiler.  */
+
+static int target_system_root_changed;
+
 /* Nonzero means write "temp" files in source directory
    and use the source file's name in them, and don't delete them.  */
 
@@ -440,7 +444,9 @@ or with constant text in a single argume
  %P	like %p, but puts `__' before and after the name of each macro.
 	(Except macros that already have __.)
 	This is for ANSI C.
- %I	Substitute a -iprefix option made from GCC_EXEC_PREFIX.
+ %I	Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
+	(made from TARGET_SYSTEM_ROOT), and -isystem (made from COMPILER_PATH
+	and -B options) as necessary.
  %s     current argument is the name of a library or startup file of some sort.
         Search for that file in a standard list of directories
 	and substitute the full name found.
@@ -2525,7 +2531,7 @@ make_relative_prefix (progname, bin_pref
     obstack_grow (&obstack, prog_dirs[i], strlen (prog_dirs[i]));
 
   /* Now build up the ..'s.  */
-  for (i = common; i < n; i++)
+  for (i = common; i < bin_num; i++)
     {
       obstack_grow (&obstack, DIR_UP, sizeof (DIR_UP) - 1);
       obstack_1grow (&obstack, DIR_SEPARATOR);
@@ -3976,14 +3982,23 @@ warranty; not even for MERCHANTABILITY o
 	      concat (tooldir_prefix, "lib", dir_separator_str, NULL),
 	      "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL, 1);
 
+#if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
+  /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
+     then consider it to relocate with the rest of the GCC installation
+     if GCC_EXEC_PREFIX is set.
+     ``make_relative_prefix'' is not compiled for VMS, so don't call it.  */
   if (target_system_root && gcc_exec_prefix)
     {
       char *tmp_prefix = make_relative_prefix (argv[0],
 					       standard_bindir_prefix,
 					       target_system_root);
       if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
-	target_system_root = tmp_prefix;
+	{
+	  target_system_root = tmp_prefix;
+	  target_system_root_changed = 1;
+	}
     }
+#endif
 
   /* More prefixes are enabled in main, after we read the specs file
      and determine whether this is cross-compilation or not.  */
@@ -4878,6 +4893,15 @@ do_spec_1 (spec, inswitch, soft_matched_
 		  /* Make this a separate argument.  */
 		  do_spec_1 (" ", 0, NULL);
 		  do_spec_1 (gcc_exec_prefix, 1, NULL);
+		  do_spec_1 (" ", 0, NULL);
+		}
+
+	      if (target_system_root_changed)
+		{
+		  do_spec_1 ("-isysroot", 1, NULL);
+		  /* Make this a separate argument.  */
+		  do_spec_1 (" ", 0, NULL);
+		  do_spec_1 (target_system_root, 1, NULL);
 		  do_spec_1 (" ", 0, NULL);
 		}
 
Index: gcc/doc/install.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
retrieving revision 1.136.2.8
diff -u -p -r1.136.2.8 install.texi
--- gcc/doc/install.texi	10 Nov 2002 01:13:53 -0000	1.136.2.8
+++ gcc/doc/install.texi	12 Nov 2002 18:30:08 -0000
@@ -891,16 +891,9 @@ searched in there.  The specified direct
 install tree, unlike the options @option{--with-headers} and
 @option{--with-libs} that this option obsoletes.  The default value,
 in case @option{--with-sysroot} is not given an argument, is
-@option{$@{gcc_tooldir@}/sys-root}.  Starting the pathname with
-@option{$@{gcc_tooldir@}/}, in such a way that this variable is not
-expanded by the shell, but rather by the gcc Makefile, enables the
-target sysroot directory to be relocatable along with the entire
-install tree, but it will require the gcc tool directory to be created
-@emph{before} the build is started.  This directory, as well as its
-intermediate pathnames, can be easily created by running @command{make
-install-gcc-tooldir} the gcc build directory.  This is not done
-automatically to avoid touching the install tree without explicit
-permission.
+@option{$@{gcc_tooldir@}/sys-root}.  If the specified directory is a
+subdirectory of @option{$@{exec_prefix@}}, then it will be found relative to
+the GCC binaries if the installation tree is moved.
 
 @item --with-headers
 @itemx --with-headers=@var{dir}
Index: gcc/doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.175.2.8
diff -u -p -r1.175.2.8 invoke.texi
--- gcc/doc/invoke.texi	5 Nov 2002 19:12:25 -0000	1.175.2.8
+++ gcc/doc/invoke.texi	12 Nov 2002 18:30:18 -0000
@@ -4840,7 +4840,10 @@ predefined macro, except for macros that
 C@.
 
 @item %I
-Substitute a @option{-iprefix} option made from @env{GCC_EXEC_PREFIX}.
+Substitute any of @option{-iprefix} (made from @env{GCC_EXEC_PREFIX}),
+@option{-isysroot} (made from @env{TARGET_SYSTEM_ROOT}), and
+@option{-isystem} (made from @env{COMPILER_PATH} and @option{-B} options)
+as necessary.
 
 @item %s
 Current argument is the name of a library or startup file of some sort.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-12 11:40 ` Daniel Jacobowitz
@ 2002-11-14 13:25   ` Daniel Jacobowitz
  2002-12-07  8:44     ` Neil Booth
  2002-12-13 12:20   ` Neil Booth
  1 sibling, 1 reply; 19+ messages in thread
From: Daniel Jacobowitz @ 2002-11-14 13:25 UTC (permalink / raw)
  To: gcc-patches

Would a global write maintainer mind reviewing these changes?

On Tue, Nov 12, 2002 at 02:41:49PM -0500, Daniel Jacobowitz wrote:
> I'm resending this patch with a couple of additions; I think this
> addresses all concerns.
> 
> On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:
> > I spent a couple days working with this and finally found a solution for
> > (most of) my concerns.  This patch:
> > 
> >  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
> >    If -iprefix was used to change the compiler prefix, then first the
> >    standard include directories which begin with the prefix were searched
> >    (using the relocated prefix); then all directories were searched in order
> >    (using the original prefix).  This means that -iprefix'd versions of
> >    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
> >    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
> >    I changed this so that the order is preserved, and unrelocated versions
> >    are not searched.  This means that people who were using -iprefix and
> >    still expecting to get GCC's <stddef.h> et al. from the normal location
> >    are out of luck; they'll have to specify that path as an -isystem
> >    explicitly.  I think this change is correct but I'd like a second
> >    opinion.
> 
> Neil and Zack seemed to agree with me on this one, whew.
> 
> >  - No longer defines PREFIX_INCLUDE_DIR for a sysrooted compiler.  This
> >    one's a little more arguable but I think it's appropriate.  The sysrooted
> >    compiler should work like a system compiler inside of $sysroot; searching
> >    $prefix/include defeats that.
> >    I need this in my local setups but I won't be heartbroken if it's
> >    considered wrong for the FSF tree :)
> 
> Lots of support for this one.  In addition, we no longer define
> PREFIX_INCLUDE_DIR for cross compilers.
> 
> >  - Searches prefixed versions of LOCAL_INCLUDE_DIR, SYSTEM_INCLUDE_DIR,
> >    and STANDARD_INCLUDE_DIR.
> > 
> >  - Relocates those prefixed directories by passing -isysroot to cc1 to
> >    override the normal prefix.
> > 
> >  - Fixes a bug in make_relative_path; it only worked if exec_prefix was the
> >    same as or inside of prefix, which generally worked for exec_prefix
> >    but won't now that we use this function for the sysroot too.
> > 
> > With this and some -rpath-link's, I can build a complete relocatable sysroot
> > compiler without having to specify the sysroot via $gcc_tooldir.  How's it
> > look?
> 
> And one last change, the sysroot is no longer relocated if it is
> outside of $exec_prefix.  Documentation updated to match.
> 
> Is this OK for b-i-b?
> 
> -- 
> Daniel Jacobowitz
> MontaVista Software                         Debian GNU/Linux Developer
> 
> 2002-11-12  Daniel Jacobowitz  <drow@mvista.com>
> 
> 	* Makefile.in (PREPROCESSOR_DEFINES): Add
> 	@TARGET_SYSTEM_ROOT_DEFINE@.
> 	* configure.in (PREFIX_INCLUDE_DIR): Don't define if $with_sysroot
> 	is specified or if building a cross compiler.
> 	(TARGET_SYSTEM_ROOT_DEFINE): Add TARGET_SYSTEM_ROOT_RELOCATABLE
> 	if the sysroot is under $exec_prefix.
> 	* configure: Regenerated.
> 	* cppdefault.h: Use native include paths if TARGET_SYSTEM_ROOT is
> 	defined.
> 	(struct default_include): Add add_sysroot field.
> 	(cpp_SYSROOT): Declare.
> 	* cppdefault.c (cpp_include_defaults): Fill in add_sysroot
> 	field.
> 	(cpp_SYSROOT): New variable.
> 	* cppinit.c (cpp_create_reader): Initialize
> 	CPP_OPTION (pfile, sysroot).
> 	(init_standard_includes): Handle add_sysroot.  Do not
> 	add unrelocated copies of relocated directories.
> 	(COMMAND_LINE_OPTIONS): Add -isysroot.
> 	(cpp_handle_option): Handle -isysroot.
> 	* cpplib.h (struct cpp_options): Add sysroot member.
> 	* gcc.c (The Specs Language): Update description of %I.
> 	(target_system_root_changed): New variable.
> 	(make_relative_prefix): Add DIR_UP components up to bin_num instead
> 	of n.
> 	(process_command): Conditionalize make_relative_prefix call
> 	on !VMS and TARGET_SYSTEM_ROOT_RELOCATABLE.  Set
> 	target_system_root_changed.
> 	(do_spec_1): Add -isysroot to %I.
> 	* doc/invoke.texi (Spec Files): Update description of %I.
> 	* doc/install.texi (--with-sysroot): Update comment about
> 	relocation.
> 
> Index: gcc/Makefile.in
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
> retrieving revision 1.939.2.13
> diff -u -p -r1.939.2.13 Makefile.in
> --- gcc/Makefile.in	5 Nov 2002 19:11:50 -0000	1.939.2.13
> +++ gcc/Makefile.in	12 Nov 2002 18:29:43 -0000
> @@ -2180,7 +2180,8 @@ PREPROCESSOR_DEFINES = \
>    -DGPLUSPLUS_BACKWARD_INCLUDE_DIR=\"$(gcc_gxx_include_dir)/backward\" \
>    -DLOCAL_INCLUDE_DIR=\"$(local_includedir)\" \
>    -DCROSS_INCLUDE_DIR=\"$(CROSS_SYSTEM_HEADER_DIR)\" \
> -  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\"
> +  -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
> +  @TARGET_SYSTEM_ROOT_DEFINE@
>  
>  LIBCPP_OBJS =	cpplib.o cpplex.o cppmacro.o cppexp.o cppfiles.o cpptrad.o \
>  		cpphash.o cpperror.o cppinit.o cppdefault.o cppmain.o \
> Index: gcc/configure.in
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/configure.in,v
> retrieving revision 1.617.4.5
> diff -u -p -r1.617.4.5 configure.in
> --- gcc/configure.in	28 Oct 2002 19:47:05 -0000	1.617.4.5
> +++ gcc/configure.in	12 Nov 2002 18:29:52 -0000
> @@ -383,6 +383,22 @@ AC_ARG_WITH(sysroot,
>     
>   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
> +  fi
> + else
> +  test_prefix=$exec_prefix
> + fi
> + case ${TARGET_SYSTEM_ROOT} in
> + ${test_prefix}*)
> +   t="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE"
> +   TARGET_SYSTEM_ROOT_DEFINE="$t"
> +   ;;
> + esac
>  ], [
>   TARGET_SYSTEM_ROOT=
>   TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=0'
> @@ -2267,7 +2283,8 @@ case "$target" in
>      ;;
>  esac
>  
> -if test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
> +if test x$with_sysroot = x && x$host = x$target \
> +   && test "$prefix" != "/usr" && test "x$prefix" != "x$local_prefix" ; then
>    AC_DEFINE_UNQUOTED(PREFIX_INCLUDE_DIR, "$prefix/include")
>  fi
>  
> Index: gcc/cppdefault.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cppdefault.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 cppdefault.c
> --- gcc/cppdefault.c	29 Sep 2001 18:22:02 -0000	1.4
> +++ gcc/cppdefault.c	12 Nov 2002 18:29:52 -0000
> @@ -33,44 +33,44 @@ const struct default_include cpp_include
>  = {
>  #ifdef GPLUSPLUS_INCLUDE_DIR
>      /* Pick up GNU C++ generic include files.  */
> -    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
> +    { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0 },
>  #endif
>  #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
>      /* Pick up GNU C++ target-dependent include files.  */
> -    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1 },
> +    { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, 0 },
>  #endif
>  #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
>      /* Pick up GNU C++ backward and deprecated include files.  */
> -    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1 },
> +    { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, 0 },
>  #endif
>  #ifdef LOCAL_INCLUDE_DIR
>      /* /usr/local/include comes before the fixincluded header files.  */
> -    { LOCAL_INCLUDE_DIR, 0, 0, 1 },
> +    { LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
>  #endif
>  #ifdef PREFIX_INCLUDE_DIR
> -    { PREFIX_INCLUDE_DIR, 0, 0, 1 },
> +    { PREFIX_INCLUDE_DIR, 0, 0, 1, 0 },
>  #endif
>  #ifdef GCC_INCLUDE_DIR
>      /* This is the dir for fixincludes and for gcc's private headers.  */
> -    { GCC_INCLUDE_DIR, "GCC", 0, 0 },
> +    { GCC_INCLUDE_DIR, "GCC", 0, 0, 0 },
>  #endif
>  #ifdef CROSS_INCLUDE_DIR
>      /* One place the target system's headers might be.  */
> -    { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
> +    { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0 },
>  #endif
>  #ifdef TOOL_INCLUDE_DIR
>      /* Another place the target system's headers might be.  */
> -    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
> +    { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0 },
>  #endif
>  #ifdef SYSTEM_INCLUDE_DIR
>      /* Some systems have an extra dir of include files.  */
> -    { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
> +    { SYSTEM_INCLUDE_DIR, 0, 0, 0, 1 },
>  #endif
>  #ifdef STANDARD_INCLUDE_DIR
>      /* /usr/include comes dead last.  */
> -    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
> +    { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
>  #endif
> -    { 0, 0, 0, 0 }
> +    { 0, 0, 0, 0, 0 }
>    };
>  #endif /* no INCLUDE_DEFAULTS */
>  
> @@ -80,4 +80,10 @@ const size_t cpp_GCC_INCLUDE_DIR_len = s
>  #else
>  const char cpp_GCC_INCLUDE_DIR[] = "";
>  const size_t cpp_GCC_INCLUDE_DIR_len = 0;
> +#endif
> +
> +#ifdef TARGET_SYSTEM_ROOT
> +const char *cpp_SYSROOT = TARGET_SYSTEM_ROOT;
> +#else
> +const char *cpp_SYSROOT = "";
>  #endif
> Index: gcc/cppdefault.h
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cppdefault.h,v
> retrieving revision 1.6
> diff -u -p -r1.6 cppdefault.h
> --- gcc/cppdefault.h	16 May 2002 19:02:59 -0000	1.6
> +++ gcc/cppdefault.h	12 Nov 2002 18:29:52 -0000
> @@ -34,12 +34,12 @@ Foundation, 59 Temple Place - Suite 330,
>  #define STANDARD_INCLUDE_COMPONENT 0
>  #endif
>  
> -#ifdef CROSS_COMPILE
> -#undef LOCAL_INCLUDE_DIR
> -#undef SYSTEM_INCLUDE_DIR
> -#undef STANDARD_INCLUDE_DIR
> +#if defined (CROSS_COMPILE) && !defined (TARGET_SYSTEM_ROOT)
> +# undef LOCAL_INCLUDE_DIR
> +# undef SYSTEM_INCLUDE_DIR
> +# undef STANDARD_INCLUDE_DIR
>  #else
> -#undef CROSS_INCLUDE_DIR
> +# undef CROSS_INCLUDE_DIR
>  #endif
>  
>  /* This is the default list of directories to search for include files.
> @@ -61,10 +61,14 @@ struct default_include
>    const int cxx_aware;		/* Includes in this directory don't need to
>  				   be wrapped in extern "C" when compiling
>  				   C++.  */
> +  const int add_sysroot;	/* FNAME should be prefixed by
> +				   cpp_SYSROOT.  */
>  };
>  
>  extern const struct default_include cpp_include_defaults[];
>  extern const char cpp_GCC_INCLUDE_DIR[];
>  extern const size_t cpp_GCC_INCLUDE_DIR_len;
> +
> +extern const char *cpp_SYSROOT;
>  
>  #endif /* ! GCC_CPPDEFAULT_H */
> Index: gcc/cppinit.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
> retrieving revision 1.260.2.3
> diff -u -p -r1.260.2.3 cppinit.c
> --- gcc/cppinit.c	15 Oct 2002 01:32:47 -0000	1.260.2.3
> +++ gcc/cppinit.c	12 Nov 2002 18:29:53 -0000
> @@ -530,6 +530,7 @@ cpp_create_reader (lang)
>    CPP_OPTION (pfile, operator_names) = 1;
>    CPP_OPTION (pfile, warn_endif_labels) = 1;
>    CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
> +  CPP_OPTION (pfile, sysroot) = cpp_SYSROOT;
>  
>    CPP_OPTION (pfile, pending) =
>      (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
> @@ -758,6 +759,8 @@ init_standard_includes (pfile)
>    char *path;
>    const struct default_include *p;
>    const char *specd_prefix = CPP_OPTION (pfile, include_prefix);
> +  int default_len, specd_len;
> +  char *default_prefix;
>  
>    /* Several environment variables may add to the include search path.
>       CPATH specifies an additional list of directories to be searched
> @@ -789,43 +792,19 @@ init_standard_includes (pfile)
>  
>    /* Search "translated" versions of GNU directories.
>       These have /usr/local/lib/gcc... replaced by specd_prefix.  */
> +  default_len = 0;
>    if (specd_prefix != 0 && cpp_GCC_INCLUDE_DIR_len)
>      {
>        /* Remove the `include' from /usr/local/lib/gcc.../include.
>  	 GCC_INCLUDE_DIR will always end in /include.  */
> -      int default_len = cpp_GCC_INCLUDE_DIR_len;
> -      char *default_prefix = (char *) alloca (default_len + 1);
> -      int specd_len = strlen (specd_prefix);
> +      default_len = cpp_GCC_INCLUDE_DIR_len;
> +      default_prefix = (char *) alloca (default_len + 1);
> +      specd_len = strlen (specd_prefix);
>  
>        memcpy (default_prefix, cpp_GCC_INCLUDE_DIR, default_len);
>        default_prefix[default_len] = '\0';
> -
> -      for (p = cpp_include_defaults; p->fname; p++)
> -	{
> -	  /* Some standard dirs are only for C++.  */
> -	  if (!p->cplusplus
> -	      || (CPP_OPTION (pfile, cplusplus)
> -		  && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
> -	    {
> -	      /* Does this dir start with the prefix?  */
> -	      if (!strncmp (p->fname, default_prefix, default_len))
> -		{
> -		  /* Yes; change prefix and add to search list.  */
> -		  int flen = strlen (p->fname);
> -		  int this_len = specd_len + flen - default_len;
> -		  char *str = (char *) xmalloc (this_len + 1);
> -		  memcpy (str, specd_prefix, specd_len);
> -		  memcpy (str + specd_len,
> -			  p->fname + default_len,
> -			  flen - default_len + 1);
> -
> -		  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
> -		}
> -	    }
> -	}
>      }
>  
> -  /* Search ordinary names for GNU include directories.  */
>    for (p = cpp_include_defaults; p->fname; p++)
>      {
>        /* Some standard dirs are only for C++.  */
> @@ -833,7 +812,30 @@ init_standard_includes (pfile)
>  	  || (CPP_OPTION (pfile, cplusplus)
>  	      && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
>  	{
> -	  char *str = update_path (p->fname, p->component);
> +	  char *str;
> +
> +	  /* Should this dir start with the sysroot?  */
> +	  if (p->add_sysroot && cpp_SYSROOT[0])
> +	    str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL);
> +
> +	  /* Does this dir start with the prefix?  */
> +	  else if (default_len
> +		   && !strncmp (p->fname, default_prefix, default_len))
> +	    {
> +	      /* Yes; change prefix and add to search list.  */
> +	      int flen = strlen (p->fname);
> +	      int this_len = specd_len + flen - default_len;
> +
> +	      str = (char *) xmalloc (this_len + 1);
> +	      memcpy (str, specd_prefix, specd_len);
> +	      memcpy (str + specd_len,
> +		      p->fname + default_len,
> +		      flen - default_len + 1);
> +	    }
> +
> +	  else
> +	    str = update_path (p->fname, p->component);
> +
>  	  append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
>  	}
>      }
> @@ -1176,6 +1178,7 @@ new_pending_directive (pend, text, handl
>    DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
>    DEF_OPT("include",                  no_fil, OPT_include)                    \
>    DEF_OPT("iprefix",                  no_pth, OPT_iprefix)                    \
> +  DEF_OPT("isysroot",                 no_dir, OPT_isysroot)                   \
>    DEF_OPT("isystem",                  no_dir, OPT_isystem)                    \
>    DEF_OPT("iwithprefix",              no_dir, OPT_iwithprefix)                \
>    DEF_OPT("iwithprefixbefore",        no_dir, OPT_iwithprefixbefore)
> @@ -1318,6 +1321,10 @@ cpp_handle_option (pfile, argc, argv)
>  	case OPT_iprefix:
>  	  CPP_OPTION (pfile, include_prefix) = arg;
>  	  CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
> +	  break;
> +
> +	case OPT_isysroot:
> +	  CPP_OPTION (pfile, sysroot) = arg;
>  	  break;
>  
>  	case OPT_A:
> Index: gcc/cpplib.h
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
> retrieving revision 1.234.4.2
> diff -u -p -r1.234.4.2 cpplib.h
> --- gcc/cpplib.h	1 Oct 2002 17:31:41 -0000	1.234.4.2
> +++ gcc/cpplib.h	12 Nov 2002 18:29:54 -0000
> @@ -240,6 +240,10 @@ struct cpp_options
>    const char *include_prefix;
>    unsigned int include_prefix_len;
>  
> +  /* Directory prefix for system include directories in the standard search
> +     path.  */
> +  const char *sysroot;
> +
>    /* The language we're preprocessing.  */
>    enum c_lang lang;
>  
> Index: gcc/gcc.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
> retrieving revision 1.336.4.10
> diff -u -p -r1.336.4.10 gcc.c
> --- gcc/gcc.c	21 Oct 2002 17:51:57 -0000	1.336.4.10
> +++ gcc/gcc.c	12 Nov 2002 18:29:59 -0000
> @@ -202,6 +202,10 @@ static int report_times;
>  
>  static const char *target_system_root = TARGET_SYSTEM_ROOT;
>  
> +/* Nonzero means pass the updated target_system_root to the compiler.  */
> +
> +static int target_system_root_changed;
> +
>  /* Nonzero means write "temp" files in source directory
>     and use the source file's name in them, and don't delete them.  */
>  
> @@ -440,7 +444,9 @@ or with constant text in a single argume
>   %P	like %p, but puts `__' before and after the name of each macro.
>  	(Except macros that already have __.)
>  	This is for ANSI C.
> - %I	Substitute a -iprefix option made from GCC_EXEC_PREFIX.
> + %I	Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot
> +	(made from TARGET_SYSTEM_ROOT), and -isystem (made from COMPILER_PATH
> +	and -B options) as necessary.
>   %s     current argument is the name of a library or startup file of some sort.
>          Search for that file in a standard list of directories
>  	and substitute the full name found.
> @@ -2525,7 +2531,7 @@ make_relative_prefix (progname, bin_pref
>      obstack_grow (&obstack, prog_dirs[i], strlen (prog_dirs[i]));
>  
>    /* Now build up the ..'s.  */
> -  for (i = common; i < n; i++)
> +  for (i = common; i < bin_num; i++)
>      {
>        obstack_grow (&obstack, DIR_UP, sizeof (DIR_UP) - 1);
>        obstack_1grow (&obstack, DIR_SEPARATOR);
> @@ -3976,14 +3982,23 @@ warranty; not even for MERCHANTABILITY o
>  	      concat (tooldir_prefix, "lib", dir_separator_str, NULL),
>  	      "BINUTILS", PREFIX_PRIORITY_LAST, 0, NULL, 1);
>  
> +#if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS)
> +  /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix,
> +     then consider it to relocate with the rest of the GCC installation
> +     if GCC_EXEC_PREFIX is set.
> +     ``make_relative_prefix'' is not compiled for VMS, so don't call it.  */
>    if (target_system_root && gcc_exec_prefix)
>      {
>        char *tmp_prefix = make_relative_prefix (argv[0],
>  					       standard_bindir_prefix,
>  					       target_system_root);
>        if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0)
> -	target_system_root = tmp_prefix;
> +	{
> +	  target_system_root = tmp_prefix;
> +	  target_system_root_changed = 1;
> +	}
>      }
> +#endif
>  
>    /* More prefixes are enabled in main, after we read the specs file
>       and determine whether this is cross-compilation or not.  */
> @@ -4878,6 +4893,15 @@ do_spec_1 (spec, inswitch, soft_matched_
>  		  /* Make this a separate argument.  */
>  		  do_spec_1 (" ", 0, NULL);
>  		  do_spec_1 (gcc_exec_prefix, 1, NULL);
> +		  do_spec_1 (" ", 0, NULL);
> +		}
> +
> +	      if (target_system_root_changed)
> +		{
> +		  do_spec_1 ("-isysroot", 1, NULL);
> +		  /* Make this a separate argument.  */
> +		  do_spec_1 (" ", 0, NULL);
> +		  do_spec_1 (target_system_root, 1, NULL);
>  		  do_spec_1 (" ", 0, NULL);
>  		}
>  
> Index: gcc/doc/install.texi
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/doc/install.texi,v
> retrieving revision 1.136.2.8
> diff -u -p -r1.136.2.8 install.texi
> --- gcc/doc/install.texi	10 Nov 2002 01:13:53 -0000	1.136.2.8
> +++ gcc/doc/install.texi	12 Nov 2002 18:30:08 -0000
> @@ -891,16 +891,9 @@ searched in there.  The specified direct
>  install tree, unlike the options @option{--with-headers} and
>  @option{--with-libs} that this option obsoletes.  The default value,
>  in case @option{--with-sysroot} is not given an argument, is
> -@option{$@{gcc_tooldir@}/sys-root}.  Starting the pathname with
> -@option{$@{gcc_tooldir@}/}, in such a way that this variable is not
> -expanded by the shell, but rather by the gcc Makefile, enables the
> -target sysroot directory to be relocatable along with the entire
> -install tree, but it will require the gcc tool directory to be created
> -@emph{before} the build is started.  This directory, as well as its
> -intermediate pathnames, can be easily created by running @command{make
> -install-gcc-tooldir} the gcc build directory.  This is not done
> -automatically to avoid touching the install tree without explicit
> -permission.
> +@option{$@{gcc_tooldir@}/sys-root}.  If the specified directory is a
> +subdirectory of @option{$@{exec_prefix@}}, then it will be found relative to
> +the GCC binaries if the installation tree is moved.
>  
>  @item --with-headers
>  @itemx --with-headers=@var{dir}
> Index: gcc/doc/invoke.texi
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
> retrieving revision 1.175.2.8
> diff -u -p -r1.175.2.8 invoke.texi
> --- gcc/doc/invoke.texi	5 Nov 2002 19:12:25 -0000	1.175.2.8
> +++ gcc/doc/invoke.texi	12 Nov 2002 18:30:18 -0000
> @@ -4840,7 +4840,10 @@ predefined macro, except for macros that
>  C@.
>  
>  @item %I
> -Substitute a @option{-iprefix} option made from @env{GCC_EXEC_PREFIX}.
> +Substitute any of @option{-iprefix} (made from @env{GCC_EXEC_PREFIX}),
> +@option{-isysroot} (made from @env{TARGET_SYSTEM_ROOT}), and
> +@option{-isystem} (made from @env{COMPILER_PATH} and @option{-B} options)
> +as necessary.
>  
>  @item %s
>  Current argument is the name of a library or startup file of some sort.
> 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-14 13:25   ` Daniel Jacobowitz
@ 2002-12-07  8:44     ` Neil Booth
  0 siblings, 0 replies; 19+ messages in thread
From: Neil Booth @ 2002-12-07  8:44 UTC (permalink / raw)
  To: gcc-patches

Daniel Jacobowitz wrote:-

> Would a global write maintainer mind reviewing these changes?

Please, I'd like to see this in bib.

Neil.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Updates to --with-sysroot support
  2002-11-12 11:40 ` Daniel Jacobowitz
  2002-11-14 13:25   ` Daniel Jacobowitz
@ 2002-12-13 12:20   ` Neil Booth
  1 sibling, 0 replies; 19+ messages in thread
From: Neil Booth @ 2002-12-13 12:20 UTC (permalink / raw)
  To: gcc-patches, Alexandre Oliva, Geoff Keating

Daniel Jacobowitz wrote:-

> I'm resending this patch with a couple of additions; I think this
> addresses all concerns.
> 
> On Mon, Nov 04, 2002 at 11:57:29AM -0500, Daniel Jacobowitz wrote:
> > I spent a couple days working with this and finally found a solution for
> > (most of) my concerns.  This patch:
> > 
> >  - Fixes an undocumented behavior in cppinit.c which I consider to be a bug.
> >    If -iprefix was used to change the compiler prefix, then first the
> >    standard include directories which begin with the prefix were searched
> >    (using the relocated prefix); then all directories were searched in order
> >    (using the original prefix).  This means that -iprefix'd versions of
> >    GCC_INCLUDE_DIR (that's -iprefix's prefix followed by "include", folks)
> >    would be searched before GPLUSPLUS_INCLUDE_DIR.  Oops.
> >    I changed this so that the order is preserved, and unrelocated versions
> >    are not searched.  This means that people who were using -iprefix and
> >    still expecting to get GCC's <stddef.h> et al. from the normal location
> >    are out of luck; they'll have to specify that path as an -isystem
> >    explicitly.  I think this change is correct but I'd like a second
> >    opinion.
> 
> Neil and Zack seemed to agree with me on this one, whew.

Daniel,

Would you commit your CPP changes to BIB?  I am changing include
handling (you probably already have a merge conflict, but I've not
touched what you touched) and I don't want to wait any longer for
these nice improvements.

Thanks,

Neil.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2002-12-13 20:20 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-04  8:56 Updates to --with-sysroot support Daniel Jacobowitz
2002-11-04  9:08 ` Jason R Thorpe
2002-11-04 10:26 ` Hans-Peter Nilsson
2002-11-04 10:30   ` Daniel Jacobowitz
2002-11-06  9:07     ` Alexandre Oliva
2002-11-04 23:29 ` Zack Weinberg
2002-11-05  6:30   ` Daniel Jacobowitz
2002-11-05 10:51   ` Geoff Keating
2002-11-06  9:15 ` Alexandre Oliva
2002-11-06  9:30   ` Daniel Jacobowitz
2002-11-06 10:04     ` Alexandre Oliva
2002-11-06 10:14       ` Daniel Jacobowitz
2002-11-06 12:49         ` Alexandre Oliva
2002-11-06 12:59           ` Daniel Jacobowitz
2002-11-06 13:30             ` Alexandre Oliva
2002-11-12 11:40 ` Daniel Jacobowitz
2002-11-14 13:25   ` Daniel Jacobowitz
2002-12-07  8:44     ` Neil Booth
2002-12-13 12:20   ` Neil Booth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).