public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* preprocessor: Update mkdeps for modules
@ 2020-11-18 14:46 Nathan Sidwell
  0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-11-18 14:46 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]


This is	slightly different to the original patch I posted.  This adds
separate module target and dependency functions (rather than a single
bi-modal function).

         libcpp/
         * include/cpplib.h (struct cpp_options): Add modules to
         dep-options.
         * include/mkdeps.h (deps_add_module_target): Declare.
         (deps_add_module_dep): Declare.
         * mkdes.c (class mkdeps): Add modules, module_name, cmi_name,
         is_header_unit fields.  Adjust cdtors.
         (deps_add_module_target, deps_add_module_dep): New.
         (make_write): Write module dependencies, if enabled.

pushing to trunk

-- 
Nathan Sidwell

[-- Attachment #2: 08a-cpp-mkdeps.diff --]
[-- Type: text/x-patch, Size: 5055 bytes --]

diff --git i/libcpp/include/cpplib.h w/libcpp/include/cpplib.h
index d2324266d39..75d4d0a9f2f 100644
--- i/libcpp/include/cpplib.h
+++ w/libcpp/include/cpplib.h
@@ -528,6 +528,9 @@ struct cpp_options
        one.  */
     bool phony_targets;
 
+    /* Generate dependency info for modules.  */
+    bool modules;
+
     /* If true, no dependency is generated on the main file.  */
     bool ignore_main_file;
 
diff --git i/libcpp/include/mkdeps.h w/libcpp/include/mkdeps.h
index 593b718aaeb..9f10327eec3 100644
--- i/libcpp/include/mkdeps.h
+++ w/libcpp/include/mkdeps.h
@@ -51,6 +51,13 @@ extern void deps_add_target (class mkdeps *, const char *, int);
    string as the default target is interpreted as stdin.  */
 extern void deps_add_default_target (class mkdeps *, const char *);
 
+/* Adds a module target.  The module name and cmi name are copied.  */
+extern void deps_add_module_target (struct mkdeps *, const char *module,
+				    const char *cmi, bool is_header);
+
+/* Adds a module dependency.  The module name is copied.  */
+extern void deps_add_module_dep (struct mkdeps *, const char *module);
+
 /* Add a dependency (appears on the right side of the colon) to the
    deps list.  Dependencies will be printed in the order that they
    were entered with this function.  By convention, the first
diff --git i/libcpp/mkdeps.c w/libcpp/mkdeps.c
index a989ed355fa..4a8e101b912 100644
--- i/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;
 };
 
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-18 14:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 14:46 preprocessor: Update mkdeps for modules Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).