One workaround is to manually call exit on error.
For example, suppose we have a directory called scripts with several shell scripts (with file names ending in .sh ) that we want to execute.
Then a variable declaration like this:
LIST_OF_SCRIPTS ?= $(wildcard scripts/*.sh)
will give us a list of these scenarios and a goal similar to this:
run-all-scripts @$(foreach scriptfile,$(LIST_OF_SCRIPTS),$(scriptfile);)
it will run all of these scripts, but as you noticed, the foreach loop will continue to work regardless of whether one of the scripts returns an error code. Adding || exit || exit || exit || exit to the command will force the subcommand to terminate in the event of an error, which will then be considered an error.
For instance,
run-all-scripts @$(foreach scriptfile,$(LIST_OF_SCRIPTS),$(scriptfile) || exit;)
will do what you want (I believe).
In particular, using your pseudo-code example, I think you want something like this:
$(foreach var,$(list), $($(var)_stuff) $($(var)_more_stuff)): @echo Building $@ from $^... ($(CC) $(FLAGS) ...) || exit
(where all I changed is the completion of the (CC) $(FLAGS)... bit (CC) $(FLAGS)... in the paren and adding || exit to fail on error).
source share