On 2022-06-25 18:20, Bruno Haible wrote: > Hi, > > When I have a Makefile rule > > target: $(DEPS1) $(DEPS2) > command1 > > it is guaranteed that $(DEPS1) and $(DEPS2) will be done, including their > dependencies, before command1 is started. > However, with -j, $(DEPS1) and $(DEPS2) are being made in parallel. If this > is not desired, I can transform this rule to > > target: $(DEPS1) > test -z "$(DEPS2)" || $(MAKE) $(DEPS2) > command1
By the way, if parallelism is not desired, mention this special target somewhere in the Makefile: .NOTPARALLEL: Then -j is ignored. > > or (equivalently?) > > target: $(DEPS1) > $(MAKE) target2 Whether equivalent or not, resorting to a re-execution of make is ugly. We'd like to avoid it. > target2: $(DEPS2) > command1 > .PHONY: target2 If there is an order among the DEPS1 and DEPS2 dependencies, you have to express it to Make! Here is a small Makefile: DEPS1 := d1a d1b d1c DEPS2 := d2a d2b d2c all: $(DEPS1) $(DEPS2) @echo making $@ from $(DEPS1) and $(DEPS2) %: @echo making $@ # Uncomment! # $(DEPS1): $(DEPS2) If you run it with "make -j", you can see perturbation of the order of the "making d1a" messages. Often, targets from the DEPS1 group are made before some from the DEPS2. But if you uncomment the indicated line, that is prevented. Now when you run "make -j", the order is perturbed within the two groups, but DEPS2 are all done before DEPS1. Cheers ....