Innot Kauker
Innot Kauker

Reputation: 1373

Makefile: execute all statements in a subtarget before going to the next subtarget

I have the following makefile:

b:
    sleep 2 && echo b1
    sleep 2 && echo b2
    sleep 2 && echo b3

a:
    sleep 2 && echo a1
    sleep 2 && echo a2
    sleep 2 && echo a3

all: | a b
    sleep 2 && echo all

I want subtargets a and b executed sequentially in a parallel build and add | before them. But instead of having something like

sleep 2 && echo a1
a1
sleep 2 && echo a2
a2
sleep 2 && echo a3
a3
sleep 2 && echo b1
b1
sleep 2 && echo b2
b2
sleep 2 && echo b3
b3
sleep 2 && echo all
all

after calling make all -j3, I get

sleep 2 && echo a1
sleep 2 && echo b1
a1
b1
sleep 2 && echo a2
sleep 2 && echo b2
a2
b2
sleep 2 && echo a3
sleep 2 && echo b3
b3
a3
sleep 2 && echo all
all

Is there a way to enforce the behaviour I expected without putting all commands in each target is a separate script? I mean, that all subtargets of all would be executed in order, but their subtargets could be done in parallel.

Upvotes: 0

Views: 1029

Answers (1)

MadScientist
MadScientist

Reputation: 101081

Saying all : | a b means that both a and b must complete before all, but you have said nothing about a and b in relation to each other.

If you want to run a before b, then you have to declare:

b: a

Upvotes: 2

Related Questions