makefile - Parallel Make - Sub-Projects called multiple times -
the question answered on file-level. have bigger project has quite lot of inter-project-dependencies (caused dbus headers, generated dynamically).
i ve created following example (example files zip - real project more complex).
the top-level makefile
following:
sub-%: $(make) -c $(patsubst sub-%,%,$@) default: $(make) -j12 sub-p1 sub-p2 sub-p3
the makefile of sub-project (p1
, p2
, p3
):
all: p1 ../lib/lib.a: $(make) -c ../lib lib.a p1: ../lib/lib.a cp -f ../lib/lib.a p1
and makefile of lib
looks this:
lib.a: sleep 2 date > $@ echo done building $@
the problem: library built each p*
-project separately in parallel - in example it's not problem, in our case causes unsolvable problems.
when call make
on top-level, following output:
$ make make -j12 sub-p1 sub-p2 sub-p3 make[1]: entering directory '/home/kkr/tmp/parallelmake' make -c p1 make -c p2 make -c p3 make[2]: entering directory '/home/kkr/tmp/parallelmake/p1' make -c ../lib lib.a make[2]: entering directory '/home/kkr/tmp/parallelmake/p2' make -c ../lib lib.a make[2]: entering directory '/home/kkr/tmp/parallelmake/p3' make -c ../lib lib.a make[3]: entering directory '/home/kkr/tmp/parallelmake/lib' make[3]: entering directory '/home/kkr/tmp/parallelmake/lib' make[3]: entering directory '/home/kkr/tmp/parallelmake/lib' sleep 2 sleep 2 sleep 2 date > lib.a date > lib.a date > lib.a make[3]: leaving directory '/home/kkr/tmp/parallelmake/lib' make[3]: leaving directory '/home/kkr/tmp/parallelmake/lib' make[3]: leaving directory '/home/kkr/tmp/parallelmake/lib' cp -f ../lib/lib.a p3 cp -f ../lib/lib.a p1 cp -f ../lib/lib.a p2 make[2]: leaving directory '/home/kkr/tmp/parallelmake/p3' make[2]: leaving directory '/home/kkr/tmp/parallelmake/p1' make[2]: leaving directory '/home/kkr/tmp/parallelmake/p2' make[1]: leaving directory '/home/kkr/tmp/parallelmake'
question: possible synchronize sub-projects somehow automatically?
since real project
has 13 sub-projects - of them having inter-project-dependencies - manual synchronization quite difficult.
there no way recursive make system "automatically" synchronize this; separate processes , have no way tell each other running given target.
you have 2 choices. first, best may lot of work, rework build system it's non-recursive. if have single make invocation builds entire system there 1 instance of make, , globally coordinate creation of targets. won't need $(make) -c ../lib lib.a
rules @ all.
if that's not feasible, need rewrite top-level makefile enforce ordering such never start making 2 directories depend on same external target, @ same time. example instead of top-level makefile show above, write this:
default: p1 p2 p3 p%: ; $(make) -c $@ .phony: default p1 p2 p3
now suppose want ensure p1
runs before p2
, p3
because want p1
build shared targets; you'd add rule top-level makefile:
p2 p3: p1
and can add other orderings needed.
Comments
Post a Comment