libc: Update auto-gen scripts

Make the scripts use external/kernel-headers/original by default.

clean_header.py:  Document -k<path>, add -d<path>
find_headers.py:  Make kernel config files optional
update_all.py:    Allow setting the path to kernel headers on the command-line
update_all.py:    Better formatting of output on ttys
update_all.py:    Automatically perform "git add/rm" on affected files.
SYSCALLS.TXT:     Fix typo in __socketcall definition.
checksyscalls.py: Add support for superH architecture in the checks.
gensyscalls.py:   Automatically perform "git add/rm" on affected files.
cpp.py:           Fixed a bug that prevented certain type definitions to
                  be kept in the generated clean header (e.g.
                  struct ethtool_drvinfo in <linux/ethtool.h>)

All scripts will use the content of external/kernel-headers/original by default now.

The generated code removes all empty lines and trailing whitespace. This is useful
to ensure a unified output even if we change the parser again in the future.

The top-level disclaimer has been edited with update instructions to regenerate
the headers when needed.

Also, a warning is now inserted every 8th line in the final output:

/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */

Changes under kernel/arch-arm and kernel/arch-x86 should correspond to whitespace
differences and additionnal struct definitions that were missed by the previous
parser implementation.

Change-Id: Icd1c056bacd766759f3e9b7bb5d63a246f3d656a

WARNING: If you run these script, do not submit the result to gerrit for now.
         It seems there are discrepancies between the content of original headers
         and those currently commited under bionic/libc/kernel/.

         (This problem is the main motivation to insert the warning repeatedly).

         Current list of issues:

           - Missing SuperH headers (i.e. external/kernel-headers/original/asm-sh)
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index dad9120..94b19ce 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -7,12 +7,12 @@
 
 noUpdate = 1
 
-def  cleanupFile( path ):
+def  cleanupFile( path, original_path=kernel_original_path ):
     """reads an original header and perform the cleanup operation on it
        this functions returns the destination path and the clean header
        as a single string"""
     # check the header path
-    src_path    = path
+    src_path = path
 
     if not os.path.exists(src_path):
         if noUpdate:
@@ -26,7 +26,6 @@
         sys.stderr.write( "warning: not a file: %s\n" % path )
         return None, None
 
-    original_path = kernel_original_path
     if os.path.commonprefix( [ src_path, original_path ] ) != original_path:
         if noUpdate:
             panic( "file is not in 'original' directory: %s\n" % path );
@@ -54,27 +53,27 @@
     else:
         dst_path = "common/" + src_path
 
-    dst_path = os.path.normpath( original_path + "/../" + dst_path )
+    dst_path = os.path.normpath( kernel_cleaned_path + "/" + dst_path )
 
     # now, let's parse the file
     #
-    list = cpp.BlockParser().parseFile(path)
-    if not list:
+    blocks = cpp.BlockParser().parseFile(path)
+    if not blocks:
         sys.stderr.write( "error: can't parse '%s'" % path )
         sys.exit(1)
 
 
-    list.optimizeMacros( kernel_known_macros )
-    list.optimizeIf01()
-    list.removeVarsAndFuncs( statics )
-    list.removeComments()
-    list.removeEmptyLines()
-    list.removeMacroDefines( kernel_ignored_macros )
-    list.insertDisclaimer( kernel.kernel_disclaimer )
-    list.replaceTokens( kernel_token_replacements )
+    blocks.optimizeMacros( kernel_known_macros )
+    blocks.optimizeIf01()
+    blocks.removeVarsAndFuncs( statics )
+    blocks.replaceTokens( kernel_token_replacements )
+    blocks.removeComments()
+    blocks.removeMacroDefines( kernel_ignored_macros )
+    blocks.removeWhiteSpace()
 
     out = StringOutput()
-    list.write(out)
+    out.write( kernel_disclaimer )
+    blocks.writeWithWarning(out, kernel_warning, 4)
     return dst_path, out.get()
 
 
@@ -92,12 +91,15 @@
                 if the content has changed. with this, you can pass more
                 than one file on the command-line
 
+            -k<path>  specify path of original kernel headers
+            -d<path>  specify path of cleaned kernel headers
+
         <header_path> must be in a subdirectory of 'original'
     """ % os.path.basename(sys.argv[0])
         sys.exit(1)
 
     try:
-        optlist, args = getopt.getopt( sys.argv[1:], 'uvk:' )
+        optlist, args = getopt.getopt( sys.argv[1:], 'uvk:d:' )
     except:
         # unrecognized option
         sys.stderr.write( "error: unrecognized option\n" )
@@ -111,6 +113,8 @@
             D_setlevel(1)
         elif opt == '-k':
             kernel_original_path = arg
+        elif opt == '-d':
+            kernel_cleaned_path = arg
 
     if len(args) == 0:
         usage()
@@ -143,9 +147,6 @@
         print "cleaning: %-*s -> %-*s (%s)" % ( 35, path, 35, dst_path, r )
 
 
-    if os.environ.has_key("ANDROID_PRODUCT_OUT"):
-        b.updateP4Files()
-    else:
-        b.updateFiles()
+    b.updateGitFiles()
 
     sys.exit(0)