[Savannah #20501] Handle adding -r/-R to MAKEFLAGS in the makefile.
authorPaul Smith <psmith@gnu.org>
Mon, 13 May 2013 08:29:35 +0000 (04:29 -0400)
committerPaul Smith <psmith@gnu.org>
Mon, 13 May 2013 08:30:20 +0000 (04:30 -0400)
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.

ChangeLog
default.c
file.c
filedef.h
main.c
makeint.h
variable.c

index d73e22dda2d3df974c885e72b0442301ba4974ba..d482c2cfee0002460006bf87d9b28d740e94194d 100644 (file)
--- 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.
index 4b24e2edd3c87150172043f3f89b6f5bffe9a36f..18b4d4a8494981301607622159e7868447446300 100644 (file)
--- 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 b36edcb3a2689486b41928a58facdf38aa6c6166..444a81d1dd2900642a839d15829e7714c8d468a2 100644 (file)
--- 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."));
index 50eec74b98bf89e5fee48428f8c832b348a63072..5fa6429cf88d362cf354f90eee80508a9aaba9ac 100644 (file)
--- 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 8eed56d8abdd4c4e9dbbb35d0cbf0e4e26ac4097..58238406e65582487a52ada9c6aa4003c92f8c3b 100644 (file)
--- 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__
index ae7e81333da0f63af5d57600b3f8d7725b3adcd9..9d351c9f92d57d245a35ea88b538d209fca6c0f6 100644 (file)
--- 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);
index 51f936bb2350a3dff0dad97c2dc68bd4870c844c..5415f05770fa0784fa0eb31971495d023bf857c1 100644 (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