Make: perform an action for each premise

I would like to create a rule similar to this in my Makefile:

log: test_A test_B
    ./test_A >> $@
    ./test_B >> $@

but test_Aand test_Bare part of the variable $(TESTS).

So, is it possible to do an action (here: call the program) for each necessary condition in GNU / make?

Note: How do you make a file rule fulfill its preconditions? does not completely solve this problem, since target log( make log) is required .

+5
source share
1 answer

Essentially, you want to go through the preconditions. The obvious way to do this is to punt the shell:

log: test_A test_B
        for f in $^; do ./$$f; done

GNU Make foreach, , , , ( define) (.. ):

log: test_A test_B
        $(foreach f,$^,./$(f);)

, , , :

log: test_A test_B
        $(patsubst %,./%;,$^)

( , $(TESTS), .)

+16

All Articles