This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
- From: Andi Kleen <andi at firstfloor dot org>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Andi Kleen <ak at linux dot intel dot com>
- Date: Mon, 4 Aug 2014 07:29:46 -0700
- Subject: [PATCH 1/2] Add -B support to gcc-ar/ranlib/nm
- Authentication-results: sourceware.org; auth=none
- References: <1407162587-5210-1-git-send-email-andi at firstfloor dot org>
From: Andi Kleen <ak@linux.intel.com>
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-08-04 Andi Kleen <ak@linux.intel.com>
* gcc-ar.c (main): Support -B option.
---
gcc/gcc-ar.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/gcc/gcc-ar.c b/gcc/gcc-ar.c
index aebaa92..372e087 100644
--- a/gcc/gcc-ar.c
+++ b/gcc/gcc-ar.c
@@ -132,9 +132,50 @@ 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;
+
+ memmove (av + i, av + i + 1, sizeof (char *) * ((ac + 1) - i));
+ ac--;
+ if (*arg == 0)
+ {
+ arg = av[i] + 1;
+ 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++;
+ }
+
+ for (end = arg; *end; end++)
+ ;
+ end--;
+ if (end > arg && *end != '/')
+ {
+ char *newarg = (char *)xmalloc (strlen(arg) + 2);
+
+ strcpy (newarg, arg);
+ strcat (newarg, "/");
+ arg = newarg;
+ }
+
+ add_prefix (&path, arg);
+ add_prefix (&target_path, arg);
+ break;
+ }
+
+
/* Find the GCC LTO plugin */
plugin = find_a_file (&target_path, LTOPLUGINSONAME, R_OK);
if (!plugin)
--
2.0.1