static struct variable *
define_makeflags (int all, int makefile)
{
- const char ref[] = "$(MAKEOVERRIDES)";
- const char posixref[] = "$(-*-command-variables-*-)";
+ const char ref[] = "MAKEOVERRIDES";
+ const char posixref[] = "-*-command-variables-*-";
const char evalref[] = "$(-*-eval-flags-*-)";
const struct command_switch *cs;
char *flagstring;
#undef ADD_FLAG
/* Four more for the possible " -- ", plus variable references. */
- flagslen += 4 + CSTRLEN (posixref) + 1 + CSTRLEN (evalref) + 1;
+ flagslen += 4 + CSTRLEN (posixref) + 4 + CSTRLEN (evalref) + 4;
/* Construct the value in FLAGSTRING.
We allocate enough space for a preceding dash and trailing null. */
p += CSTRLEN (evalref);
}
- if (all && command_variables)
+ if (all)
{
- /* Write a reference to $(MAKEOVERRIDES), which contains all the
- command-line variable definitions. Separate the variables from the
- switches with a "--" arg. */
+ /* If there are any overrides to add, write a reference to
+ $(MAKEOVERRIDES), which contains command-line variable definitions.
+ Separate the variables from the switches with a "--" arg. */
- strcpy (p, " -- ");
- p += 4;
+ const char *r = posix_pedantic ? posixref : ref;
+ size_t l = strlen (r);
+ struct variable *v = lookup_variable (r, l);
- /* Copy in the string. */
- if (posix_pedantic)
- {
- memcpy (p, posixref, CSTRLEN (posixref));
- p += CSTRLEN (posixref);
- }
- else
+ if (v && v->value && v->value[0] != '\0')
{
- memcpy (p, ref, CSTRLEN (ref));
- p += CSTRLEN (ref);
+ strcpy (p, " -- ");
+ p += 4;
+
+ *(p++) = '$';
+ *(p++) = '(';
+ memcpy (p, r, l);
+ p += l;
+ *(p++) = ')';
}
}
# Test some basic recursion.
run_make_test('
+.RECIPEPREFIX := |
all:
- $(MAKE) -f #MAKEFILE# foo
+| $(MAKE) -f #MAKEFILE# foo
foo:
- @echo $(MAKE)
- @echo MAKELEVEL = $(MAKELEVEL)
- $(MAKE) -f #MAKEFILE# last
+| @echo $(MAKE)
+| @echo MAKELEVEL = $(MAKELEVEL)
+| $(MAKE) -f #MAKEFILE# last
last:
- @echo $(MAKE)
- @echo MAKELEVEL = $(MAKELEVEL)
- @echo THE END
+| @echo $(MAKE)
+| @echo MAKELEVEL = $(MAKELEVEL)
+| @echo THE END
',
('CFLAGS=-O -w' . ($parallel_jobs ? ' -j 2' : '')),
($vos
MAKEOVERRIDES = a=AA
');
+# SV 46013: Ensure that MAKEOVERRIDES is passed even if set in the makefile
+run_make_test(q!
+ifeq ($(MAKELEVEL),0)
+MAKEOVERRIDES += FOO+=bar
+endif
+.PHONY: M R
+M: ; @$(MAKE) --no-print-directory -f #MAKEFILE# R
+R: ; @echo '$(FOO)'
+!,
+ '', 'bar');
+
1;