Search This Blog

Thursday, November 06, 2008

GNU make slow build process

While building one my project it was taking too much time; the project was taking around 40-60 seconds to build and around 20 seconds to clean. I was frustrated with this because the debugging cycle time for my project was going high.

So I decided to stop debugging my project and start debugging the build process. In my makefile I had .SILENT option and I removed it to see what is going.  The following was the output
make[1]: Entering directory `/cygdrive/g/Projects/Ace3/src/lib'
make[2]: Entering directory `/cygdrive/g/Projects/Ace3/src/lib/string'
make[2]: Nothing to be done for `all'.
..
make[1]: Leaving directory `/cygdrive/g/Projects/Ace3/src/lib'
make[1]: Entering directory `/cygdrive/g/Projects/Ace3/src/kernel'
..
make[2]: Leaving directory `/cygdrive/g/Projects/Ace3/src/kernel/pic'
New kernel is at /cygdrive/g/Projects/Ace3/obj/kernel.sys
/cygdrive/g/Projects/Ace3/img/create_bootcd.sh
Everything was fast, however there was huge delay before getting the output “make[1]: Leaving directory `/cygdrive/g/Projects/Ace3/src/lib'”

Then I tried invoking make with –d (debug) option and it gave the following output
This program built for i686-pc-cygwin
Reading makefiles...
Reading makefile `makefile'...
Reading makefile `/cygdrive/g/Projects/Ace3/make.conf' (search path) (no ~ expansion)...
Reading makefile `boot_module.d' (search path) (don't care) (no ~ expansion)...
Reading makefile `interrupt.d' (search path) (don't care) (no ~ expansion)...
Reading makefile `ktrace.d' (search path) (don't care) (no ~ expansion)...
Reading makefile `main.d' (search path) (don't care) (no ~ expansion)...
And it took lot of time before continuing the from the above step, so I knew something wrong with the main.c dependency file, so I opened it and it had too many entries. I casually checked the size of the file and it was 50MB. That explained why make was slow. I carefully examined the dependency entries and found they were repeating. I opened make.conf and checked the rule for making dependency file and found the culprit 
%.d:    %.c
@$(CC) -c -M $< -I$(INCLUDE) $(CFLAGS) >> $@
The output redirection symbol >> caused the problem. It appended the dependency rules every time I compiled and increased the size of .d file.  I replaced >> with > and now incremental build process completes in 3 seconds.

0 comments: