gyp_uv.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. import os
  3. import platform
  4. import sys
  5. CC = os.environ.get('CC', 'cc')
  6. script_dir = os.path.dirname(__file__)
  7. uv_root = os.path.normpath(script_dir)
  8. output_dir = os.path.join(os.path.abspath(uv_root), 'out')
  9. sys.path.insert(0, os.path.join(uv_root, 'build', 'gyp', 'pylib'))
  10. try:
  11. import gyp
  12. except ImportError:
  13. print('You need to install gyp in build/gyp first. See the README.')
  14. sys.exit(42)
  15. def host_arch():
  16. machine = platform.machine()
  17. if machine == 'i386': return 'ia32'
  18. if machine == 'x86_64': return 'x64'
  19. if machine.startswith('arm'): return 'arm'
  20. if machine.startswith('mips'): return 'mips'
  21. return machine # Return as-is and hope for the best.
  22. def run_gyp(args):
  23. rc = gyp.main(args)
  24. if rc != 0:
  25. print 'Error running GYP'
  26. sys.exit(rc)
  27. if __name__ == '__main__':
  28. args = sys.argv[1:]
  29. # GYP bug.
  30. # On msvs it will crash if it gets an absolute path.
  31. # On Mac/make it will crash if it doesn't get an absolute path.
  32. if sys.platform == 'win32':
  33. args.append(os.path.join(uv_root, 'uv.gyp'))
  34. common_fn = os.path.join(uv_root, 'common.gypi')
  35. options_fn = os.path.join(uv_root, 'options.gypi')
  36. # we force vs 2010 over 2008 which would otherwise be the default for gyp
  37. if not os.environ.get('GYP_MSVS_VERSION'):
  38. os.environ['GYP_MSVS_VERSION'] = '2010'
  39. else:
  40. args.append(os.path.join(os.path.abspath(uv_root), 'uv.gyp'))
  41. common_fn = os.path.join(os.path.abspath(uv_root), 'common.gypi')
  42. options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')
  43. if os.path.exists(common_fn):
  44. args.extend(['-I', common_fn])
  45. if os.path.exists(options_fn):
  46. args.extend(['-I', options_fn])
  47. args.append('--depth=' + uv_root)
  48. # There's a bug with windows which doesn't allow this feature.
  49. if sys.platform != 'win32':
  50. if '-f' not in args:
  51. args.extend('-f make'.split())
  52. if 'eclipse' not in args and 'ninja' not in args:
  53. args.extend(['-Goutput_dir=' + output_dir])
  54. args.extend(['--generator-output', output_dir])
  55. if not any(a.startswith('-Dhost_arch=') for a in args):
  56. args.append('-Dhost_arch=%s' % host_arch())
  57. if not any(a.startswith('-Dtarget_arch=') for a in args):
  58. args.append('-Dtarget_arch=%s' % host_arch())
  59. if not any(a.startswith('-Dlibrary=') for a in args):
  60. args.append('-Dlibrary=static_library')
  61. if not any(a.startswith('-Dcomponent=') for a in args):
  62. args.append('-Dcomponent=static_library')
  63. gyp_args = list(args)
  64. print gyp_args
  65. run_gyp(gyp_args)