From 356bfacef7da39052d404e2db166996cf7b74d4d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 20 Apr 2024 16:08:09 +0100 Subject: make: skip shell -e option when running commands POSIX says, regarding execution of commands: The execution line shall then be executed by a shell as if it were passed as the argument to the system() interface, except that if errors are not being ignored then the shell -e option shall also be in effect. As a non-POSIX extension, skip the use of the -e option. This is how GNU make and BSD make behave. (GitHub issue #409) --- miscutils/make.c | 3 +-- testsuite/make.tests | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 87f17aad7..970919ddc 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -2217,7 +2217,7 @@ docmds(struct name *np, struct cmd *cp) if (sdomake) { // Get the shell to execute it int status; - char *cmd = !signore ? auto_concat("set -e;", q) : q; + char *cmd = !signore && posix ? auto_concat("set -e;", q) : q; target = np; status = system(cmd); @@ -2233,7 +2233,6 @@ docmds(struct name *np, struct cmd *cp) diagnostic("failed to build '%s'", np->n_name); estat |= MAKE_FAILURE; free(command); - free(cmd); break; } else if (doinclude) { warning("failed to build '%s'", np->n_name); diff --git a/testsuite/make.tests b/testsuite/make.tests index 1fc95a8d2..c512fbdaa 100755 --- a/testsuite/make.tests +++ b/testsuite/make.tests @@ -497,6 +497,13 @@ test.b: ' cd .. || exit 1; rm -rf make.tempdir 2>/dev/null +# Don't use the shell -e option when running commands. +testing "make no shell -e option when running commands" \ + "make -f -" "OK\n" "" ' +target: + @false; echo OK +' + # An empty original suffix indicates that every word should have # the new suffix added. If neither suffix is provided the words # remain unchanged. -- cgit v1.2.3-55-g6feb