diff --git a/NEWS b/NEWS index e60644a1..6e2c5c65 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,12 @@ http://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=108&set This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable. +* WARNING: Backward-incompatibility! + Previously appending using '+=' to an empty variable would result in a value + starting with a space. Now the initial space is only added if the variable + already contains some value. Similarly, appending an empty string does not + add a trailing space. + * The previous limit of 63 jobs under -jN on MS-Windows is now increased to 4095. That limit includes the subprocess started by the $(shell) function. diff --git a/doc/make.texi b/doc/make.texi index c7c0f4f9..dfa44549 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -5720,7 +5720,8 @@ objects += another.o @noindent This takes the value of the variable @code{objects}, and adds the text -@samp{another.o} to it (preceded by a single space). Thus: +@samp{another.o} to it (preceded by a single space, if it has a value +already). Thus: @example objects = main.o foo.o bar.o utils.o diff --git a/tests/scripts/variables/flavors b/tests/scripts/variables/flavors index ba133ea8..ed060dcb 100644 --- a/tests/scripts/variables/flavors +++ b/tests/scripts/variables/flavors @@ -93,4 +93,23 @@ all: ; @echo $(foo) ', '', "Goodbye\n"); +# TEST 8: Append to empty +run_make_test(q! +recur = +recur += foo +simple := +simple += bar +recur_empty = foo +recur_empty += +simple_empty := bar +simple_empty += +empty_recur = +empty_recur += +empty_simple := +empty_simple += + +all: ; @: $(info recur=/$(recur)/ simple=/$(simple)/ recure=/$(recur_empty)/ simplee=/$(simple_empty)/ erecur=/$(empty_recur)/ esimple=/$(empty_simple)/) +!, + '', "recur=/foo/ simple=/bar/ recure=/foo/ simplee=/bar/ erecur=// esimple=//\n"); + 1; diff --git a/variable.c b/variable.c index 36ab1f45..15096b0b 100644 --- a/variable.c +++ b/variable.c @@ -1197,7 +1197,7 @@ do_variable_definition (const floc *flocp, const char *varname, The value is set IFF the variable is not defined yet. */ v = lookup_variable (varname, strlen (varname)); if (v) - return v->special ? set_special_var (v) : v; + goto done; conditional = 1; flavor = f_recursive; @@ -1253,15 +1253,29 @@ do_variable_definition (const floc *flocp, const char *varname, buffer if we're looking at a target-specific variable. */ val = tp = allocated_variable_expand (val); - oldlen = strlen (v->value); + /* If the new value is empty, nothing to do. */ vallen = strlen (val); + if (!vallen) + { + alloc_value = tp; + goto done; + } + + oldlen = strlen (v->value); p = alloc_value = xmalloc (oldlen + 1 + vallen + 1); - memcpy (alloc_value, v->value, oldlen); - alloc_value[oldlen] = ' '; - memcpy (&alloc_value[oldlen + 1], val, vallen + 1); + + if (oldlen) + { + memcpy (alloc_value, v->value, oldlen); + alloc_value[oldlen] = ' '; + ++oldlen; + } + + memcpy (&alloc_value[oldlen], val, vallen + 1); free (tp); } + break; } } @@ -1405,8 +1419,8 @@ do_variable_definition (const floc *flocp, const char *varname, v->append = append; v->conditional = conditional; + done: free (alloc_value); - return v->special ? set_special_var (v) : v; }