]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/gcc.c
*** empty log message ***
[gcc.git] / gcc / gcc.c
index 16eda227e47eee85ea01b4e194ee11c7cd195fb9..6a6449d679caa53361e8d0961440ab44bd0fdc37 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -34,20 +34,19 @@ compilation is specified by a string called a "spec".  */
 #include <sys/types.h>
 #include <ctype.h>
 #include <signal.h>
-#include <sys/file.h>
 #include <sys/stat.h>
 
 #include "config.h"
 #include "obstack.h"
 #include "gvarargs.h"
 
-#ifdef USG
 #ifndef R_OK
 #define R_OK 4
 #define W_OK 2
 #define X_OK 1
 #endif
 
+#ifdef USG
 #define vfork fork
 #endif /* USG */
 
@@ -71,11 +70,12 @@ compilation is specified by a string called a "spec".  */
 
 /* By default there is no special suffix for executables.  */
 #ifndef EXECUTABLE_SUFFIX
-#if __MSDOS__
-#define EXECUTABLE_SUFFIX ".exe"
-#else
 #define EXECUTABLE_SUFFIX ""
 #endif
+
+/* By default, colon separates directories in a path.  */
+#ifndef PATH_SEPARATOR
+#define PATH_SEPARATOR ':'
 #endif
 
 #define obstack_chunk_alloc xmalloc
@@ -125,7 +125,7 @@ static int cross_compile = 0;
 static struct obstack obstack;
 
 /* This is the obstack to build an environment variable to pass to
-   collect2 that describes all of the relavant switches of what to
+   collect2 that describes all of the relevant switches of what to
    pass the compiler in building the list of pointers to constructors
    and destructors.  */
 
@@ -237,7 +237,7 @@ or with constant text in a single argument.
  %{S*:X} substitutes X if one or more switches whose names with -S are
        specified to CC.  Note that the tail part of the -S option
        (i.e. the part matched by the `*') will be substituted for each
-       occurance of %* within X.
+       occurrence of %* within X.
  %{S:X} substitutes X, but only if the -S switch was given to CC.
  %{!S:X} substitutes X, but only if the -S switch was NOT given to CC.
  %{|S:X} like %{S:X}, but if no S switch, substitute `-'.
@@ -395,7 +395,7 @@ static struct compiler default_compilers[] =
 {
   {".c", "@c"},
   {"@c",
-   "cpp -lang-c %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+   "cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C does not support -C without using -E}}\
        %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
         -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
@@ -415,7 +415,7 @@ static struct compiler default_compilers[] =
                      %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o}\
                       %{!pipe:%g.s} %A\n }}}}"},
   {"-",
-   "%{E:cpp -lang-c %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+   "%{E:cpp -lang-c %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C does not support -C without using -E}}\
        %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
         -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
@@ -427,7 +427,7 @@ static struct compiler default_compilers[] =
     %{!E:%e-E required when input is from standard input}"},
   {".m", "@objective-c"},
   {"@objective-c",
-   "cpp -lang-objc %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+   "cpp -lang-objc %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C does not support -C without using -E}}\
        %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d}\
         -undef -D__OBJC__ -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
@@ -450,7 +450,7 @@ static struct compiler default_compilers[] =
   {".h", "@c-header"},
   {"@c-header",
    "%{!E:%eCompilation of header file requested} \
-    cpp %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+    cpp %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C does not support -C without using -E}}\
         %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
         -undef -D__GNUC__=2 %{ansi:-trigraphs -$ -D__STRICT_ANSI__}\
@@ -463,7 +463,7 @@ static struct compiler default_compilers[] =
   {".cxx", "@c++"},
   {".C", "@c++"},
   {"@c++",
-   "cpp -lang-c++ %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+   "cpp -lang-c++ %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C++ does not support -C without using -E}}\
        %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} \
        -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus \
@@ -509,7 +509,7 @@ static struct compiler default_compilers[] =
             %{c:%W{o*}%{!o*:-o %w%b.o}}%{!c:-o %d%w%b.o} %i %A\n }"},
   {".S", "@assembler-with-cpp"},
   {"@assembler-with-cpp",
-   "cpp -lang-asm %{nostdinc} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
+   "cpp -lang-asm %{nostdinc*} %{C} %{v} %{A*} %{D*} %{U*} %{I*} %{i*} %{P}\
        %{C:%{!E:%eGNU C does not support -C without using -E}}\
        %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{trigraphs} \
         -undef -$ %{!undef:%p %P} -D__ASSEMBLER__ \
@@ -533,22 +533,23 @@ static int n_default_compilers
 
 #ifdef LINK_LIBGCC_SPECIAL
 /* Have gcc do the search.  */
+/* -u* was put back because both BSD and SysV seem to support it.  */
 static char *link_command_spec = "\
-%{!c:%{!M:%{!MM:%{!E:%{!S:ld %X %l %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
-                       %{r} %{s} %{T*} %{t} %{x} %{z}\
+%{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
+                       %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
                        %{!A:%{!nostdlib:%S}} \
                        %{L*} %D %o %{!nostdlib:libgcc.a%s %L libgcc.a%s %{!A:%E}}\n }}}}}";
 #else
 /* Use -l and have the linker do the search.  */
 static char *link_command_spec = "\
-%{!c:%{!M:%{!MM:%{!E:%{!S:ld %X %l %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
-                       %{r} %{s} %{T*} %{t} %{x} %{z}\
+%{!c:%{!M:%{!MM:%{!E:%{!S:ld %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} \
+                       %{r} %{s} %{T*} %{t} %{u*} %{x} %{z}\
                        %{!A:%{!nostdlib:%S}} \
                        %{L*} %D %o %{!nostdlib:-lgcc %L -lgcc %{!A:%E}}\n }}}}}";
 #endif
 
 /* A vector of options to give to the linker.
-   These options are accumlated by %x
+   These options are accumulated by %x
    and substituted into the linker command with %X.  */
 static int n_linker_options;
 static char **linker_options;
@@ -1073,7 +1074,6 @@ choose_temp_base ()
 putenv (str)
      char *str;
 {
-#ifndef __MSDOS__              /* not sure about MS/DOS */
 #ifndef VMS                    /* nor about VMS */
 
   extern char **environ;
@@ -1109,7 +1109,6 @@ putenv (str)
   bcopy (old_environ, environ+1, sizeof (char *) * (num_envs+1));
 
 #endif /* VMS */
-#endif /* __MSDOS__ */
 }
 
 #endif /* HAVE_PUTENV */
@@ -1371,19 +1370,28 @@ pexecute (func, program, argv, not_last)
   FILE *argfile;
   int i;
 
-  scmd = (char *)malloc(strlen(program) + strlen(temp_filename) + 6);
-  sprintf(scmd, "%s @%s.gp", program, temp_filename);
-  argfile = fopen(scmd+strlen(program)+2, "w");
+  scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6);
+  sprintf (scmd, "%s @%s.gp", program, temp_filename);
+  argfile = fopen (scmd+strlen (program) + 2, "w");
   if (argfile == 0)
-    pfatal_with_name(scmd+strlen(program)+2);
+    pfatal_with_name (scmd + strlen (program) + 2);
 
   for (i=1; argv[i]; i++)
-    fprintf(argfile, "%s\n", argv[i]);
-  fclose(argfile);
+  {
+    char *cp;
+    for (cp = argv[i]; *cp; cp++)
+      {
+       if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
+         fputc ('\\', argfile);
+       fputc (*cp, argfile);
+      }
+    fputc ('\n', argfile);
+  }
+  fclose (argfile);
 
-  i = system(scmd);
+  i = system (scmd);
 
-  remove(scmd+strlen(program)+2);
+  remove (scmd + strlen (program) + 2);
   return i << 8;
 }
 
@@ -1694,7 +1702,7 @@ process_command (argc, argv)
       startp = endp = temp;
       while (1)
        {
-         if ((*endp == ':') || (*endp == 0))
+         if (*endp == PATH_SEPARATOR || *endp == 0)
            {
              strncpy (nstore, startp, endp-startp);
              if (endp == startp)
@@ -1727,7 +1735,7 @@ process_command (argc, argv)
       startp = endp = temp;
       while (1)
        {
-         if ((*endp == ':') || (*endp == 0))
+         if (*endp == PATH_SEPARATOR || *endp == 0)
            {
              strncpy (nstore, startp, endp-startp);
              if (endp == startp)
@@ -1763,7 +1771,7 @@ process_command (argc, argv)
       startp = endp = temp;
       while (1)
        {
-         if ((*endp == ':') || (*endp == 0))
+         if (*endp == PATH_SEPARATOR || *endp == 0)
            {
              strncpy (nstore, startp, endp-startp);
              if (endp == startp)
@@ -2210,6 +2218,10 @@ do_spec_1 (spec, inswitch, soft_matched_part)
              {
                struct prefix_list *pl
                  = (i == 0 ? library_prefix.plist : startfile_prefix.plist);
+               int bufsize = 100;
+               char *buffer = (char *) xmalloc (bufsize);
+               int idx;
+
                for (; pl; pl = pl->next)
                  {
 #ifdef RELATIVE_PREFIX_NOT_LINKDIR
@@ -2230,7 +2242,15 @@ do_spec_1 (spec, inswitch, soft_matched_part)
                            do_spec_1 (" ", 0, 0);
 #endif
                            do_spec_1 (pl->prefix, 1, 0);
-                           do_spec_1 (machine_suffix, 1, 0);
+                           /* Remove slash from machine_suffix.  */
+                           if (strlen (machine_suffix) >= bufsize)
+                             bufsize = strlen (machine_suffix) * 2 + 1;
+                           buffer = (char *) xrealloc (buffer, bufsize);
+                           strcpy (buffer, machine_suffix);
+                           idx = strlen (buffer);
+                           if (buffer[idx - 1] == '/')
+                             buffer[idx - 1] = 0;
+                           do_spec_1 (buffer, 1, 0);
                            /* Make this a separate argument.  */
                            do_spec_1 (" ", 0, 0);
                          }
@@ -2243,12 +2263,21 @@ do_spec_1 (spec, inswitch, soft_matched_part)
 #ifdef SPACE_AFTER_L_OPTION
                            do_spec_1 (" ", 0, 0);
 #endif
-                           do_spec_1 (pl->prefix, 1, 0);
+                           /* Remove slash from pl->prefix.  */
+                           if (strlen (pl->prefix) >= bufsize)
+                             bufsize = strlen (pl->prefix) * 2 + 1;
+                           buffer = (char *) xrealloc (buffer, bufsize);
+                           strcpy (buffer, pl->prefix);
+                           idx = strlen (buffer);
+                           if (buffer[idx - 1] == '/')
+                             buffer[idx - 1] = 0;
+                           do_spec_1 (buffer, 1, 0);
                            /* Make this a separate argument.  */
                            do_spec_1 (" ", 0, 0);
                          }
                      }
                  }
+               free (buffer);
              }
            break;
 
This page took 0.037145 seconds and 5 git commands to generate.