* cpp.texi: Update for -MQ.
* cppinit.c (cpp_create_reader): Always create pfile->deps.
(cpp_cleanup): Always free pfile->deps.
(initialize_dependency_output): Don't create pfile->deps.
(cpp_handle_option): Similarly.
(OPT_MQ): New.
* gcc.c (cpp_options): Handle -MQ.
(DEFAULT_WORD_SWITCH_TAKES_ARG): Add -MQ.
* mkdeps.c (base_name): Remove.
(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.
From-SVN: r38735
+2001-01-05 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cpp.texi: Update for -MQ.
+ * cppinit.c (cpp_create_reader): Always create pfile->deps.
+ (cpp_cleanup): Always free pfile->deps.
+ (initialize_dependency_output): Don't create pfile->deps.
+ (cpp_handle_option): Similarly.
+ (OPT_MQ): New.
+ * gcc.c (cpp_options): Handle -MQ.
+ (DEFAULT_WORD_SWITCH_TAKES_ARG): Add -MQ.
+ * mkdeps.c (base_name): Remove.
+ (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.
+
2001-01-05 DJ Delorie <dj@redhat.com>
* config/v850/v850.h (RETURN_ADDR_RTX): Define.
/tmp/test.h:
@end smallexample
+@item -MQ @var{target}
@item -MT @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. For
+example, -MT '$(objpfx)foo.o' gives
@smallexample
--MT '$(objpfx)foo.o $(objpfx)foo.os $(objpfx)foo.op'
+$(objpfx)foo.o: /tmp/foo.c
@end smallexample
+but -MQ '$(objpfx)foo.o' gives
+
+@smallexample
+$$(objpfx)foo.o: /tmp/foo.c
+@end smallexample
+
+The default target is automatically quoted, as if it were given with
+@samp{-MQ}.
+
@item -H
@findex -H
Print the name of each header file used, in addition to other normal
/* 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);
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);
return;
}
- if (! pfile->deps)
- pfile->deps = deps_init ();
-
/* Find the space before the DEPS_TARGET, if there is one. */
s = strchr (spec, ' ');
if (s)
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) \
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
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:
"%{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__}}\
|| !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)
};
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
return buffer;
}
-/* 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. */
-
-/* Find the base name of a (partial) pathname FNAME.
- Returns a pointer into the string passed in.
- Accepts Unix (/-separated) paths on all systems,
- DOS and VMS paths on those systems. */
-
-static const char *
-base_name (fname)
- const char *fname;
-{
- const char *s = fname;
- const char *p;
-#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
- if (ISALPHA (s[0]) && s[1] == ':') s += 2;
- if ((p = strrchr (s, '\\'))) s = p + 1;
-#elif defined VMS
- if ((p = strrchr (s, ':'))) s = p + 1; /* Skip device. */
- if ((p = strrchr (s, ']'))) s = p + 1; /* Skip directory. */
- if ((p = strrchr (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
-#endif
- if ((p = strrchr (s, '/'))) s = p + 1;
- return s;
-}
-
/* Public routines. */
struct deps *
{
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;
}
{
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);
}
{
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 *));
}
deps_add_target (d, "-", 1);
else
{
- tgt = base_name (tgt);
o = (char *) alloca (strlen (tgt) + 8);
strcpy (o, tgt);
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 *));
}