Clean up IRT munge process.

Move irt_syscalls.py to tools dir.
Add NeedsUpdate check for irt.h files to prevent rebuild.
diff --git a/build.py b/build.py
index f11fee2..d295908 100755
--- a/build.py
+++ b/build.py
@@ -33,7 +33,7 @@
 
   if options.no_cache:
     tc_args += ['--no-use-cached-results', '--no-use-remote-cache']
-  
+
   print 'Building PNaCl: ' + ' '.join(tc_args)
   process.Run(tc_args, cwd=TOOLCHAIN_BUILD_DIR, outfile=sys.stdout)
 
@@ -49,19 +49,8 @@
               cwd=NATIVE_CLIENT_DIR, outfile=sys.stdout)
 
 
-def UpdateToolchain():
-  copy_srcs = [
-    'bin', 'docs', 'lib', 'include', 'share',
-    'FEATURE_VERSION', 'REV', 'README'
-  ]
-
-  for name in copy_srcs:
-    src = os.path.join(OUTPUT_ROOT, 'bionic_work', name)
-    dst = os.path.join(OUTPUT_ROOT, 'bionic_install', name)
-    UpdateFromTo(src, dst)
-
-
 def UpdateBionicToolchain():
+  print 'Updating Bionic Toolchain.'
   COPY_FULL = [
     'arm_bc-nacl', 'bin', 'docs',
     'i686_bc-nacl', 'include', 'le32-nacl',
@@ -81,7 +70,7 @@
     'lib/clang/3.4/lib/le32-nacl',
     'lib/clang/3.4/lib/x86_64-nacl',
   ]
-  
+
   srcpath = os.path.join(OUTPUT_ROOT, 'bionic_work')
   dstpath = os.path.join(OUTPUT_ROOT, 'bionic_install')
   for dirpath in COPY_FULL:
@@ -110,6 +99,11 @@
     'off_t': 'int64_t',
     'native_client/src/untrusted/irt/' : '',
   }
+
+  if not NeedsUpdate(src,dst):
+    return
+
+  print 'Munging IRT %s -> %s.' % (src,dst)
   with open(src, 'r') as srcf:
     text = srcf.read()
     text = ReplaceText(text, [replace_map])
@@ -209,6 +203,8 @@
   for arch in ARCH_TYPES:
     ConfigureProject(arch, 'libc')
 
+  for arch in ARCH_TYPES:
+    MakeProject(arch, 'libc', ['irt'])
 
 
 if __name__ == '__main__':
diff --git a/tools/file_update.py b/tools/file_update.py
index 063e87f..be4445a 100644
--- a/tools/file_update.py
+++ b/tools/file_update.py
@@ -67,7 +67,7 @@
   return True
 
 
-def UpdateFile(srcpath, dstpath, verbose=False):
+def UpdateFile(srcpath, dstpath, verbose=True):
   if verbose:
     print '%s -> %s\n' % (dstpath, srcpath)
   shutil.copy(srcpath, dstpath)
diff --git a/v2/libc/arch-nacl/syscalls/irt_syscalls.py b/tools/irt_syscalls.py
similarity index 95%
rename from v2/libc/arch-nacl/syscalls/irt_syscalls.py
rename to tools/irt_syscalls.py
index 019086d..6aad7ec 100644
--- a/v2/libc/arch-nacl/syscalls/irt_syscalls.py
+++ b/tools/irt_syscalls.py
@@ -9,7 +9,7 @@
 import StringIO
 import sys
 
-SCRIPT_PATH = os.path.dirname(__file__)
+from bionic_dirs import *
 
 NOTICE ="""/*
  * Copyright (C) 2008 The Android Open Source Project
@@ -252,6 +252,19 @@
   return None
 
 
+def ReplaceText(src, dst):
+  print 'Munging IRT %s -> %s.' % (src,dst)
+  replace_map = {
+    'off_t': 'int64_t',
+    'native_client/src/untrusted/irt/' : '',
+  }
+  with open(src, 'r') as srcf:
+    text = srcf.read()
+    text = ReplaceText(text, [replace_map])
+    with open(dst, 'w') as dstf:
+      dstf.write(text)
+
+
 def GetGroupName(name):
   parts = name.split('_')
   start = 0
@@ -381,22 +394,19 @@
       help='Produce more output.')
   parser.add_option(
       '-i', '--include', dest='include',
-      default=os.path.join(SCRIPT_PATH, 'irt_syscalls.h'),
+      default=os.path.join(BIONIC_SRC, 'libc', 'irt_syscalls.h'),
       help='Output include filename.')
   parser.add_option(
       '-s', '--source', dest='source',
-      default=os.path.join(SCRIPT_PATH, 'irt_syscalls.c'),
+      default=os.path.join(BIONIC_SRC, 'libc', 'irt_syscalls.c'),
       help='Output source filename.')
 
   options, args = parser.parse_args(argv[1:])
   groups = {}
   if not args:
-    NACL_PATH = os.path.join(SCRIPT_PATH, '../../../../../..')
     args = [
       'irt.h',
       'irt_dev.h',
-#      os.path.join(NACL_PATH, 'src/untrusted/irt/irt.h'),
-#      os.path.join(NACL_PATH, 'src/untrusted/irt/irt_dev.h'),
     ]
 
 
diff --git a/tools/make_tools.py b/tools/make_tools.py
index ab90121..2bf9f62 100644
--- a/tools/make_tools.py
+++ b/tools/make_tools.py
@@ -7,14 +7,14 @@
 """
 
 import process
+import sys
+
 from bionic_dirs import *
 from file_update import Mkdir, Rmdir, Symlink, UpdateText
 from replace import ReplaceArch, ReplaceText
 
 
 def GetProjectPaths(out_dir, arch, project):
-  print "BIONIC_SRC=" + BIONIC_SRC
-  print "PROJECT=" + str(project)
   srcpath = os.path.join(BIONIC_SRC, project)
   workpath = os.path.join(out_dir, 'bionic_$GCC_work')
   toolpath = os.path.join(out_dir, 'bionic_install')
@@ -87,27 +87,25 @@
 
   Mkdir(paths['work'])
   Mkdir(paths['ins'])
-  print "Working at " + paths['work']
   UpdateText(os.path.join(paths['work'], 'Makefile'), text)
 
 
-def MakeProject(project, targets=None, clobber=False):
-  for arch in ARCH_TYPES:
-    paths = GetProjectPaths(OUTPUT_DIR, arch, project)
-    workpath = paths['work']
-    targets = targets or []
-    targetlist = ' '.join(targets)
-    print 'Building %s for %s at %s %s.' % (project, arch, workpath, targetlist)
-    if clobber:
-      args = ['make', '-j12', 'V=1', 'clean']
-      if process.Run(args, cwd=workpath, outfile=sys.stdout):
-        raise RuntimeError('Failed to clean %s for %s.\n' % (project, arch))
-
-    args = ['make', '-j12', 'V=1'] + targets
+def MakeProject(arch, project, targets=None, clobber=False):
+  paths = GetProjectPaths(OUTPUT_ROOT, arch, project)
+  workpath = paths['work']
+  targets = targets or []
+  targetlist = ' '.join(targets)
+  print 'Building %s for %s at %s %s.' % (project, arch, workpath, targetlist)
+  if clobber:
+    args = ['make', '-j12', 'V=1', 'clean']
     if process.Run(args, cwd=workpath, outfile=sys.stdout):
-      print "Building at: " + workpath
-      args = ['make', '-j1', 'V=1'] + targets
-      process.Run(args, cwd=workpath, outfile=sys.stdout)
-      raise RuntimeError('Failed to build %s for %s.\n' % (project, arch))
-    print 'Done with %s for %s.\n' % (project, arch)
+      raise RuntimeError('Failed to clean %s for %s.\n' % (project, arch))
+
+  args = ['make', '-j12', 'V=1'] + targets
+  if process.Run(args, cwd=workpath, outfile=sys.stdout):
+    print "Building at: " + workpath
+    args = ['make', '-j1', 'V=1'] + targets
+    process.Run(args, cwd=workpath, outfile=sys.stdout)
+    raise RuntimeError('Failed to build %s for %s.\n' % (project, arch))
+  print 'Done with %s for %s.\n' % (project, arch)
 
diff --git a/tools/process.py b/tools/process.py
index 6162c41..a972db0 100644
--- a/tools/process.py
+++ b/tools/process.py
@@ -16,7 +16,6 @@
 
 class Process(object):
   def __init__(self, args, cwd=None, shell=False, env=None, pipe=True):
-    print 'IN CWD=%s' % str(cwd)
     self.args = args
     self.cwd = cwd or os.getcwd()
     self.shell = shell
diff --git a/v2/libc/Makefile b/v2/libc/Makefile
index c943a81..3aff866 100644
--- a/v2/libc/Makefile
+++ b/v2/libc/Makefile
@@ -484,11 +484,12 @@
 all: compile lib
 
 .PHONY : irt
+IRT_PY := $(SRC_ROOT)/../../tools/irt_syscalls.py
+
 IRT_H := $(INS_ROOT)/../include/irt.h
 IRT_DEV_H := $(INS_ROOT)/../include/irt_dev.h
 IRT_SOCKET_H := $(SRC_ROOT)/arch-nacl/syscalls/irt_socket.h
 IRT_POLL_H := $(SRC_ROOT)/arch-nacl/syscalls/irt_poll.h
-IRT_PY := $(SRC_ROOT)/arch-nacl/syscalls/irt_syscalls.py
 IRT_SYSCALLS_C := $(SRC_ROOT)/arch-nacl/syscalls/irt_syscalls.c
 IRT_SYSCALLS_H := $(INS_ROOT)/../include/irt_syscalls.h
 
@@ -499,6 +500,12 @@
 $(IRT_SYSCALLS_C) $(IRT_SYSCALLS_H) : $(IRT_PY) $(IRT_H) $(IRT_DEV_H) $(IRT_SOCKET_H) $(IRT_POLL_H)
 	python $(IRT_PY) -i $(IRT_SYSCALLS_H) $(IRT_H) $(IRT_DEV_H) $(IRT_SOCKET_H) $(IRT_POLL_H)
 
+$(eval $(call BASIC_COMPILE_TARGET,irt_munge_test.o,$(SRC_ROOT)/irt_munge_test.c,$(CC),-nostdlib -nostdinc))
+	
+irt_munge_test:
+	$(RUN_SEL_LDR) 
+	
+	
 # Fake libdl.so to provide a way to share the IRT pointers
 DL_SOURCE:=arch-nacl/bionic/irt_ptrs.c
 DL_OBJECT:=$(subst .c,.o,$(DL_SOURCE))