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.

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

_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to