help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about parallel optimzation


From: Oleksandr Gavenko
Subject: Re: question about parallel optimzation
Date: Wed, 13 Apr 2011 16:30:09 +0300
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9

On 13.04.2011 14:24, Toralf Förster wrote:
> Hello,
>
> related to the parallel build capabilities I'm wondering how make does
> optimize the build process.
>
Make do not make copy of itself unless you invoke it for recursive build:

SHELL = /bin/sh

parallel-build:
        make -C $(dir1) & make -C $(dir2) &

Above example have disadvantage as main Make do not wait for spawned child processes.

You can simulate parallel building with waiting with GNU xargs utility:

DIR_LIST := $(patsubst %/.,%,$(wildcard */.))
CPUCNT := 4

# $(1)  list of subdirs
# $(2)  target name
define process-subdirs
  for d in $(1); do \
    [ -f $$d/Makefile ] && echo $$d || :; \
  done | xargs --max-procs=$(CPUCNT) --no-run-if-empty -n 1 make $(2) -C
endef

.PHONY: all
all:
        $(call process-subdirs,$(DIR_LIST),$@)

Make can run in parallel independent targets in processing of single Makefile by -j NUM option.

--
С уважением, Александр Гавенко.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]