[Ada] Consistently use explicit Entity_Id type instead of alias
[gcc.git] / libcpp / mkdeps.c
index a989ed355facb974d8d7757a6cbdb608ebdaa1fb..4a8e101b912f3f18079b9859f94b4bed5df6e341 100644 (file)
@@ -81,7 +81,7 @@ public:
   };
 
   mkdeps ()
-    : quote_lwm (0)
+    : module_name (NULL), cmi_name (NULL), is_header_unit (false), quote_lwm (0)
   {
   }
   ~mkdeps ()
@@ -94,14 +94,22 @@ public:
       free (const_cast <char *> (deps[i]));
     for (i = vpath.size (); i--;)
       XDELETEVEC (vpath[i].str);
+    for (i = modules.size (); i--;)
+      XDELETEVEC (modules[i]);
+    XDELETEVEC (module_name);
+    free (const_cast <char *> (cmi_name));
   }
 
 public:
   vec<const char *> targets;
   vec<const char *> deps;
   vec<velt> vpath;
+  vec<const char *> modules;
 
 public:
+  const char *module_name;
+  const char *cmi_name;
+  bool is_header_unit;
   unsigned short quote_lwm;
 };
 
@@ -313,6 +321,28 @@ deps_add_vpath (class mkdeps *d, const char *vpath)
     }
 }
 
+/* Add a new module target (there can only be one).  M is the module
+   name.   */
+
+void
+deps_add_module_target (struct mkdeps *d, const char *m,
+                       const char *cmi, bool is_header_unit)
+{
+  gcc_assert (!d->module_name);
+  
+  d->module_name = xstrdup (m);
+  d->is_header_unit = is_header_unit;
+  d->cmi_name = xstrdup (cmi);
+}
+
+/* Add a new module dependency.  M is the module name.  */
+
+void
+deps_add_module_dep (struct mkdeps *d, const char *m)
+{
+  d->modules.push (xstrdup (m));
+}
+
 /* Write NAME, with a leading space to FP, a Makefile.  Advance COL as
    appropriate, wrap at COLMAX, returning new column number.  Iff
    QUOTE apply quoting.  Append TRAIL.  */
@@ -369,6 +399,8 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
   if (d->deps.size ())
     {
       column = make_write_vec (d->targets, fp, 0, colmax, d->quote_lwm);
+      if (CPP_OPTION (pfile, deps.modules) && d->cmi_name)
+       column = make_write_name (d->cmi_name, fp, column, colmax);
       fputs (":", fp);
       column++;
       make_write_vec (d->deps, fp, column, colmax);
@@ -377,6 +409,59 @@ make_write (const cpp_reader *pfile, FILE *fp, unsigned int colmax)
        for (unsigned i = 1; i < d->deps.size (); i++)
          fprintf (fp, "%s:\n", munge (d->deps[i]));
     }
+
+  if (!CPP_OPTION (pfile, deps.modules))
+    return;
+
+  if (d->modules.size ())
+    {
+      column = make_write_vec (d->targets, fp, 0, colmax, d->quote_lwm);
+      if (d->cmi_name)
+       column = make_write_name (d->cmi_name, fp, column, colmax);
+      fputs (":", fp);
+      column++;
+      column = make_write_vec (d->modules, fp, column, colmax, 0, ".c++m");
+      fputs ("\n", fp);
+    }
+
+  if (d->module_name)
+    {
+      if (d->cmi_name)
+       {
+         /* module-name : cmi-name */
+         column = make_write_name (d->module_name, fp, 0, colmax,
+                                   true, ".c++m");
+         fputs (":", fp);
+         column++;
+         column = make_write_name (d->cmi_name, fp, column, colmax);
+         fputs ("\n", fp);
+
+         column = fprintf (fp, ".PHONY:");
+         column = make_write_name (d->module_name, fp, column, colmax,
+                                   true, ".c++m");
+         fputs ("\n", fp);
+       }
+
+      if (d->cmi_name && !d->is_header_unit)
+       {
+         /* An order-only dependency.
+             cmi-name :| first-target
+            We can probably drop this this in favour of Make-4.3's grouped
+             targets '&:'  */
+         column = make_write_name (d->cmi_name, fp, 0, colmax);
+         fputs (":|", fp);
+         column++;
+         column = make_write_name (d->targets[0], fp, column, colmax);
+         fputs ("\n", fp);
+       }
+    }
+  
+  if (d->modules.size ())
+    {
+      column = fprintf (fp, "CXX_IMPORTS +=");
+      make_write_vec (d->modules, fp, column, colmax, 0, ".c++m");
+      fputs ("\n", fp);
+    }
 }
 
 /* Write out dependencies according to the selected format (which is