Basic implementation of 'make headers_check'

Based on the 'headers_install' target, this performs a basic sanity check
on the exported headers -- so far only checking that they do not include
any other headers which aren't selected for import, but easily extendable.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst
index 688f8cb..aa9990a 100644
--- a/scripts/Makefile.headersinst
+++ b/scripts/Makefile.headersinst
@@ -78,6 +78,11 @@
       cmd_unifdef	  = $(UNIFDEF) $(srctree)/$(obj)/$@ | $(HDRSED)	\
                             > $(INSTALL_HDR_PATH)/$(_dst)/$@ || :
 
+quiet_cmd_check		  = CHECK   $(_dst)/$@
+      cmd_check		  = $(srctree)/scripts/hdrcheck.sh		\
+                              $(INSTALL_HDR_PATH)/include		\
+			      $(INSTALL_HDR_PATH)/$(_dst)/$@
+
 quiet_cmd_mkdir		  = MKDIR   $@
       cmd_mkdir		  = mkdir -p $(INSTALL_HDR_PATH)/$@
 
@@ -112,6 +117,11 @@
 
 .PHONY: $(header-y) $(unifdef-y) $(subdir-y)
 
+ifdef HDRCHECK
+# Rules for checking headers
+$(objhdr-y) $(header-y) $(unifdef-y):
+	$(call cmd,check)
+else
 # Rules for installing headers
 
 $(objhdr-y) $(subdir-y) $(header-y) $(unifdef-y): $(_dst)
@@ -134,6 +144,7 @@
 $(unifdef-y):
 	$(call cmd,unifdef)
 endif
+endif
 
 hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
 
diff --git a/scripts/hdrcheck.sh b/scripts/hdrcheck.sh
new file mode 100755
index 0000000..b3bb683
--- /dev/null
+++ b/scripts/hdrcheck.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+for FILE in `grep '^#include <' $2 | cut -f2 -d\< | cut -f1 -d\> | egrep ^linux\|^asm` ; do
+    if [ ! -r $1/$FILE ]; then
+	echo $2 requires $FILE, which does not exist
+	exit 1
+    fi
+done