Using make to execute independent tasks in parallel
See pattern rules
Another way, if this is the single reason why you need make
, is to use -n
and -P
options of xargs
.
First the easy part. As Roman Cheplyaka points out, pattern rules are very useful:
LOGS = log.1 log.2 ... log.4096all: $(LOGS)log.%: command -n $* > log.$*
The tricky part is creating that list, LOGS
. Make isn't very good at handling numbers. The best way is probably to call on the shell. (You may have to adjust this script for your shell-- shell scripting isn't my strongest subject.)
NUM_LOGS = 4096LOGS = $(shell for ((i=1 ; i<=$(NUM_LOGS) ; ++i)) ; do echo log.$$i ; done)