aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-11-18 06:44:38 -0800
committerNathan Sidwell <nathan@acm.org>2020-11-18 08:44:49 -0800
commitdb87f19ae3cfc126fb39616515b57dea4df02e6d (patch)
treeb6ecb449034d003a05e622635f3c11b862687825
parentd4a788c7174496aca5fbe3e2b617a5a62e32c209 (diff)
downloadgcc-db87f19ae3cfc126fb39616515b57dea4df02e6d.zip
gcc-db87f19ae3cfc126fb39616515b57dea4df02e6d.tar.gz
gcc-db87f19ae3cfc126fb39616515b57dea4df02e6d.tar.bz2
preprocessor: Update mkdeps for modules
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. * mkdeps.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.
-rw-r--r--libcpp/include/cpplib.h3
-rw-r--r--libcpp/include/mkdeps.h7
-rw-r--r--libcpp/mkdeps.c87
3 files changed, 96 insertions, 1 deletions
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index d232426..75d4d0a 100644
--- a/libcpp/include/cpplib.h
+++ b/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 a/libcpp/include/mkdeps.h b/libcpp/include/mkdeps.h
index 593b718..9f10327 100644
--- a/libcpp/include/mkdeps.h
+++ b/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 a/libcpp/mkdeps.c b/libcpp/mkdeps.c
index a989ed3..4a8e101 100644
--- a/libcpp/mkdeps.c
+++ b/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