1
0

gyp_uv 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. return machine # Return as-is and hope for the best.
  23. def compiler_version():
  24. proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE)
  25. is_clang = 'clang' in proc.communicate()[0].split('\n')[0]
  26. proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE)
  27. version = proc.communicate()[0].split('.')
  28. version = map(int, version[:2])
  29. version = tuple(version)
  30. return (version, is_clang)
  31. def run_gyp(args):
  32. rc = gyp.main(args)
  33. if rc != 0:
  34. print 'Error running GYP'
  35. sys.exit(rc)
  36. if __name__ == '__main__':
  37. args = sys.argv[1:]
  38. # GYP bug.
  39. # On msvs it will crash if it gets an absolute path.
  40. # On Mac/make it will crash if it doesn't get an absolute path.
  41. if sys.platform == 'win32':
  42. args.append(os.path.join(uv_root, 'uv.gyp'))
  43. common_fn = os.path.join(uv_root, 'common.gypi')
  44. options_fn = os.path.join(uv_root, 'options.gypi')
  45. # we force vs 2010 over 2008 which would otherwise be the default for gyp
  46. if not os.environ.get('GYP_MSVS_VERSION'):
  47. os.environ['GYP_MSVS_VERSION'] = '2010'
  48. else:
  49. args.append(os.path.join(os.path.abspath(uv_root), 'uv.gyp'))
  50. common_fn = os.path.join(os.path.abspath(uv_root), 'common.gypi')
  51. options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')
  52. if os.path.exists(common_fn):
  53. args.extend(['-I', common_fn])
  54. if os.path.exists(options_fn):
  55. args.extend(['-I', options_fn])
  56. args.append('--depth=' + uv_root)
  57. # There's a bug with windows which doesn't allow this feature.
  58. if sys.platform != 'win32':
  59. if '-f' not in args:
  60. args.extend('-f make'.split())
  61. if 'ninja' not in args:
  62. args.extend(['-Goutput_dir=' + output_dir])
  63. args.extend(['--generator-output', output_dir])
  64. (major, minor), is_clang = compiler_version()
  65. args.append('-Dgcc_version=%d' % (10 * major + minor))
  66. args.append('-Dclang=%d' % int(is_clang))
  67. if not any(a.startswith('-Dhost_arch=') for a in args):
  68. args.append('-Dhost_arch=%s' % host_arch())
  69. if not any(a.startswith('-Dtarget_arch=') for a in args):
  70. args.append('-Dtarget_arch=%s' % host_arch())
  71. if not any(a.startswith('-Dlibrary=') for a in args):
  72. args.append('-Dlibrary=static_library')
  73. if not any(a.startswith('-Dcomponent=') for a in args):
  74. args.append('-Dcomponent=static_library')
  75. gyp_args = list(args)
  76. print gyp_args
  77. run_gyp(gyp_args)