[PATCH] kbuild: add headercheck

From: Sam Ravnborg
Date: Thu Apr 09 2009 - 15:56:03 EST


headercheck is used to check if all headerfiles include the
files that is needed for a headerfile to build.

It visits all directories listed in include/Kbuild using header-y.
And for each header file it creates a .c file that is then build.

Signed-off-by: Sam Ravnborg <sam@xxxxxxxxxxxx>
---
Makefile | 6 +++++
include/linux/Kbuild | 7 ++++++
scripts/Kbuild.headercheck | 46 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
create mode 100644 scripts/Kbuild.headercheck

diff --git a/Makefile b/Makefile
index e5ad5fd..39ed688 100644
--- a/Makefile
+++ b/Makefile
@@ -837,6 +837,9 @@ vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o)
ifdef CONFIG_HEADERS_CHECK
$(Q)$(MAKE) -f $(srctree)/Makefile headers_check
endif
+ifndef CONFIG_INCLUDE_HEADER_CHECK
+ $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.headercheck obj=include
+endif
ifdef CONFIG_SAMPLES
$(Q)$(MAKE) $(build)=samples
endif
@@ -1463,6 +1466,9 @@ namespacecheck:
export_report:
$(PERL) $(srctree)/scripts/export_report.pl

+headercheck:
+ $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.headercheck obj=include
+
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)

diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index ca9b9b9..49b61ff 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -375,3 +375,10 @@ unifdef-y += xfrm.h
objhdr-y += version.h
header-y += wimax.h
header-y += wimax/
+
+# header files that cannot be build alone
+# (not checked by make headercheck)
+ignore-y += compiler-intel.h
+ignore-y += compiler-gcc.h
+ignore-y += compiler-gcc3.h
+ignore-y += compiler-gcc4.h
diff --git a/scripts/Kbuild.headercheck b/scripts/Kbuild.headercheck
new file mode 100644
index 0000000..9701341
--- /dev/null
+++ b/scripts/Kbuild.headercheck
@@ -0,0 +1,46 @@
+# ==========================================================================
+# Check that the header files include all files needed for them to build
+# without errors
+#
+# The Kbuild files used for specifying exported header files are used
+# to tell what headerfile to check.
+#
+# header-y - used to tell what directories to visit
+# ignore-y - list files we should not check
+#
+# ==========================================================================
+
+.PHONY: __headercheck
+__headercheck:
+
+include scripts/Kbuild.include
+
+kbuild-file := $(srctree)/$(obj)/Kbuild
+include $(kbuild-file)
+
+include $(srctree)/scripts/Makefile.lib
+
+headers := $(wildcard $(srctree)/$(obj)/*.h)
+ignores := $(addprefix $(srctree)/$(obj)/,$(ignore-y))
+headers := $(filter-out $(ignores), $(headers))
+headers := $(sort $(headers))
+
+subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
+
+o_files := $(addsuffix .o, $(headers))
+
+__headercheck: $(subdirs) $(o_files)
+ echo $^
+
+
+include_name = $(subst $(srctree)/include/,,$<)
+
+$(o_files): %.h.o : %.h
+ $(Q)echo "#include <$(include_name)>" > $(@:.o=.c)
+ $(Q)$(CC) $(c_flags) -c -o $@ $<
+
+
+.PHONY: $(subdirs)
+$(subdirs):
+ $(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.headercheck obj=$(obj)/$@
+
--
1.6.0.2.GIT



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/