[Savannah #20501] Handle adding -r/-R to MAKEFLAGS in the makefile.

If -R is set in the makefile and not the command line, then go through all the
default variables and undefine them.  If -r is set in the makefile and not in
the command line, then remove all .SUFFIX prefixes (unless the user set it)
and SUFFIX variable setting.  In -p mode don't print builtins.
This commit is contained in:
Paul Smith 2013-05-13 04:29:35 -04:00
parent c7732bd5ad
commit 58dae24352
7 changed files with 97 additions and 37 deletions

View File

@ -1,5 +1,16 @@
2013-05-13 Paul Smith <psmith@gnu.org>
* filedef.h (struct file): Add a builtin flag.
* file.c (enter_file): Unset the builtin flag.
(rehash_file): Ditto.
(print_file): Don't print builtin files if we've omitted them.
* default.c (undefine_default_variables): New function: go through
the default variables and undefine them.
(set_default_suffixes): Mark these suffix rules as builtin.
* makeint.h: Prototype.
* main.c (main): Handle addition of -r and -R to MAKEFLAGS in the
makefile. Fixes Savannah bug #20501.
* main.c (define_makeflags): Assign o_env_override level to
MAKEFLAGS to ensure it's set even in the presence of -e.
Fixes Savannah bug #2216.

View File

@ -15,6 +15,9 @@ You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
#include "makeint.h"
#include <assert.h>
#include "filedef.h"
#include "variable.h"
#include "rule.h"
@ -536,15 +539,20 @@ void
set_default_suffixes (void)
{
suffix_file = enter_file (strcache_add (".SUFFIXES"));
suffix_file->builtin = 1;
if (no_builtin_rules_flag)
define_variable_cname ("SUFFIXES", "", o_default, 0);
else
{
struct dep *d;
char *p = default_suffixes;
suffix_file->deps = enter_prereqs(PARSE_FILE_SEQ (&p, struct dep, '\0',
NULL, 0),
NULL);
for (d = suffix_file->deps; d; d = d->next)
d->file->builtin = 1;
define_variable_cname ("SUFFIXES", default_suffixes, o_default, 0);
}
}
@ -565,15 +573,14 @@ install_default_suffix_rules (void)
for (s = default_suffix_rules; *s != 0; s += 2)
{
struct file *f = enter_file (strcache_add (s[0]));
/* Don't clobber cmds given in a makefile if there were any. */
if (f->cmds == 0)
{
f->cmds = xmalloc (sizeof (struct commands));
f->cmds->fileinfo.filenm = 0;
f->cmds->commands = s[1];
f->cmds->command_lines = 0;
f->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
}
/* This function should run before any makefile is parsed. */
assert (f->cmds == 0);
f->cmds = xmalloc (sizeof (struct commands));
f->cmds->fileinfo.filenm = 0;
f->cmds->commands = s[1];
f->cmds->command_lines = 0;
f->cmds->recipe_prefix = RECIPEPREFIX_DEFAULT;
f->builtin = 1;
}
}
@ -606,3 +613,12 @@ define_default_variables (void)
for (s = default_variables; *s != 0; s += 2)
define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
}
void
undefine_default_variables (void)
{
const char **s;
for (s = default_variables; *s != 0; s += 2)
undefine_variable_global (s[0], strlen (s[0]), o_default);
}

16
file.c
View File

@ -177,7 +177,10 @@ enter_file (const char *name)
file_slot = (struct file **) hash_find_slot (&files, &file_key);
f = *file_slot;
if (! HASH_VACANT (f) && !f->double_colon)
return f;
{
f->builtin = 0;
return f;
}
new = xcalloc (sizeof (struct file));
new->name = new->hname = name;
@ -213,6 +216,7 @@ rehash_file (struct file *from_file, const char *to_hname)
struct file *f;
/* If it's already that name, we're done. */
from_file->builtin = 0;
file_key.hname = to_hname;
if (! file_hash_cmp (from_file, &file_key))
return;
@ -321,6 +325,7 @@ rehash_file (struct file *from_file, const char *to_hname)
MERGE (ignore_vpath);
#undef MERGE
to_file->builtin = 0;
from_file->renamed = to_file;
}
@ -917,6 +922,13 @@ print_file (const void *item)
{
const struct file *f = item;
/* If we're not using builtin targets, don't show them.
Ideally we'd be able to delete them altogether but currently there's no
facility to ever delete a file once it's been added. */
if (no_builtin_rules_flag && f->builtin)
return;
putchar ('\n');
if (f->cmds && f->cmds->recipe_prefix != cmd_prefix)
@ -944,6 +956,8 @@ print_file (const void *item)
puts (_("# Command line target."));
if (f->dontcare)
puts (_("# A default, MAKEFILES, or -include/sinclude makefile."));
if (f->builtin)
puts (_("# Builtin rule"));
puts (f->tried_implicit
? _("# Implicit rule search has been done.")
: _("# Implicit rule search has not been done."));

View File

@ -95,6 +95,7 @@ struct file
considered on current scan of goal chain */
unsigned int no_diag:1; /* True if the file failed to update and no
diagnostics has been issued (dontcare). */
unsigned int builtin:1; /* True if the file is a builtin rule. */
};

28
main.c
View File

@ -1767,13 +1767,33 @@ main (int argc, char **argv, char **envp)
}
#endif /* __MSDOS__ || __EMX__ */
/* Decode switches again, in case the variables were set by the makefile. */
decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
{
int old_builtin_rules_flag = no_builtin_rules_flag;
int old_builtin_variables_flag = no_builtin_variables_flag;
/* Decode switches again, for variables set by the makefile. */
decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
#if 0
decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
#endif
/* If we've disabled builtin rules, get rid of them. */
if (no_builtin_rules_flag && ! old_builtin_rules_flag)
{
if (suffix_file->builtin)
{
free_dep_chain (suffix_file->deps);
suffix_file->deps = 0;
}
define_variable_cname ("SUFFIXES", "", o_default, 0);
}
/* If we've disabled builtin variables, get rid of them. */
if (no_builtin_variables_flag && ! old_builtin_variables_flag)
undefine_default_variables ();
}
#if defined (__MSDOS__) || defined (__EMX__)
if (job_slots != 1
# ifdef __EMX__

View File

@ -454,6 +454,7 @@ const char *dir_name (const char *);
void hash_init_directories (void);
void define_default_variables (void);
void undefine_default_variables (void);
void set_default_suffixes (void);
void install_default_suffix_rules (void);
void install_default_implicit_rules (void);

View File

@ -280,7 +280,21 @@ define_variable_in_set (const char *name, unsigned int length,
variable (makefile, command line or environment). */
static void
free_variable_name_and_value (const void *item);
free_variable_name_and_value (const void *item)
{
struct variable *v = (struct variable *) item;
free (v->name);
free (v->value);
}
void
free_variable_set (struct variable_set_list *list)
{
hash_map (&list->set->table, free_variable_name_and_value);
hash_free (&list->set->table, 1);
free (list->set);
free (list);
}
void
undefine_variable_in_set (const char *name, unsigned int length,
@ -305,17 +319,17 @@ undefine_variable_in_set (const char *name, unsigned int length,
if (! HASH_VACANT (v))
{
if (env_overrides && v->origin == o_env)
/* V came from in the environment. Since it was defined
before the switches were parsed, it wasn't affected by -e. */
v->origin = o_env_override;
/* V came from in the environment. Since it was defined
before the switches were parsed, it wasn't affected by -e. */
v->origin = o_env_override;
/* If the definition is from a stronger source than this one, don't
undefine it. */
if ((int) origin >= (int) v->origin)
{
{
hash_delete_at (&set->table, var_slot);
free_variable_name_and_value (v);
}
}
}
}
@ -643,23 +657,6 @@ create_new_variable_set (void)
return setlist;
}
static void
free_variable_name_and_value (const void *item)
{
struct variable *v = (struct variable *) item;
free (v->name);
free (v->value);
}
void
free_variable_set (struct variable_set_list *list)
{
hash_map (&list->set->table, free_variable_name_and_value);
hash_free (&list->set->table, 1);
free (list->set);
free (list);
}
/* Create a new variable set and push it on the current setlist.
If we're pushing a global scope (that is, the current scope is the global
scope) then we need to "push" it the other way: file variable sets point