Creating mutually exclusive jobs in GNU?

Using GNU make, is it possible to create a set of goals that will never be planned using the --jobs option?

Reference Information:

To make this a little more specific, consider a make form file

p1: ...deps... # no parallelization conflicts (can run at the same time as p*, e*) ...rules... p2: ...deps... # no parallelization conflicts (can run at the same time as p*, e*) ...rules... p3: ...deps... # no parallelization conflicts (can run at the same time as p*, e*) ...rules... e1: ...deps... # cannot run at same time as any other e* ...rules... e2: ...deps... # cannot run at same time as any other e* ...rules... e3: ...deps... # cannot run at same time as any other e* ...rules... 

The main thing I need to do is make sure that e1, e2 and e3 are never processed at the same time, because they do some work on an embedded device with limited resources. They crash if several of them are running at the same time. p1, p2 and p3 can be executed in parallel with anything, including any task e *.

Please note that the actual makefile has several thousand goals with a dependency tree, which is about 10 levels, so I hope there is a way to do this so that (a) does not require serial runs and (b) preserves the benefits of coding the dependency tree in the file makefile.

+4
source share
2 answers

One option for you is to use the "flock" to run the "e" rules under exclusive lock. See Man flock (1) for more details. For example, instead of

 e2: deps my_cmd foo bar 

You may have

 e2: deps flock .embedded-device-lock -c my_cmd foo bar 

What happens then is that all the "e" targets start with parallel (maybe), but the actual commands will be executed in series.

+6
source

This is not an ideal solution, but you can use the precondition for ordering to place a specific order for e * targets:

 e1: ...deps... ...commands... e2: ...deps... | e1 ...commands... e3: ...deps... | e2 e1 ...commands... 

Prerequisites after pipe symbol '|' are only ordinal: they do not force, say, e3 to be updated if e1 or e2 has changed, but they require that all commands for e1 and e2 end before the commands for e3 are run.

The disadvantage of this is that it imposes a specific order for these mutually exclusive preconditions, instead of having to choose an order, but in practice, you can probably find a reasonable order manually.

+2
source

All Articles