This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Clearly report used sysroot


Hi,
presently, there's no easy way to ask gdb about the directory
where it expects target sysroot to be located. The issue is
complicated by the fact that the path is the concatenation
of target_system_root and target_sysroot_suffix. The former
is specified either at configure time, or with the --sysroot
option, and the latter depends on used compilation options.

Presently, there are only two ways to get this information:

	- Parse the output of -v
	- Parse the specs

Neither of those approaches is very nice. This patch introduces
-print-specific-sysroot option that just outputs the right path.
I've tested with arm-linux toolchain, and it seem to work fine.
This patch needs some tweaks, like adding the option to help,
but does the overall approach seem sane?

Tested by hand arm-linux with several multilibs.

OK?

	[gcc]
	* gcc.c (print_sysroot): New.
	(option_map, display_help, process_command): Handle the
	-print-sysroot option.
	(main): Print the sysroot if requested.

	[gcc/doc]
	* invoke.texi (Debugging Options): Document -print-sysroot.

- Volodya
Index: src/gcc-4.2/gcc/doc/invoke.texi
===================================================================
--- src/gcc-4.2/gcc/doc/invoke.texi	(revision 208779)
+++ src/gcc-4.2/gcc/doc/invoke.texi	(working copy)
@@ -300,7 +300,7 @@
 -p  -pg  -print-file-name=@var{library}  -print-libgcc-file-name @gol
 -print-multi-directory  -print-multi-lib @gol
 -print-prog-name=@var{program}  -print-search-dirs  -Q @gol
--print-sysroot-headers-suffix @gol
+-print-sysroot -print-sysroot-headers-suffix @gol
 -save-temps  -time}
 
 @item Optimization Options
@@ -4529,6 +4529,14 @@
 Don't forget the trailing @samp{/}.
 @xref{Environment Variables}.
 
+@item -print-sysroot
+@opindex print-sysroot
+Print the target sysroot directory that will be used during
+compilation.  This is the target sysroot specified either at configure
+time or or using the @option{--sysroot} option, possibly with an extra
+suffix that depends on compilation options.  If no target sysroot is
+specified, the options prints nothing.
+
 @item -print-sysroot-headers-suffix
 @opindex print-sysroot-headers-suffix
 Print the suffix added to the target sysroot when searching for
Index: src/gcc-4.2/gcc/gcc.c
===================================================================
--- src/gcc-4.2/gcc/gcc.c	(revision 208779)
+++ src/gcc-4.2/gcc/gcc.c	(working copy)
@@ -162,6 +162,8 @@
 
 static int print_multi_directory;
 
+static int print_sysroot;
+
 /* Flag saying to print the relative path we'd use to
    find OS libraries given the current compiler flags.  */
 
@@ -1173,6 +1175,7 @@
    {"--print-multi-directory", "-print-multi-directory", 0},
    {"--print-multi-os-directory", "-print-multi-os-directory", 0},
    {"--print-prog-name", "-print-prog-name=", "aj"},
+   {"--print-sysroot", "-print-sysroot", 0},
    {"--print-sysroot-headers-suffix", "-print-sysroot-headers-suffix", 0},
    {"--profile", "-p", 0},
    {"--profile-blocks", "-a", 0},
@@ -3241,6 +3244,7 @@
   -print-multi-lib         Display the mapping between command line options and\n\
                            multiple library search directories\n"), stdout);
   fputs (_("  -print-multi-os-directory Display the relative path to OS libraries\n"), stdout);
+  fputs (_("  -print-sysroot           Display the target libraries directory\n"), stdout);
   fputs (_("  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers\n"), stdout);
   fputs (_("  -Wa,<options>            Pass comma-separated <options> on to the assembler\n"), stdout);
   fputs (_("  -Wp,<options>            Pass comma-separated <options> on to the preprocessor\n"), stdout);
@@ -3680,6 +3684,8 @@
 	print_multi_lib = 1;
       else if (! strcmp (argv[i], "-print-multi-directory"))
 	print_multi_directory = 1;
+      else if (! strcmp (argv[i], "-print-sysroot"))
+	print_sysroot = 1;
       else if (! strcmp (argv[i], "-print-multi-os-directory"))
 	print_multi_os_directory = 1;
       else if (! strcmp (argv[i], "-print-sysroot-headers-suffix"))
@@ -4134,6 +4140,8 @@
 	;
       else if (! strcmp (argv[i], "-print-multi-directory"))
 	;
+      else if (! strcmp (argv[i], "-print-sysroot"))
+	;
       else if (! strcmp (argv[i], "-print-multi-os-directory"))
 	;
       else if (! strcmp (argv[i], "-print-sysroot-headers-suffix"))
@@ -6555,6 +6563,18 @@
       return (0);
     }
 
+  if (print_sysroot)
+    {
+      if (target_system_root)
+	{
+          if (target_sysroot_suffix)
+	    printf ("%s%s\n", target_system_root, target_sysroot_suffix);
+          else
+	    printf ("%s\n", target_system_root);
+	}
+      return (0);
+    }
+
   if (print_multi_os_directory)
     {
       if (multilib_os_dir == NULL)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]