diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7f280c1f329..84f8a29522b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2001-01-05 Neil Booth + + * 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 * config/v850/v850.h (RETURN_ADDR_RTX): Define. diff --git a/gcc/cpp.texi b/gcc/cpp.texi index 7df4531af03..1f8121f9b10 100644 --- a/gcc/cpp.texi +++ b/gcc/cpp.texi @@ -3491,24 +3491,36 @@ This is typical output:- /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 diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 7454b6f6733..b0c00ae425e 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -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, handler) 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) \ @@ -1494,9 +1495,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 @@ -1515,11 +1513,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: diff --git a/gcc/gcc.c b/gcc/gcc.c index b33cacc09a1..65fa5206a8e 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -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_head, *user_specs_tail; || !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) diff --git a/gcc/mkdeps.c b/gcc/mkdeps.c index f83d82f9e30..a128a6f326f 100644 --- a/gcc/mkdeps.c +++ b/gcc/mkdeps.c @@ -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,33 +106,6 @@ munge (filename) 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 * @@ -141,15 +113,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 +132,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 +159,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 +190,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 +216,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 *)); }