On Fri, 2007-10-12 at 19:01 +0200, Eli Zaretskii wrote:
> > And if it's expanded right here then won't the automatic variables like
> > $@, $^, and $? not be set yet?
> 
> Yes.  That is why the modified patch below installs the original
> value, not the expanded one (as the original patch mistakenly did).

Ah!  That makes more sense to me.  Thanks!

> Btw, I wonder whether I should recursively_expand the value, not just
> expand it once, in case the first expansion still yields variables
> and/or functions.  WDYT?

All expansion in make is recursive; there's no such thing as an
expansion that just does "the first level".  It already does what you'd
expect, as far as I can see, just by using allocated_variable_expand().

> Oh, and I think there's no memory leak introduced by the patch,
> because do_variable_definition does this just before it returns:
> 
>   if (alloc_value)
>     free (alloc_value);

True, but before that happens you drop whatever memory alloc_value is
set to, here:

> +      else if (find_and_set_default_shell (alloc_value = 
> allocated_variable_expand (p)))

so that's the memory leak.  But, I fixed this and applied this patch;
let me know if I messed something up:

2007-10-12  Eli Zaretskii  <[EMAIL PROTECTED]>

        * variable.c (do_variable_definition): Allow $(SHELL) to expand to
        a more complex value than a simple shell: if it's not a default
        shell now then expand it and see if is a default shell then.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <[EMAIL PROTECTED]>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
Index: variable.c
===================================================================
RCS file: /sources/make/make/variable.c,v
retrieving revision 1.92
diff -u -r1.92 variable.c
--- variable.c	4 Jul 2007 19:35:20 -0000	1.92
+++ variable.c	13 Oct 2007 01:23:37 -0000
@@ -1188,7 +1188,24 @@
           no_default_sh_exe = 0;
         }
       else
-        v = lookup_variable (varname, strlen (varname));
+        {
+          if (alloc_value)
+            free (alloc_value);
+
+          alloc_value = allocated_variable_expand (p);
+          if (find_and_set_default_shell (alloc_value))
+            {
+              v = define_variable_in_set (varname, strlen (varname), p,
+                                          origin, flavor == f_recursive,
+                                          (target_var
+                                           ? current_variable_set_list->set
+                                           : NULL),
+                                          flocp);
+              no_default_sh_exe = 0;
+            }
+          else
+            v = lookup_variable (varname, strlen (varname));
+        }
     }
   else
 #endif
_______________________________________________
Make-w32 mailing list
Make-w32@gnu.org
http://lists.gnu.org/mailman/listinfo/make-w32

Reply via email to