return 0;
if (shellflags == 0)
- shellflags = posix_pedantic ? "-ec" : "-c";
+ shellflags = posix_pedantic && NONE_SET (flags, COMMANDS_NOERROR) ? "-ec" : "-c";
/* See if it is safe to parse commands internally. */
if (shell == 0)
char **argv;
{
+ struct variable *var;
/* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
int save = warn_undefined_variables_flag;
warn_undefined_variables_flag = 0;
}
#endif /* __EMX__ */
- shellflags = allocated_variable_expand_for_file ("$(.SHELLFLAGS)", file);
+ var = lookup_variable_for_file (STRING_SIZE_TUPLE (".SHELLFLAGS"), file);
+ if (!var)
+ shellflags = xstrdup ("");
+ else if (posix_pedantic && var->origin == o_default)
+ /* In POSIX mode we default to -ec, unless we're ignoring errors. */
+ shellflags = xstrdup (ANY_SET (cmd_flags, COMMANDS_NOERROR) ? "-c" : "-ec");
+ else
+ shellflags = allocated_variable_expand_for_file (var->value, file);
+
ifs = allocated_variable_expand_for_file ("$(IFS)", file);
warn_undefined_variables_flag = save;
return 0;
}
+/* Lookup a variable whose name is a string starting at NAME
+ and with LENGTH chars. NAME need not be null-terminated.
+ Returns address of the 'struct variable' containing all info
+ on the variable, or nil if no such variable is defined. */
+
+struct variable *
+lookup_variable_for_file (const char *name, size_t length, struct file *file)
+{
+ struct variable *var;
+ struct variable_set_list *savev;
+
+ if (file == NULL)
+ return lookup_variable (name, length);
+
+ savev = current_variable_set_list;
+ current_variable_set_list = file->variables;
+
+ var = lookup_variable (name, length);
+
+ current_variable_set_list = savev;
+
+ return var;
+}
\f
/* Lookup a variable whose name is a string starting at NAME
and with LENGTH chars in set SET. NAME need not be null-terminated.
unsigned int min, unsigned int max, unsigned int flags,
gmk_func_ptr func);
struct variable *lookup_variable (const char *name, size_t length);
+struct variable *lookup_variable_for_file (const char *name, size_t length,
+ struct file *file);
struct variable *lookup_variable_in_set (const char *name, size_t length,
const struct variable_set *set);
# Ensure turning on .POSIX enables the -e flag for the shell
-run_make_test(qq!
+run_make_test(q!
.POSIX:
-all: ; \@#HELPER# -q fail 1; true
+all: ; @#HELPER# -q fail 1; #HELPER# out hello
!,
'', "#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512);
+# But explicit settings must still take precedence
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+.SHELLFLAGS = -c
+!,
+ '', "hello");
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+all: .SHELLFLAGS = -c
+!,
+ '', "hello");
+
+# SV 63667: We shouldn't add -e to sh if errors are ignored
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+!,
+ '', "hello\n");
+
+# But explicit settings must still take precedence
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+.SHELLFLAGS = -ec
+!,
+ '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n");
+
+run_make_test(q!
+.POSIX:
+all: ; @-#HELPER# -q fail 1; #HELPER# out hello
+all: .SHELLFLAGS = -ec
+!,
+ '', "#MAKE#: [#MAKEFILE#:3: all] Error 1 (ignored)\n");
+
# User settings must override .POSIX
# In the standard .POSIX must be the first thing in the makefile
# but we relax that rule in GNU Make.