Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 154 lines (118 sloc) 3.42 KB
#!/usr/bin/env python
"""
From <https://github.com/joyent/node/blob/master/configure-gyp>
"""
import optparse
import os
import json
import sys
import glob
import shutil
root_dir = os.path.dirname(__file__)
# parse our options
parser = optparse.OptionParser()
parser.add_option("--debug",
action="store_true",
dest="debug",
help="Build debug build")
parser.add_option("--prefix",
action="store",
dest="prefix",
help="Select the install prefix (defaults to /usr/local)")
(options, args) = parser.parse_args()
def pkg_config(pkg):
cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
libs = cmd.readline().strip()
ret = cmd.close()
if (ret): return None
cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
cflags = cmd.readline().strip()
ret = cmd.close()
if (ret): return None
return (libs, cflags)
def uname(switch):
f = os.popen('uname %s' % switch)
s = f.read().strip()
f.close()
return s
def host_arch():
"""Host architecture. One of arm, ia32 or x64."""
if sys.platform == "win32":
return 'ia32'
if sys.platform == "darwin":
return 'ia32'
arch = uname('-p')
if arch == 'unknown':
arch = uname('-m')
return {
'arm': 'arm',
'x86': 'ia32',
'i386': 'ia32',
'i486': 'ia32',
'i586': 'ia32',
'i686': 'ia32',
'x86_64': 'x64',
'amd64': 'x64',
}.get(arch, arch)
def target_arch():
# TODO act on options.dest_cpu
return host_arch()
def configure_virgo(o):
# TODO add gdb and dest_cpu
o['variables']['virgo_debug'] = 'true' if options.debug else 'false'
o['variables']['virgo_prefix'] = options.prefix if options.prefix else ''
o['variables']['host_arch'] = host_arch()
o['variables']['target_arch'] = target_arch()
print "configure options:", options
output = {
'variables': {},
'include_dirs': [],
'libraries': [],
'defines': [],
'cflags': [],
}
configure_virgo(output)
# variables should be a root level element,
# move everything else to target_defaults
variables = output['variables']
del output['variables']
output = {
'variables': variables,
'target_defaults': output
}
fn = os.path.join(root_dir, 'options.gypi')
print "creating ", fn
f = open(fn, 'w+')
f.write("# Do not edit. Generated by the configure script.\n")
json.dump(output, f, indent=2, skipkeys=True)
f.write("\n")
f.close()
if os.path.isdir(os.path.join('.', '.git')):
print "Updating git submodules...."
os.system(' '.join(['git', 'submodule', 'update', '--init', '--recursive']))
print "Generating build system with GYP..."
def render_openssl_symlinks(src, dest):
src = os.path.abspath(src)
dest = os.path.abspath(dest)
for x in glob.glob(os.path.join(src, '*.h')):
with open(x) as f:
d = f.read().strip()
srcf = os.path.abspath(os.path.join(src, d))
destf = os.path.join(dest, os.path.basename(srcf))
# use copy2, so we preserve mtimes, reducing rebuilds
shutil.copy2(srcf, destf)
if sys.platform == "win32":
os.environ['GYP_MSVS_VERSION'] = '2010'
render_openssl_symlinks('deps/luvit/deps/openssl/openssl/include/openssl',
'deps/luvit/deps/openssl/openssl-configs/realized/openssl')
os.system("python tools\gyp_virgo -f msvs -G msvs_version=2010")
else:
os.system("tools/gyp_virgo")
print ""
print "Done!"
print ""
if sys.platform == "win32":
print "Now run `python tools/build.py build` to build!"
else:
print "Now run `make` to build!"
print ""