Updates to --with-sysroot support
Daniel Jacobowitz
drow@mvista.com
Tue Nov 12 11:40:00 GMT 2002
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.
More information about the Gcc-patches
mailing list