0

I've this Makefile

framework:
    @$(MAKE) -C $(HIGGSBASESELECTOR) 
    @$(MAKE) -C $(MATRIX4)
    @$(MAKE) -C $(SUBSELECTOR)
    @$(MAKE) -C $(MCSUBSELECTOR)
    @$(MAKE) -C $(MATRIXSUBSELECTOR)
    @$(MAKE) -C $(CHECKSUBSELECTOR)
    ...

if I run

 make -j framework

it uses only one process. What is the best (and fast) way to refactor this Makfile to parallize the compilation?

Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141

1 Answers1

0

Your rule executes the $(MAKE) commands in sequence, so it's not surprising that you see only one process at a time.

A quick and dirty approach (if nothing's waiting for the results of these calls) is

framework:
    @$(MAKE) -C $(HIGGSBASESELECTOR) &
    @$(MAKE) -C $(MATRIX4) &
    @$(MAKE) -C $(SUBSELECTOR) &
    @$(MAKE) -C $(MCSUBSELECTOR) &
    @$(MAKE) -C $(MATRIXSUBSELECTOR) &
    @$(MAKE) -C $(CHECKSUBSELECTOR) &

If that makes your blood run cold (and it should) you can do it this way:

framework: $(HIGGSBASESELECTOR) $(MATRIX4) $(SUBSELECTOR) ...
    do things after the calls

.PHONY: $(HIGGSBASESELECTOR) $(MATRIX4) $(SUBSELECTOR) ...
$(HIGGSBASESELECTOR) $(MATRIX4) $(SUBSELECTOR) ...:
    @$(MAKE) -C $@
Beta
  • 96,650
  • 16
  • 149
  • 150
  • I get: `Makefile:88: *** multiple target patterns. Stop.` on the `.PHONY` line – Ruggero Turra Sep 20 '12 at 20:28
  • I assumed `HIGGSBASESELECTOR`, `MATRIX4` and so on were simple paths. What are they? (Also, I assume you know that by `...` I mean the rest of the target directories, `MCSUBSELECTOR` and so on.) – Beta Sep 20 '12 at 22:08
  • Can you give an example of a path that produces the error? Also, what version of Make are you using? – Beta Sep 20 '12 at 22:24