[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: parallel compilation of subdirs
From: |
John Graham-Cumming |
Subject: |
Re: parallel compilation of subdirs |
Date: |
Thu, 29 Nov 2007 19:27:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
David Larson wrote:
>> I have the following Makefile, which will go to each subdir and call
>> "make". But "make" in each subdir can not be executed in parallel
>> (when I "make" in the parent dir with -j option). I'm wondering if
>> there is any way to enable parallel compilation.
>
> That is one of the problems with recursive make. See:
>
> Recursive Make Considered Harmful.
> http://aegis.sourceforge.net/auug97.pdf
That is an interesting paper even if it's getting a little long in the
tooth. You can also read more about parallelization of GNU Make in the
following article I wrote for CM Basics:
http://www.cmcrossroads.com/articles/ask-mr.-make/-the-pitfalls-and-benefits-of-gnu-make-parallelization.html
And if you are trying to do away with recursive make I put together
another article on that subject here:
http://www.cmcrossroads.com/articles/ask-mr.-make/painless-non%11recursive-make.html
Having said all that the original question posed by Yu is actually
answered in the GNU Make manual itself. It is possible to do recursive,
parallel GNU Make because of the cleverness of GNU Make's job server
system (which you can read all about here:
http://make.paulandlesley.org/jobserver.html).
The relevant section of the GNU Make manual is:
http://www.gnu.org/software/make/manual/make.html#Phony-Targets. It's a
pity that this important topic is covered under Phony Targets, but it
_is_ there.
Yu's original Makefile looked like this:
SUBDIRS = $(filter-out Makefile%, $(wildcard *))
.PHONY: all
all:
@for dir in $(filter-out backup, $(SUBDIRS)); do \
$(MAKE) -C $$dir; \
done
The parallel way to do this is
SUBDIRS = $(filter-out backup Makefile%, $(wildcard *))
.PHONY: all $(SUBDIRS)
all: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
John.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHTwR1Lphrp73n/hARAvSdAJ47ynxDjQYZCFf9fyPNvjZJsrlwlACdHLXw
/ZR3Xi5lCI5em+w4hdbRrOc=
=QciG
-----END PGP SIGNATURE-----