 +      # the rule namespace is global, but it really should be scoped to the
 +      # subninja.
 +      name = self.name + '.' + action['action_name'].replace(' ', '_')
-+      command = gyp.common.EncodePOSIXShellList(action['action'])
++      args = action['action']
++      command = ''
 +      if self.base_dir:
-+        command = 'cd %s; %s' % (self.base_dir, command)
-+      if 'description' in action:
-+        description = action['message']
++        # The command expects to be run from the current directory.
++        # cd into the directory before running, and adjust all the
++        # paths to point to the proper locations.
++        command = 'cd %s; ' % self.base_dir
++        cdup = '../' * len(self.base_dir.split('/'))
++        args = [arg.replace('$b', cdup + '$b') for arg in args]
++
++      command += gyp.common.EncodePOSIXShellList(args)
++
++      if 'message' in action:
++        description = 'ACTION ' + action['message']
 +      else:
-+        description = '%s: %s' % (self.name, action['action_name'])
++        description = 'ACTION %s: %s' % (self.name, action['action_name'])
 +      self.WriteRule(name=name, command=command, description=description)
 +
 +      inputs = [self.InputPath(i) for i in action['inputs']]

Index: pylib/gyp/generator/ninja.py
===================================================================
--- pylib/gyp/generator/ninja.py	(revision 0)
+++ pylib/gyp/generator/ninja.py	(revision 0)
@@ -0,0 +1,505 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 Google Inc. All rights reserved.

+
+rule alink
+  description = AR $out
+  command = rm -f $out && ar rcsT $out $in
+
+rule solink
+  description = SOLINK $out
