OSDN Git Service

* tradcpp.c (deps_file, print_deps_missing_files): New variables.
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 4 Jan 2001 17:26:12 +0000 (17:26 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 4 Jan 2001 17:26:12 +0000 (17:26 +0000)
(main): Handle -MG, -MD, -MMD.  Bail out if -MG is given without -M
or -MM.
(do_include): Handle missing headers like cpp0.
* cppfiles.c (_cpp_execute_include): Don't prefix absolute header
paths with first include pathname.  Don't strcat to uninitialized
string.

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

gcc/ChangeLog
gcc/cppfiles.c
gcc/tradcpp.c

index 2a0f123..bda5763 100644 (file)
@@ -1,3 +1,13 @@
+2001-01-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * tradcpp.c (deps_file, print_deps_missing_files): New variables.
+       (main): Handle -MG, -MD, -MMD.  Bail out if -MG is given without -M
+       or -MM.
+       (do_include): Handle missing headers like cpp0.
+       * cppfiles.c (_cpp_execute_include): Don't prefix absolute header
+       paths with first include pathname.  Don't strcat to uninitialized
+       string.
+
 2001-01-04  Bernd Schmidt  <bernds@redhat.com>
 
        * regrename.c (regrename_optimize): Don't rename from frame pointer
index ddf2e80..b0678d7 100644 (file)
@@ -648,12 +648,14 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
   if (CPP_OPTION (pfile, print_deps_missing_files)
       && PRINT_THIS_DEP (pfile, angle_brackets))
     {
-      if (!angle_brackets)
+      if (!angle_brackets || *fname == '/')
        deps_add_dep (pfile->deps, fname);
       else
        {
          char *p;
          struct file_name_list *ptr;
+         int len = strlen (ptr->name);
+
          /* If requested as a system header, assume it belongs in
             the first system header directory. */
          if (CPP_OPTION (pfile, bracket_include))
@@ -661,14 +663,13 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
          else
            ptr = CPP_OPTION (pfile, quote_include);
 
-         p = (char *) alloca (strlen (ptr->name)
-                              + strlen (fname) + 2);
-         if (*ptr->name != '\0')
+         p = (char *) alloca (len + strlen (fname) + 2);
+         if (len)
            {
-             strcpy (p, ptr->name);
-             strcat (p, "/");
+             memcpy (p, ptr->name, len);
+             p[len++] = '/';
            }
-         strcat (p, fname);
+         strcpy (p + len, fname);
          _cpp_simplify_pathname (p);
          deps_add_dep (pfile->deps, p);
        }
index 206541c..ff43902 100644 (file)
@@ -46,6 +46,16 @@ int put_out_comments = 0;
 
 int print_deps = 0;
 
+/* File name which deps are being written to.  This is 0 if deps are
+   being written to stdout.  */
+
+const char *deps_file = 0;
+
+/* Nonzero if missing .h files in -M output are assumed to be
+   generated files and not errors.  */
+
+int print_deps_missing_files = 0;
+       
 /* Nonzero means don't output line number information.  */
 
 int no_line_commands;
@@ -608,11 +618,32 @@ main (argc, argv)
        break;
 
       case 'M':
-       if (!strcmp (argv[i], "-M"))
-         print_deps = 2;
-       else if (!strcmp (argv[i], "-MM"))
-         print_deps = 1;
-       inhibit_output = 1;
+       {
+         char *p = NULL;
+
+         if (!strncmp (argv[i], "-MD", 3)) {
+           p = argv[i] + 3;
+           print_deps = 2;
+         } else if (!strncmp (argv[i], "-MMD", 4)) {
+           p = argv[i] + 4;
+           print_deps = 1;
+         } else if (!strcmp (argv[i], "-M")) {
+           print_deps = 2;
+           inhibit_output = 1;
+         } else if (!strcmp (argv[i], "-MM")) {
+           print_deps = 1;
+           inhibit_output = 1;
+         } else if (!strcmp (argv[i], "-MG"))
+           print_deps_missing_files = 1;
+         if (p) {
+           if (*p)
+             deps_file = p;
+           else if (i + 1 == argc)
+             fatal ("Filename missing after %s option", argv[i]);
+           else
+             deps_file = argv[++i];
+         }
+       }
        break;
 
       case 'd':
@@ -716,6 +747,9 @@ main (argc, argv)
     }
   }
 
+  if (print_deps_missing_files && (!print_deps || !inhibit_output))
+    fatal ("-MG must be specified with one of -M or -MM");
+
   if (user_label_prefix == 0)
     user_label_prefix = USER_LABEL_PREFIX;
 
@@ -809,7 +843,6 @@ main (argc, argv)
     {
       char *spec = getenv ("DEPENDENCIES_OUTPUT");
       char *s;
-      char *output_file;
 
       if (spec == 0)
        {
@@ -823,28 +856,33 @@ main (argc, argv)
       s = strchr (spec, ' ');
       if (s)
        {
+         char *out_file;
+
          deps_target = s + 1;
-         output_file = (char *) xmalloc (s - spec + 1);
-         memcpy (output_file, spec, s - spec);
-         output_file[s - spec] = 0;
+         out_file = (char *) xmalloc (s - spec + 1);
+         memcpy (out_file, spec, s - spec);
+         out_file[s - spec] = 0;
+         deps_file = out_file;
        }
       else
        {
          deps_target = 0;
-         output_file = spec;
+         deps_file = spec;
        }
-      
-      deps_stream = fopen (output_file, "a");
-      if (deps_stream == 0)
-       pfatal_with_name (output_file);
     }
-  /* If the -M option was used, output the deps to standard output.  */
-  else if (print_deps)
-    deps_stream = stdout;
 
   /* For -M, print the expected object file name
      as the target of this Make-rule.  */
   if (print_deps) {
+
+    if (deps_file) {
+      deps_stream = fopen (deps_file, "a");
+      if (deps_stream == 0)
+       pfatal_with_name (deps_file);
+    } else
+      /* If the -M option was used, output the deps to standard output.  */
+      deps_stream = stdout;
+
     deps_allocated_size = 200;
     deps_buffer = (char *) xmalloc (deps_allocated_size);
     deps_buffer[0] = 0;
@@ -2334,19 +2372,38 @@ get_filename:
   if (f < 0) {
     strncpy (fname, (const char *)fbeg, flen);
     fname[flen] = 0;
-    error_from_errno (fname);
+    if (print_deps_missing_files
+       && print_deps > (system_header_p || (system_include_depth > 0))) {
 
-    /* For -M, add this file to the dependencies.  */
-    if (print_deps > (system_header_p || (system_include_depth > 0))) {
-      if (system_header_p)
-       warning ("nonexistent file <%.*s> omitted from dependency output",
-                flen, fbeg);
+      /* If requested as a system header, assume it belongs in
+        the first system header directory. */
+      if (first_bracket_include)
+       stackp = first_bracket_include;
       else
-       {
-         deps_output ((const char *)fbeg, flen);
-         deps_output (" ", 0);
-       }
-    }
+       stackp = include;
+
+      if (!system_header_p || *fbeg == '/' || !stackp->fname)
+       deps_output ((const char *)fbeg, flen);
+      else {
+       char *p;
+       int len = strlen(stackp->fname);
+
+       p = (char *) alloca (len + flen + 2);
+       memcpy (p, stackp->fname, len);
+       p[len++] = '/';
+       memcpy (p + len, fbeg, flen);
+       len += flen;
+       deps_output (p, len);
+      }
+      deps_output (" ", 0);
+
+    } else if (print_deps
+              && print_deps <= (system_header_p
+                                || (system_include_depth > 0)))
+      warning ("No include path in which to find %.*s", flen, fbeg);
+    else
+      error_from_errno (fname);
+
   } else {
 
     /* Check to see if this include file is a once-only include file.