summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2013-05-13 04:29:35 -0400
committerPaul Smith <psmith@gnu.org>2013-05-13 04:30:20 -0400
commit58dae243526bd322ae6bec0c4394a117a5fe0171 (patch)
tree921c2f73d7ef59e149880a44472ccd54106aca1c
parentc7732bd5add31b38fea113c9ab4ad4d97a0870c7 (diff)
downloadgunmake-58dae243526bd322ae6bec0c4394a117a5fe0171.tar.gz
[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.
-rw-r--r--ChangeLog11
-rw-r--r--default.c34
-rw-r--r--file.c16
-rw-r--r--filedef.h1
-rw-r--r--main.c28
-rw-r--r--makeint.h1
-rw-r--r--variable.c43
7 files changed, 97 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index d73e22d..d482c2c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/default.c b/default.c
index 4b24e2e..18b4d4a 100644
--- a/default.c
+++ b/default.c
@@ -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);
+}
diff --git a/file.c b/file.c
index b36edcb..444a81d 100644
--- a/file.c
+++ b/file.c
@@ -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."));
diff --git a/filedef.h b/filedef.h
index 50eec74..5fa6429 100644
--- a/filedef.h
+++ b/filedef.h
@@ -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. */
};
diff --git a/main.c b/main.c
index 8eed56d..5823840 100644
--- a/main.c
+++ b/main.c
@@ -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__
diff --git a/makeint.h b/makeint.h
index ae7e813..9d351c9 100644
--- a/makeint.h
+++ b/makeint.h
@@ -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);
diff --git a/variable.c b/variable.c
index 51f936b..5415f05 100644
--- a/variable.c
+++ b/variable.c
@@ -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