gyp_uv.py 3.0 KB

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