OSDN Git Service

add sparc64-*-solaris2 support just like sparcv9-*-solaris2
[pf3gnuchains/gcc-fork.git] / gcc / gcc.c
index 1ba86ee..cbf62f8 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -2,22 +2,22 @@
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2001 Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
 
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
 
 This paragraph is here to try to keep Sun CC from dying.
 The number of chars here seems crucial!!!!  */
@@ -185,7 +185,7 @@ static int print_help_list;
 
 static int verbose_flag;
 
-/* Flag indicating to print target specific command line options. */
+/* Flag indicating to print target specific command line options.  */
 
 static int target_help_flag;
 
@@ -663,7 +663,7 @@ static const char *cc1_options =
  %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
  %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*} %{ansi}\
  %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
- %{aux-info*} %{Qn:-fno-ident} %{--help:--help}\
+ %{Qn:-fno-ident} %{--help:--help}\
  %{--target-help:--target-help}\
  %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
  %{fsyntax-only:-o %j} %{-param*}";
@@ -952,6 +952,18 @@ struct option_map option_map[] =
    {"--", "-f", "*j"}
  };
 \f
+
+#ifdef TARGET_OPTION_TRANSLATE_TABLE
+static struct {
+  const char *option_found;
+  const char *replacements;
+} target_option_translations[] =
+{
+  TARGET_OPTION_TRANSLATE_TABLE,
+  { 0, 0 }
+};
+#endif
+
 /* Translate the options described by *ARGCP and *ARGVP.
    Make a new vector and store it back in *ARGVP,
    and store its length in *ARGVC.  */
@@ -964,8 +976,9 @@ translate_options (argcp, argvp)
   int i;
   int argc = *argcp;
   const char *const *argv = *argvp;
+  int newvsize = (argc + 2) * 2 * sizeof (const char *);
   const char **newv =
-    (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
+    (const char **) xmalloc (newvsize);
   int newindex = 0;
 
   i = 0;
@@ -973,6 +986,56 @@ translate_options (argcp, argvp)
 
   while (i < argc)
     {
+#ifdef TARGET_OPTION_TRANSLATE_TABLE
+      int tott_idx;
+
+      for (tott_idx = 0;
+          target_option_translations[tott_idx].option_found;
+          tott_idx++)
+       {
+         if (strcmp (target_option_translations[tott_idx].option_found,
+                     argv[i]) == 0)
+           {
+             int spaces = 1;
+             const char *sp;
+             char *np;
+
+             for (sp = target_option_translations[tott_idx].replacements;
+                  *sp; sp++)
+               {
+                 if (*sp == ' ')
+                   spaces ++;
+               }
+
+             newvsize += spaces * sizeof (const char *);
+             newv = (const char **) xrealloc (newv, newvsize);
+
+             sp = target_option_translations[tott_idx].replacements;
+             np = (char *) xmalloc (strlen (sp) + 1);
+             strcpy (np, sp);
+
+             while (1)
+               {
+                 while (*np == ' ')
+                   np++;
+                 if (*np == 0)
+                   break;
+                 newv[newindex++] = np;
+                 while (*np != ' ' && *np)
+                   np++;
+                 if (*np == 0)
+                   break;
+                 *np++ = 0;
+               }
+
+             i ++;
+             break;
+           }
+       }
+      if (target_option_translations[tott_idx].option_found)
+       continue;
+#endif
+
       /* Translate -- options.  */
       if (argv[i][0] == '-' && argv[i][1] == '-')
        {
@@ -1142,7 +1205,7 @@ skip_whitespace (p)
 
 struct prefix_list
 {
-  char *prefix;               /* String to prepend to the path.  */
+  const char *prefix;        /* String to prepend to the path.  */
   struct prefix_list *next;   /* Next in linked list.  */
   int require_machine_suffix; /* Don't use without machine_suffix.  */
   /* 2 means try both machine_suffix and just_machine_suffix.  */
@@ -1323,15 +1386,15 @@ init_gcc_specs (obstack, shared_name, static_name)
   char buffer[128];
 
   /* If we see -shared-libgcc, then use the shared version.  */
-  sprintf (buffer, "%%{shared-libgcc:%s}", shared_name);
+  sprintf (buffer, "%%{shared-libgcc:%s %s}", shared_name, static_name);
   obstack_grow (obstack, buffer, strlen (buffer));
   /* If we see -static-libgcc, then use the static version.  */
   sprintf (buffer, "%%{static-libgcc:%s}", static_name);
   obstack_grow (obstack, buffer, strlen (buffer));
   /* Otherwise, if we see -shared, then use the shared version.  */
   sprintf (buffer,
-          "%%{!shared-libgcc:%%{!static-libgcc:%%{shared:%s}}}", 
-          shared_name);
+          "%%{!shared-libgcc:%%{!static-libgcc:%%{shared:%s %s}}}", 
+          shared_name, static_name);
   obstack_grow (obstack, buffer, strlen (buffer));
   /* Otherwise, use the static version.  */
   sprintf (buffer, 
@@ -1454,6 +1517,15 @@ init_spec ()
     libgcc_spec = obstack_finish (&obstack);
   }
 #endif
+#ifdef USE_AS_TRADITIONAL_FORMAT
+  /* Prepend "--traditional-format" to whatever asm_spec we had before.  */
+  {
+    static char tf[] = "--traditional-format ";
+    obstack_grow (&obstack, tf, sizeof(tf) - 1);
+    obstack_grow0 (&obstack, asm_spec, strlen (asm_spec));
+    asm_spec = obstack_finish (&obstack);
+  }
+#endif
 
   specs = sl;
 }
@@ -2213,8 +2285,12 @@ make_relative_prefix (progname, bin_prefix, prefix)
       GET_ENV_PATH_LIST (temp, "PATH");
       if (temp)
        {
-         char *startp, *endp;
-         char *nstore = (char *) alloca (strlen (temp) + strlen (progname) + 1);
+         char *startp, *endp, *nstore;
+         size_t prefixlen = strlen (temp) + 1;
+         if (prefixlen < 2)
+           prefixlen = 2;
+
+         nstore = (char *) alloca (prefixlen + strlen (progname) + 1);
 
          startp = endp = temp;
          while (1)
@@ -2535,7 +2611,7 @@ add_prefix (pprefix, prefix, component, priority, require_machine_suffix, warn)
     pprefix->max_len = len;
 
   pl = (struct prefix_list *) xmalloc (sizeof (struct prefix_list));
-  pl->prefix = save_string (prefix, len);
+  pl->prefix = prefix;
   pl->require_machine_suffix = require_machine_suffix;
   pl->used_flag_ptr = warn;
   pl->priority = priority;
@@ -2795,7 +2871,7 @@ struct infile
 
 static struct infile *infiles;
 
-static int n_infiles;
+int n_infiles;
 
 /* This counts the number of libraries added by lang_specific_driver, so that
    we can tell if there were any user supplied any files or libraries.  */
@@ -2804,7 +2880,7 @@ static int added_libraries;
 
 /* And a vector of corresponding output files is made up later.  */
 
-static const char **outfiles;
+const char **outfiles;
 
 /* Used to track if none of the -B paths are used.  */
 static int warn_B;
@@ -2860,7 +2936,8 @@ convert_filename (name, do_exe)
       return name;
 
   obstack_grow (&obstack, name, len);
-  obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, strlen (TARGET_EXECUTABLE_SUFFIX));
+  obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX,
+                strlen (TARGET_EXECUTABLE_SUFFIX));
   name = obstack_finish (&obstack);
 #endif
 
@@ -3207,7 +3284,7 @@ process_command (argc, argv)
        }
       else if (strcmp (argv[i], "-ftarget-help") == 0)
         {
-          /* translate_options() has turned --target-help into -ftarget-help. */
+          /* translate_options() has turned --target-help into -ftarget-help.  */
           target_help_flag = 1;
 
           /* We will be passing a dummy file on to the sub-processes.  */
@@ -3356,36 +3433,57 @@ process_command (argc, argv)
            case 'B':
              {
                const char *value;
+               int len;
+
                if (p[1] == 0 && i + 1 == argc)
                  fatal ("argument to `-B' is missing");
                if (p[1] == 0)
                  value = argv[++i];
                else
                  value = p + 1;
-               {
-                 /* As a kludge, if the arg is "[foo/]stageN/", just
-                    add "[foo/]include" to the include prefix.  */
-                 int len = strlen (value);
-                 if ((len == 7
-                      || (len > 7
-                          && (IS_DIR_SEPARATOR (value[len - 8]))))
-                     && strncmp (value + len - 7, "stage", 5) == 0
-                     && ISDIGIT (value[len - 2])
-                     && (IS_DIR_SEPARATOR (value[len - 1])))
-                   {
-                     if (len == 7)
-                       add_prefix (&include_prefixes, "include", NULL,
+
+               len = strlen (value);
+
+               /* Catch the case where the user has forgotten to append a
+                  directory seperator to the path.  Note, they may be using
+                  -B to add an executable name prefix, eg "i386-elf-", in
+                  order to distinguish between multiple installations of
+                  GCC in the same directory.  Hence we must check to see
+                  if appending a directory separator actually makes a
+                  valid directory name.  */
+               if (! IS_DIR_SEPARATOR (value [len - 1])
+                   && is_directory (value, "", 0))
+                 {
+                   char *tmp = xmalloc (len + 2);
+                   strcpy (tmp, value);
+                   tmp[len] = DIR_SEPARATOR;
+                   tmp[++ len] = 0;
+                   value = tmp;
+                 }
+               
+               /* As a kludge, if the arg is "[foo/]stageN/", just
+                  add "[foo/]include" to the include prefix.  */
+               if ((len == 7
+                    || (len > 7
+                        && (IS_DIR_SEPARATOR (value[len - 8]))))
+                   && strncmp (value + len - 7, "stage", 5) == 0
+                   && ISDIGIT (value[len - 2])
+                   && (IS_DIR_SEPARATOR (value[len - 1])))
+                 {
+                   if (len == 7)
+                     add_prefix (&include_prefixes, "include", NULL,
+                                 PREFIX_PRIORITY_B_OPT, 0, NULL);
+                   else
+                     {
+                       char * string = xmalloc (len + 1);
+
+                       strncpy (string, value, len - 7);
+                       strcpy (string + len - 7, "include");
+                       add_prefix (&include_prefixes, string, NULL,
                                    PREFIX_PRIORITY_B_OPT, 0, NULL);
-                     else
-                       {
-                         char *string = xmalloc (len + 1);
-                         strncpy (string, value, len-7);
-                         strcpy (string+len-7, "include");
-                         add_prefix (&include_prefixes, string, NULL,
-                                     PREFIX_PRIORITY_B_OPT, 0, NULL);
-                       }
-                   }
-               }
+                     }
+                 }
+
                add_prefix (&exec_prefixes, value, NULL,
                            PREFIX_PRIORITY_B_OPT, 0, &warn_B);
                add_prefix (&startfile_prefixes, value, NULL,
@@ -3479,9 +3577,9 @@ process_command (argc, argv)
                              have_c = 1;
                              break;
                            }
-                         else if (skip = SWITCH_TAKES_ARG (argv[j][1]))
+                         else if ((skip = SWITCH_TAKES_ARG (argv[j][1])))
                            j += skip - (argv[j][2] != 0);
-                         else if (skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1))
+                         else if ((skip = WORD_SWITCH_TAKES_ARG (argv[j] + 1)))
                            j += skip;
                        }
                      j++;
@@ -3910,7 +4008,7 @@ static int this_is_library_file;
 static int input_from_pipe;
 
 /* Nonnull means substitute this for any suffix when outputting a switches
-   arguments. */
+   arguments.  */
 static const char *suffix_subst;
 
 /* Process the spec SPEC and run the commands specified therein.
@@ -4287,7 +4385,8 @@ do_spec_1 (spec, inswitch, soft_matched_part)
                      && t->unique == (c != 'g'))
                    break;
 
-               /* Make a new association if needed.  %u and %j require one.  */
+               /* Make a new association if needed.  %u and %j
+                  require one.  */
                if (t == 0 || c == 'u' || c == 'j')
                  {
                    if (t == 0)
@@ -4297,7 +4396,13 @@ do_spec_1 (spec, inswitch, soft_matched_part)
                        temp_names = t;
                      }
                    t->length = suffix_length;
-                   t->suffix = save_string (suffix, suffix_length);
+                   if (saved_suffix)
+                     {
+                       t->suffix = saved_suffix;
+                       saved_suffix = NULL;
+                     }
+                   else
+                     t->suffix = save_string (suffix, suffix_length);
                    t->unique = (c != 'g');
                    temp_filename = make_temp_file (t->suffix);
                    temp_filename_length = strlen (temp_filename);
@@ -4987,7 +5092,7 @@ next_member:
              else if (*q == '}')
                count--;
              else if (*q == 0)
-               abort ();
+               fatal ("Mismatched braces in specs");
              q++;
            }
          endbody = q;
@@ -5280,19 +5385,19 @@ give_switch (switchnum, omit_first_word, include_blanks)
          if (suffix_subst)
            {
              unsigned length = strlen (arg);
+             int dot = 0;
 
              while (length-- && !IS_DIR_SEPARATOR (arg[length]))
                if (arg[length] == '.')
                  {
                    ((char *)arg)[length] = 0;
+                   dot = 1;
                    break;
                  }
              do_spec_1 (arg, 1, NULL);
-             if (!arg[length])
-               {
-                 ((char *)arg)[length] = '.';
-                 do_spec_1 (suffix_subst, 1, NULL);
-               }
+             if (dot)
+               ((char *)arg)[length] = '.';
+             do_spec_1 (suffix_subst, 1, NULL);
            }
          else
            do_spec_1 (arg, 1, NULL);
@@ -5778,7 +5883,7 @@ main (argc, argv)
       /* We do not exit here. Instead we have created a fake input file
          called 'target-dummy' which needs to be compiled, and we pass this
          on to the various sub-processes, along with the --target-help
-         switch. */
+         switch.  */
     }
 
   if (print_help_list)
@@ -6099,20 +6204,12 @@ fancy_abort ()
 void
 fatal VPARAMS ((const char *msgid, ...))
 {
-#ifndef ANSI_PROTOTYPES
-  const char *msgid;
-#endif
-  va_list ap;
-
-  VA_START (ap, msgid);
-
-#ifndef ANSI_PROTOTYPES
-  msgid = va_arg (ap, const char *);
-#endif
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
 
   fprintf (stderr, "%s: ", programname);
   vfprintf (stderr, _(msgid), ap);
-  va_end (ap);
+  VA_CLOSE (ap);
   fprintf (stderr, "\n");
   delete_temp_files ();
   exit (1);
@@ -6121,20 +6218,12 @@ fatal VPARAMS ((const char *msgid, ...))
 void
 error VPARAMS ((const char *msgid, ...))
 {
-#ifndef ANSI_PROTOTYPES
-  const char *msgid;
-#endif
-  va_list ap;
-
-  VA_START (ap, msgid);
-
-#ifndef ANSI_PROTOTYPES
-  msgid = va_arg (ap, const char *);
-#endif
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
 
   fprintf (stderr, "%s: ", programname);
   vfprintf (stderr, _(msgid), ap);
-  va_end (ap);
+  VA_CLOSE (ap);
 
   fprintf (stderr, "\n");
 }
@@ -6142,19 +6231,11 @@ error VPARAMS ((const char *msgid, ...))
 static void
 notice VPARAMS ((const char *msgid, ...))
 {
-#ifndef ANSI_PROTOTYPES
-  const char *msgid;
-#endif
-  va_list ap;
-
-  VA_START (ap, msgid);
-
-#ifndef ANSI_PROTOTYPES
-  msgid = va_arg (ap, const char *);
-#endif
+  VA_OPEN (ap, msgid);
+  VA_FIXEDARG (ap, const char *, msgid);
 
   vfprintf (stderr, _(msgid), ap);
-  va_end (ap);
+  VA_CLOSE (ap);
 }
 \f
 static void