kbuild: prepare headers_* for arch/$ARCH/include

Factor out the headers_*_all support to a seperate
shell script and add support for arch specific
header files can be located in either

    arch/$ARCH/include/asm
or
    include/asm-$ARCH/

In "make help" always display the headers_* targets.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
diff --git a/scripts/headers.sh b/scripts/headers.sh
new file mode 100755
index 0000000..d33426f
--- /dev/null
+++ b/scripts/headers.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# Run headers_$1 command for all suitable architectures
+
+# Stop on error
+set -e
+
+do_command()
+{
+	if [ -f ${srctree}/arch/$2/include/asm/Kbuild ]; then
+		make ARCH=$2 KBUILD_HEADERS=$1 headers_$1
+	elif [ -f ${srctree}/include/asm-$2/Kbuild ]; then
+		make ARCH=$2 KBUILD_HEADERS=$1 headers_$1
+	else
+		printf "Ignoring arch: %s\n" ${arch}
+	fi
+}
+
+# Do not try this architecture
+drop="generic um ppc sparc64 cris"
+
+archs=$(ls ${srctree}/arch)
+
+for arch in ${archs}; do
+	case ${arch} in
+	um)        # no userspace export
+		;;
+	ppc)       # headers exported by powerpc
+		;;
+	sparc64)   # headers exported by sparc
+		;;
+	cris)      # headers export are known broken
+		;;
+	*)
+		if [ -d ${srctree}/arch/${arch} ]; then
+			do_command $1 ${arch}
+		fi
+		;;
+	esac
+done
+
+