Reputation: 2887
I use the following code to execute targets in parallel. Now what I want that it will work in parallel but there is some targets that need to be executed at the end, like wait
for 3 processes that run in parallel to finish and then execute another 2 processes. How can I do that?
For example here is pack
and cleanup
to run after module1
and module2
will run in parallel.
NPROCS = $(shell sysctl hw.ncpu | grep -o '[0-9]\+')
MAKEFLAGS += -j$(NPROCS)
all: module1 module2
.PHONY: module1
module1:
@echo "run module 1"
DIR=$(PWD)
@echo $(DIR)
.PHONY: module2
module2:
@echo "run module2”
.PHONY:
pack:
pack $(DIR)
cleanup:
gbt clean $(DIR)
Upvotes: 1
Views: 467
Reputation: 6351
This is what prerequisites, one of make
’s great strengths, are for.
Change:
pack:
↓
pack: module1 module2
Which tells make
that the pack
target has two prerequisites; module1
and module2
.
This means make
won’t run pack
until both module1
and module2
have finished running. Whether they run in parallel won’t make a difference.
If you have a lot of prerequisites, you can put them in a macro, e.g:
modules = module1 module2 …
pack: $(modules)
Upvotes: 1