How to make makefile with error when using loop?

If I have the following bash command:

for i in ./ x ; do ls $i ; done && echo OK 
Performed

"ls./" and then "ls x" which does not work (x is absent) and OK is not printed.

If

 for i in x ./ ; do ls $i ; done && echo OK 

then even if "ls x" fails because the last statement in the for loop succeeded, then OK is printed. This is a problem when using the shell for loops in makefiles:

 x: for i in $(LIST) ; do \ cmd $$i ;\ done 

How can I make make fail if any of the individual cmd executions fail?

+6
source share
1 answer

Use the break command to end the loop if the command fails.

 x: for i in $(LIST) ; do \ cmd $$i || break ;\ done 

This will not disable the makefile. Instead, you can use exit with non-zero code:

 x: for i in $(LIST) ; do \ cmd $$i || exit 1 ;\ done 
+15
source

Source: https://habr.com/ru/post/956200/


All Articles