make -j optimization

Mark Hertel mhertel at aptima.com
Thu Sep 30 16:45:00 EDT 2004


David Kramer wrote:

>Major DOH!
>
>Apparently make is not smart enough to not build things it doesn't have 
>the dependencies for yet.  Huh?  Make has one function and one function 
>only: build dependencied before the things that need them.  
>
>I was trying to compile Rogue Wave.  There are about 20 or 30 .o target
>files that get build from .cpp files.  Then there's a library that gets
>built from the .o files.  Even though the makefile correctly had the .c
>files as dependencies for the .o files, and the .o files as dependencies
>for the library, it tried to "ar" the library together before all the .o 
>files were created, resulting in about half of them being "not found".
>
>That blows.  How could they get that wrong?  If it's not going to be smart 
>enough to try building a target until its dependencies are built, then at 
>least only parallelize the commands to build one target at a time.
>  
>
I used this many years ago, but I remember that the -j spread out the 
make targets to multiple processes. So if you have a rule

objs : $(SOURCES) $(INCLUDES)
    gcc $*

the -j doesn't spread out the 'gcc' invocations, it would put the 'objs' 
target in one process and then it would find another make target and 
start it up immediately.

When I used it I spent a long time reorganizing the make file so that I 
had 4 separate targets to build the source (I was using a 4way Sparcserver).


--Mark



More information about the Discuss mailing list