summaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure113
1 files changed, 113 insertions, 0 deletions
diff --git a/configure b/configure
new file mode 100755
index 0000000000..0c6ddf70cb
--- /dev/null
+++ b/configure
@@ -0,0 +1,113 @@
+#!/usr/bin/env python
+import optparse
+import os
+import pprint
+import re
+import shlex
+import subprocess
+import sys
+
+root_dir = os.path.dirname(__file__)
+sys.path.insert(0, os.path.join(root_dir, 'deps', 'gyp', 'pylib'))
+import gyp
+
+# parse our options
+parser = optparse.OptionParser()
+
+parser.add_option("--debug",
+ action="store_true",
+ dest="debug",
+ help="Also build debug build")
+
+parser.add_option("--boost",
+ action="store",
+ dest="boost_root",
+ help="Path to boost (defaults to /usr/local)")
+
+parser.add_option("--glfw3",
+ action="store",
+ dest="glfw3",
+ help="Path to gflw3 (defaults to using pkg-config)")
+
+(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 configure_llmr(o):
+ if options.boost_root:
+ o['variables']['boost_root'] = options.boost_root
+ else:
+ o['variables']['boost_root'] = '/usr/local'
+ o['target_defaults']['default_configuration'] = 'Debug' if options.debug else 'Release'
+
+def configure_glfw3(o):
+ if options.glfw3:
+ o['variables']['glfw3_libraries'] = '-L'+os.path.join(options.glfw3,'lib')
+ o['variables']['glfw3_libraries'] += '-lglfw3'
+ o['variables']['glfw3_cflags'] += '-I'+os.path.join(options.glfw3,'lib')
+ else:
+ ret = pkg_config('glfw3')
+ if not ret:
+ sys.stderr.write('could not find glfw3 with pkg-config')
+ sys.exit(-1)
+ o['variables']['glfw3_libraries'] = ret[0].split()
+ o['variables']['glfw3_cflags'] = ret[1].split()
+
+def write(filename, data):
+ filename = os.path.join(root_dir, filename)
+ print "creating ", filename
+ f = open(filename, 'w+')
+ f.write(data)
+
+output = {
+ 'variables': { 'python': sys.executable },
+ 'target_defaults' : {
+ 'include_dirs': [],
+ 'libraries': [],
+ 'defines': [],
+ 'cflags': []
+ }
+}
+
+def run_gyp(args):
+ rc = gyp.main(args)
+ if rc != 0:
+ print 'Error running GYP'
+ sys.exit(rc)
+
+if __name__ == '__main__':
+ configure_llmr(output)
+ configure_glfw3(output)
+ pprint.pprint(output, indent=2)
+
+ write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
+ pprint.pformat(output, indent=2) + "\n")
+
+ config = {
+ 'BUILDTYPE': 'Debug' if options.debug else 'Release',
+ 'PYTHON': sys.executable,
+ }
+ config = '\n'.join(map('='.join, config.iteritems())) + '\n'
+
+ write('config.mk',
+ '# Do not edit. Generated by the configure script.\n' + config)
+
+ gyp_args = []
+ gyp_args.extend(['-f', 'make'])
+ gyp_args.append(os.path.join(os.path.abspath(root_dir), 'llmr.gyp'))
+ gyp_args.append('--depth=' + root_dir)
+ output_dir = os.path.join(os.path.abspath(root_dir), 'out')
+ gyp_args.extend(['--generator-output', output_dir])
+ gyp_args.extend(['-Goutput_dir=' + output_dir])
+ run_gyp(gyp_args)