The final bit of preprocessor change is that to mkdeps. We have a new kind of thing to be dependent upon -- a compiled module interface. That's also an additional target.

This adds the logic to mkdeps to keep those dependencies separate from include file dependencies. I made use of this when demonstrating a module-aware Make POC.


--
Nathan Sidwell

diff --git c/libcpp/include/mkdeps.h w/libcpp/include/mkdeps.h
index 6d05351cb4a..1d6dd9562a5 100644
--- c/libcpp/include/mkdeps.h
+++ w/libcpp/include/mkdeps.h
@@ -55,9 +57,12 @@ extern void deps_add_default_target (class mkdeps *, const char *);
    dependency entered should be the primary source file.  */
 extern void deps_add_dep (class mkdeps *, const char *);
 
-/* Write out a deps buffer to a specified file.  The third argument
+extern void deps_add_module (struct mkdeps *, const char *,
+			     const char * = NULL, bool = false);
+
+/* Write out a deps buffer to a specified file.  The last argument
    is the number of columns to word-wrap at (0 means don't wrap).  */
-extern void deps_write (const class mkdeps *, FILE *, bool, unsigned int);
+extern void deps_write (const cpp_reader *, FILE *, unsigned int);
 
 /* Write out a deps buffer to a file, in a form that can be read back
    with deps_restore.  Returns nonzero on error, in which case the
diff --git c/libcpp/mkdeps.c w/libcpp/mkdeps.c
index ea5f060c380..0e70b0b633b 100644
--- c/libcpp/mkdeps.c
+++ w/libcpp/mkdeps.c
@@ -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;
 };
 
@@ -323,6 +331,27 @@ deps_add_vpath (class mkdeps *d, const char *vpath)
     }
 }
 
+/* Add a new module dependency.  M is the module name, with P being
+   any partition name thereof (might be NULL).  If CMI is NULL, this
+   is an import dependency.  Otherwise, this is an output dependency
+   specifying CMI as the output file, of type IS_HEADER_UNIT.  */
+
+void
+deps_add_module (struct mkdeps *d, const char *m,
+		 const char *cmi, bool is_header_unit)
+{
+  m = xstrdup (m);
+
+  if (cmi)
+    {
+      d->module_name = m;
+      d->is_header_unit = is_header_unit;
+      d->cmi_name = xstrdup (cmi);
+    }
+  else
+    d->modules.push (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.  */
@@ -379,6 +408,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);
@@ -387,6 +418,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

Reply via email to