Hello, I decided to try out the header precompilation feature of newer GCCs to see if it would speed up kernel building. Following is a patch which 1) adds "headers" target to top-level makefile, 2) allows and compiles .h files into .h.gch using gcc. When gcc compiles the normal C files, it looks for the precompiled headers by default, and no change is needed.
I am not a kbuild expert, so I want to ask if my changes are done correctly. It seems to me that the build in fact slows down tremendously, and I don't know why. It seems that the last "make" does nothing at all for a long time before finally starting as normal, so most of the "extra" time comes from before anything is compiled at all. For instance, just compiling the kernel/ subdir with and without the precompiled headers: make clean scripts/; time make kernel/ real 0m27.174s user 0m23.760s sys 0m3.003s make clean scripts/; make headers; time make kernel/ real 0m53.076s user 0m25.211s sys 0m4.155s By the way, according to the GCC manual [1], "Only one precompiled header can be used in a particular compilation", which, if I interpret it correctly, might make header precompilation useless for the kernel anyway. But here's my attempt (I hope the patch comes through okay). Kind regards, Vegard Nossum [1] http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html >From 41d6eeab27442cec728596123bb6f4ecb143b9a3 Mon Sep 17 00:00:00 2001 From: Vegard Nossum <[EMAIL PROTECTED]> Date: Wed, 30 May 2007 19:01:10 +0200 Subject: [PATCH] [kbuild] Added support for precompiled headers --- Makefile | 13 ++++++++++++- scripts/Makefile.build | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index 562a909..48f2b68 100644 --- a/Makefile +++ b/Makefile @@ -1046,7 +1046,7 @@ clean: archclean $(clean-dirs) @find . $(RCS_FIND_IGNORE) \ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ - -o -name '*.symtypes' \) \ + -o -name '*.symtypes' -o -name '*.h.gch' \) \ -type f -print | xargs rm -f # mrproper - Delete all generated files, including .config @@ -1116,6 +1116,7 @@ help: @echo ' cscope - Generate cscope index' @echo ' kernelrelease - Output the release version string' @echo ' kernelversion - Output the version stored in Makefile' + @echo ' headers - Build precompiled headers' @if [ -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \ echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ echo ' (default: $(INSTALL_HDR_PATH))'; \ @@ -1252,6 +1253,14 @@ prepare: ; scripts: ; endif # KBUILD_EXTMOD + +# Compile headers +# --------------------------------------------------------------------------- + +headers: FORCE + $(Q)$(MAKE) -i $(build)=include + + # Generate tags for editors # --------------------------------------------------------------------------- @@ -1424,6 +1433,8 @@ else target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@)) endif +%.h.gch: %.h prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.s: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.i: %.c prepare scripts FORCE diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a525112..b9ec464 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -78,10 +78,16 @@ ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target)),) builtin-target := $(obj)/built-in.o endif +# Extract subdirs and header targets from header-y +subdir-ym += $(patsubst %,$(src)/%,$(patsubst %/,%,$(filter %/,$(header-y)))) +cheader-y += $(patsubst %.h,$(patsubst %/,%,$(obj))/%.h.gch,$(filter %.h,$(header-y))) +cheader-y += $(patsubst %.h,$(patsubst %/,%,$(obj))/%.h.gch,$(filter %.h,$(unifdef-y))) + # We keep a list of all modules in $(MODVERDIR) __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \ $(if $(KBUILD_MODULES),$(obj-m)) \ + $(cheader-y) \ $(subdir-ym) $(always) @: @@ -97,6 +103,18 @@ ifneq ($(KBUILD_CHECKSRC),0) endif +# Compile header files (.h) +# --------------------------------------------------------------------------- + +quiet_cmd_cc_h_gch_h = CC $(quiet_modtag) $@ + cmd_cc_h_gch_h = $(CC) $(c_flags) -o $@ $< + +$(obj)/%.h.gch: $(src)/%.h FORCE + $(call if_changed_dep,cc_h_gch_h) + +targets += $(cheader-y) + + # Compile C sources (.c) # --------------------------------------------------------------------------- -- 1.5.0.6 ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ kbuild-devel mailing list kbuild-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kbuild-devel