This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
cpplib: more dependency tweaks
- To: Zack Weinberg <zackw at Stanford dot EDU>
- Subject: cpplib: more dependency tweaks
- From: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Date: Fri, 5 Jan 2001 19:08:21 +0000
- Cc: gcc-patches at gcc dot gnu dot org
This patch
o Adds Tom's suggestion of -MQ: it quotes the file name supplied. -MT
does not.
o Simplifies code by allocating pfile->deps in one place only, during
cpp_reader creation. Since we don't need this struct most of the time,
we no longer pre-allocate any space for the dependency and target
vectors unless they are needed.
o Doesn't strip the path from the default target. For example:-
bash-2.04$ ./cpp0 -MM /tmp/test.c
/tmp/test.o: /tmp/test.c /tmp/test.h
^^^^^
New.
Zack, can't we just remove base_name? We have an implementation in
libiberty if we ever need one.
Neil.
* cpp.texi: Update for -MQ.
* cppinit.c (cpp_create_reader): Always create pfile->deps.
(cpp_cleanup): Don't create pfile->deps.
(initialize_dependency_output): Similarly.
(cpp_handle_option): Similarly.
(OPT_MQ): New.
* gcc.c (cpp_options): Handle -MQ.
(DEFAULT_WORD_SWITCH_TAKES_ARG): Add -MQ.
* mkdeps.c (base_name): Comment out.
(deps_init): Don't allocate vector space until it's needed.
(deps_free): Only free vectors if allocated.
(deps_add_target, deps_add_dep): Update for initial allocation.
(deps_add_default_target): Don't strip to the base_name.
Index: cpp.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpp.texi,v
retrieving revision 1.39
diff -u -p -r1.39 cpp.texi
--- cpp.texi 2001/01/05 07:50:22 1.39
+++ cpp.texi 2001/01/05 19:06:09
@@ -3491,23 +3491,28 @@ This is typical output:-
/tmp/test.h:
@end smallexample
-@item -MT @var{target}
+@item -MT @var{target} or -MQ @var{target}
@findex -MT
-By default CPP uses the base file name and appends the object suffix,
-normally ``.o'', to it to obtain the name of the target for dependency
-generation. With @samp{-MT} you can specify a target yourself,
-overriding the default one.
+@findex -MQ
+By default CPP uses the main file name, including any path, and appends
+the object suffix, normally ``.o'', to it to obtain the name of the
+target for dependency generation. With @samp{-MT} you can specify a
+target yourself, overriding the default one.
If you want multiple targets, you can specify them as a single argument
to @samp{-MT}, or use multiple @samp{-MT} options.
The targets you specify are output in the order they appear on the
-command line, and, unlike the default target, are not quoted for MAKE.
-This allows you to do things like, for example,
+command line. @samp{-MQ} is identical to @samp{-MT}, except that the
+target name is quoted for Make, but with @samp{-MT} it isn't. This
+allows you to do things like, for example,
@smallexample
-MT '$(objpfx)foo.o $(objpfx)foo.os $(objpfx)foo.op'
@end smallexample
+
+The default target is quoted for Make, as if it were given with
+@samp{-MQ}.
@item -H
@findex -H
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.129
diff -u -p -r1.129 cppinit.c
--- cppinit.c 2001/01/05 07:50:22 1.129
+++ cppinit.c 2001/01/05 19:06:14
@@ -499,6 +499,10 @@ cpp_create_reader (lang)
/* After creating pfile->pending. */
set_lang (pfile, lang);
+ /* It's simplest to just create this struct whether or not it will
+ be needed. */
+ pfile->deps = deps_init ();
+
/* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
@@ -552,8 +556,7 @@ cpp_cleanup (pfile)
if (pfile->macro_buffer)
free ((PTR) pfile->macro_buffer);
- if (pfile->deps)
- deps_free (pfile->deps);
+ deps_free (pfile->deps);
_cpp_cleanup_includes (pfile);
_cpp_cleanup_stacks (pfile);
@@ -753,9 +756,6 @@ initialize_dependency_output (pfile)
return;
}
- if (! pfile->deps)
- pfile->deps = deps_init ();
-
/* Find the space before the DEPS_TARGET, if there is one. */
s = strchr (spec, ' ');
if (s)
@@ -1083,6 +1083,7 @@ new_pending_directive (pend, text, handl
DEF_OPT("MM", 0, OPT_MM) \
DEF_OPT("MMD", no_fil, OPT_MMD) \
DEF_OPT("MP", 0, OPT_MP) \
+ DEF_OPT("MQ", no_tgt, OPT_MQ) \
DEF_OPT("MT", no_tgt, OPT_MT) \
DEF_OPT("P", 0, OPT_P) \
DEF_OPT("U", no_mac, OPT_U) \
@@ -1485,9 +1486,6 @@ cpp_handle_option (pfile, argc, argv)
case OPT_MD:
case OPT_MM:
case OPT_MMD:
- if (! pfile->deps)
- pfile->deps = deps_init ();
-
if (opt_code == OPT_M || opt_code == OPT_MD)
CPP_OPTION (pfile, print_deps) = 2;
else
@@ -1506,11 +1504,10 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, deps_phony_targets) = 1;
break;
+ case OPT_MQ:
case OPT_MT:
- /* Add a target. */
- if (! pfile->deps)
- pfile->deps = deps_init ();
- deps_add_target (pfile->deps, arg, 0);
+ /* Add a target. -MQ quotes for Make. */
+ deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
break;
case OPT_A:
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.192
diff -u -p -r1.192 gcc.c
--- gcc.c 2001/01/05 07:50:23 1.192
+++ gcc.c 2001/01/05 19:06:32
@@ -584,7 +584,7 @@ static const char *cpp_options =
"%{C:%{!E:%eGNU C does not support -C without using -E}}\
%{std*} %{nostdinc*}\
%{C} %{v} %{I*} %{P} %{$} %I\
- %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{MP} %{MT}\
+ %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG} %{MP} %{MQ} %{MT}\
%{!no-gcc:-D__GNUC__=%v1 -D__GNUC_MINOR__=%v2 -D__GNUC_PATCHLEVEL__=%v3}\
%{!undef:%{!ansi:%{!std=*:%p}%{std=gnu*:%p}} %P} %{trigraphs}\
%c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
@@ -663,7 +663,7 @@ static struct user_specs *user_specs_hea
|| !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
|| !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
|| !strcmp (STR, "isystem") || !strcmp (STR, "specs") \
- || !strcmp (STR, "MF") || !strcmp (STR, "MT"))
+ || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
#ifndef WORD_SWITCH_TAKES_ARG
#define WORD_SWITCH_TAKES_ARG(STR) DEFAULT_WORD_SWITCH_TAKES_ARG (STR)
Index: mkdeps.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/mkdeps.c,v
retrieving revision 1.9
diff -u -p -r1.9 mkdeps.c
--- mkdeps.c 2001/01/05 07:50:23 1.9
+++ mkdeps.c 2001/01/05 19:06:37
@@ -38,7 +38,6 @@ struct deps
};
static const char *munge PARAMS ((const char *));
-static const char *base_name PARAMS ((const char *));
/* Given a filename, quote characters in that filename which are
significant to Make. Note that it's not possible to quote all such
@@ -107,6 +106,7 @@ munge (filename)
return buffer;
}
+#if 0 /* May be useful later. */
/* Given a pathname, calculate the non-directory part. This always
knows how to handle Unix-style pathnames, and understands VMS and
DOS paths on those systems. */
@@ -133,6 +133,7 @@ base_name (fname)
if ((p = strrchr (s, '/'))) s = p + 1;
return s;
}
+#endif /* 0 */
/* Public routines. */
@@ -141,15 +142,15 @@ deps_init ()
{
struct deps *d = (struct deps *) xmalloc (sizeof (struct deps));
- /* Allocate space for the vectors now. */
+ /* Allocate space for the vectors only if we need it. */
- d->targetv = (const char **) xmalloc (2 * sizeof (const char *));
- d->depv = (const char **) xmalloc (8 * sizeof (const char *));
+ d->targetv = 0;
+ d->depv = 0;
d->ntargets = 0;
- d->targets_size = 2;
+ d->targets_size = 0;
d->ndeps = 0;
- d->deps_size = 8;
+ d->deps_size = 0;
return d;
}
@@ -160,14 +161,20 @@ deps_free (d)
{
unsigned int i;
- for (i = 0; i < d->ntargets; i++)
- free ((PTR) d->targetv[i]);
+ if (d->targetv)
+ {
+ for (i = 0; i < d->ntargets; i++)
+ free ((PTR) d->targetv[i]);
+ free (d->targetv);
+ }
- for (i = 0; i < d->ndeps; i++)
- free ((PTR) d->depv[i]);
+ if (d->depv)
+ {
+ for (i = 0; i < d->ndeps; i++)
+ free ((PTR) d->depv[i]);
+ free (d->depv);
+ }
- free (d->targetv);
- free (d->depv);
free (d);
}
@@ -181,7 +188,7 @@ deps_add_target (d, t, quote)
{
if (d->ntargets == d->targets_size)
{
- d->targets_size *= 2;
+ d->targets_size = d->targets_size * 2 + 4;
d->targetv = (const char **) xrealloc (d->targetv,
d->targets_size * sizeof (const char *));
}
@@ -212,7 +219,6 @@ deps_add_default_target (d, tgt)
deps_add_target (d, "-", 1);
else
{
- tgt = base_name (tgt);
o = (char *) alloca (strlen (tgt) + 8);
strcpy (o, tgt);
@@ -239,7 +245,7 @@ deps_add_dep (d, t)
if (d->ndeps == d->deps_size)
{
- d->deps_size *= 2;
+ d->deps_size *= 2 + 8;
d->depv = (const char **)
xrealloc (d->depv, d->deps_size * sizeof (const char *));
}