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

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).