Add -B support to gcc-ar/ranlib/nm
authorak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 1 Sep 2014 16:41:17 +0000 (16:41 +0000)
committerak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 1 Sep 2014 16:41:17 +0000 (16:41 +0000)
To use gcc-{ar,ranlib} for boot strap we need to add a -B option
to the tool. Since ar has weird and unusual argument conventions
implement the code by hand instead of using any libraries.

gcc/:

2014-09-01  Andi Kleen  <ak@linux.intel.com>

* file-find.c (add_prefix_begin): Add.
(do_add_prefix): Rename from add_prefix with first argument.
(add_prefix): Add new wrapper.
* file-find.h (add_prefix_begin): Add.
* gcc-ar.c (main): Support -B option.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@214800 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/file-find.c
gcc/file-find.h
gcc/gcc-ar.c

index 7b5548a..ce0f3bb 100644 (file)
@@ -1,3 +1,11 @@
+2014-09-01  Andi Kleen  <ak@linux.intel.com>
+
+       * file-find.c (add_prefix_begin): Add.
+       (do_add_prefix): Rename from add_prefix with first argument.
+       (add_prefix): Add new wrapper.
+       * file-find.h (add_prefix_begin): Add.
+       * gcc-ar.c (main): Support -B option.
+
 2014-09-01  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * genemit.c: Include dumpfile.h.
index 87d486d..be608b2 100644 (file)
@@ -105,15 +105,16 @@ find_a_file (struct path_prefix *pprefix, const char *name, int mode)
   return 0;
 }
 
-/* Add an entry for PREFIX to prefix list PPREFIX.  */
+/* Add an entry for PREFIX to prefix list PREFIX.
+   Add at beginning if FIRST is true.  */
 
 void
-add_prefix (struct path_prefix *pprefix, const char *prefix)
+do_add_prefix (struct path_prefix *pprefix, const char *prefix, bool first)
 {
   struct prefix_list *pl, **prev;
   int len;
 
-  if (pprefix->plist)
+  if (pprefix->plist && !first)
     {
       for (pl = pprefix->plist; pl->next; pl = pl->next)
        ;
@@ -138,6 +139,22 @@ add_prefix (struct path_prefix *pprefix, const char *prefix)
   *prev = pl;
 }
 
+/* Add an entry for PREFIX at the end of prefix list PREFIX.  */
+
+void
+add_prefix (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, false);
+}
+
+/* Add an entry for PREFIX at the begin of prefix list PREFIX.  */
+
+void
+add_prefix_begin (struct path_prefix *pprefix, const char *prefix)
+{
+  do_add_prefix (pprefix, prefix, true);
+}
+
 /* Take the value of the environment variable ENV, break it into a path, and
    add of the entries to PPREFIX.  */
 
index b438056..0754d99 100644 (file)
@@ -40,6 +40,7 @@ struct path_prefix
 extern void find_file_set_debug (bool);
 extern char *find_a_file (struct path_prefix *, const char *, int);
 extern void add_prefix (struct path_prefix *, const char *);
+extern void add_prefix_begin (struct path_prefix *, const char *);
 extern void prefix_from_env (const char *, struct path_prefix *);
 extern void prefix_from_string (const char *, struct path_prefix *);
 
index aebaa92..fdff89c 100644 (file)
@@ -132,9 +132,52 @@ main (int ac, char **av)
   const char **nargv;
   bool is_ar = !strcmp (PERSONALITY, "ar");
   int exit_code = FATAL_EXIT_CODE;
+  int i;
 
   setup_prefixes (av[0]);
 
+  /* Not using getopt for now.  */
+  for (i = 0; i < ac; i++)
+      if (!strncmp (av[i], "-B", 2))
+       {
+         const char *arg = av[i] + 2;
+         const char *end;
+         size_t len;
+
+         memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+         ac--;
+         if (*arg == 0)
+           {
+             arg = av[i];
+             if (!arg)
+               {
+                 fprintf (stderr, "Usage: gcc-ar [-B prefix] ar arguments ...\n");
+                 exit (EXIT_FAILURE);
+               }
+             memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+             ac--;
+             i++;
+           }
+         /* else it's a joined argument  */
+
+         len = strlen (arg);
+         if (len > 0)
+                 len--;
+         end = arg + len;
+
+         /* Always add a dir separator for the prefix list.  */
+         if (end > arg && !IS_DIR_SEPARATOR (*end))
+           {
+             static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
+             arg = concat (arg, dir_separator_str, NULL);
+           }
+
+         add_prefix_begin (&path, arg);
+         add_prefix_begin (&target_path, arg);
+         break;
+       }
+
+
   /* Find the GCC LTO plugin */
   plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
   if (!plugin)