Don't #define SYS_ constants unless they make sense for the current architecture.

Fixes the MIPS and x86 builds. strace tests whether syscalls
are supported using #ifdef of the appropriate SYS_ constant.

Change-Id: I90be118dc42abfdaf5b0f9b1e676e8601f55106e
diff --git a/libc/tools/gensyscalls.py b/libc/tools/gensyscalls.py
index 389177e..aaa3de3 100755
--- a/libc/tools/gensyscalls.py
+++ b/libc/tools/gensyscalls.py
@@ -303,27 +303,18 @@
                 t["asm-mips"] = self.mips_genstub(syscall_func,"__NR_"+syscall_name)
 
 
-    def gen_NR_syscall(self, fp, name, id):
-        fp.write("#define __NR_%-25s    (__NR_SYSCALL_BASE + %d)\n" % (name,id))
-
-
-    def gen_glibc_syscalls_h(self):
-        glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
-        all_syscall_names = set()
-        for sc in self.syscalls:
-            all_syscall_names.add(sc["name"])
-        fp = create_file(glibc_syscalls_h_path)
-        fp.write("/* Auto-generated by gensyscalls.py; do not edit. */\n")
-        fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
-        fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
-        for syscall_name in sorted(all_syscall_names):
-            fp.write("#define SYS_%-25s __NR_%s\n" % (syscall_name, syscall_name))
-        fp.write("#endif\n")
-        fp.close()
-        self.other_files.append(glibc_syscalls_h_path)
+    def gen_NR_syscall(self, glibc_fp, linux_fp, name, id):
+        linux_fp.write("#define __NR_%-25s    (__NR_SYSCALL_BASE + %d)\n" % (name,id))
+        glibc_fp.write("#define SYS_%-25s __NR_%s\n" % (name, name))
 
 
     def gen_linux_syscalls_h(self):
+        glibc_syscalls_h_path = "include/sys/glibc-syscalls.h"
+        glibc_fp = create_file(glibc_syscalls_h_path)
+        glibc_fp.write("/* Auto-generated by gensyscalls.py; do not edit. */\n")
+        glibc_fp.write("#ifndef _BIONIC_GLIBC_SYSCALLS_H_\n")
+        glibc_fp.write("#define _BIONIC_GLIBC_SYSCALLS_H_\n")
+
         linux_syscalls_h_path = "include/sys/linux-syscalls.h"
         D("generating " + linux_syscalls_h_path)
         fp = create_file(linux_syscalls_h_path)
@@ -344,39 +335,50 @@
             sc_id  = sc["common"]
             sc_name = sc["name"]
             if sc_id >= 0:
-                self.gen_NR_syscall(fp, sc_name, sc_id)
+                self.gen_NR_syscall(glibc_fp, fp, sc_name, sc_id)
 
         # now, all arm-specific syscalls
-        fp.write( "\n#ifdef __arm__\n" );
+        fp.write("\n#ifdef __arm__\n")
+        glibc_fp.write( "\n#ifdef __arm__\n")
         for sc in self.syscalls:
             sc_id  = sc["armid"]
             sc_name = sc["name"]
             if sc_id >= 0:
-                self.gen_NR_syscall(fp, sc_name, sc_id)
-        fp.write( "#endif\n" );
+                self.gen_NR_syscall(glibc_fp, fp, sc_name, sc_id)
+        fp.write("#endif\n")
+        glibc_fp.write("#endif\n")
 
         gen_syscalls = {}
-        # finally, all i386-specific syscalls
-        fp.write( "\n#ifdef __i386__\n" );
+        # all i386-specific syscalls
+        fp.write("\n#ifdef __i386__\n")
+        glibc_fp.write("\n#ifdef __i386__\n")
         for sc in sorted(self.syscalls,key=lambda x:x["x86id"]):
             sc_id  = sc["x86id"]
             sc_name = sc["name"]
             if sc_id >= 0 and sc_name not in gen_syscalls:
-                self.gen_NR_syscall(fp, sc_name, sc_id)
+                self.gen_NR_syscall(glibc_fp, fp, sc_name, sc_id)
                 gen_syscalls[sc_name] = True
-        fp.write( "#endif\n" );
+        fp.write("#endif\n")
+        glibc_fp.write("#endif\n")
 
         # all mips-specific syscalls
-        fp.write( "\n#ifdef __mips__\n" );
+        fp.write("\n#ifdef __mips__\n")
+        glibc_fp.write("\n#ifdef __mips__\n")
         for sc in sorted(self.syscalls,key=lambda x:x["mipsid"]):
             sc_id = sc["mipsid"]
             if sc_id >= 0:
-                self.gen_NR_syscall(fp, sc["name"], sc_id)
+                self.gen_NR_syscall(glibc_fp, fp, sc["name"], sc_id)
         fp.write( "#endif\n" );
+        glibc_fp.write( "#endif\n" );
 
         fp.write( "\n#endif\n" )
         fp.write( "\n#endif /* _BIONIC_LINUX_SYSCALLS_H_ */\n" );
         fp.close()
+
+        glibc_fp.write("#endif\n")
+        glibc_fp.close()
+
+        self.other_files.append(glibc_syscalls_h_path)
         self.other_files.append(linux_syscalls_h_path)
 
 
@@ -448,7 +450,6 @@
 
         D( "re-generating stubs and support files" )
 
-        self.gen_glibc_syscalls_h()
         self.gen_linux_syscalls_h()
         for arch in all_archs:
             self.gen_arch_syscalls_mk(arch)