Reputation: 11377
If I have a list of n commands, c = c1 ... cn, how can I execute them in order for a given target? I tried the foreach construct
$(foreach x,$(c),./$(x))
but that puts all the commands on one line. Any clues?
Upvotes: 11
Views: 11484
Reputation: 4462
If there is no need to check for success, then adding semicolon should work:
$(foreach x,$c,./$(x);)
If you need to fail if one of the command in the list returns failure, you need to break it in steps. Instead of directly executing the commands, we wrap the execution in a make function:
define execute-command
$(1)
endef
execute-list:
$(foreach x,$(c),$(call execute-command,./$(x)))
Upvotes: 15
Reputation: 15493
You identified the problem (“but that puts all the commands on one line”). You just need to append a newline whenever you expand $x
in your loop.
define \n
endef
Now simply use $(foreach x,$c,./$(x)${\n})
in your recipe.
Upvotes: 16