diff options
Diffstat (limited to 'configure.py')
-rwxr-xr-x | configure.py | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/configure.py b/configure.py index 4c49f40..2e044c1 100755 --- a/configure.py +++ b/configure.py @@ -32,13 +32,16 @@ profilers = ['gmon', 'pprof'] parser.add_option('--platform', help='target platform (' + '/'.join(platforms) + ')', choices=platforms) +parser.add_option('--host', + help='host platform (' + '/'.join(platforms) + ')', + choices=platforms) parser.add_option('--debug', action='store_true', help='enable debugging flags',) parser.add_option('--profile', metavar='TYPE', choices=profilers, help='enable profiling (' + '/'.join(profilers) + ')',) parser.add_option('--with-gtest', metavar='PATH', - help='use gtest built in directory PATH') + help='use gtest unpacked in directory PATH') parser.add_option('--with-python', metavar='EXE', help='use EXE as the Python interpreter', default=os.path.basename(sys.executable)) @@ -53,6 +56,7 @@ if platform is None: platform = 'freebsd' elif platform.startswith('mingw') or platform.startswith('win'): platform = 'mingw' +host = options.host or platform BUILD_FILENAME = 'build.ninja' buildfile = open(BUILD_FILENAME, 'w') @@ -73,6 +77,10 @@ def doc(filename): return os.path.join('doc', filename) def cxx(name, **kwargs): return n.build(built(name + '.o'), 'cxx', src(name + '.cc'), **kwargs) +def binary(name): + if platform == 'mingw': + return name + '.exe' + return name n.variable('builddir', 'build') n.variable('cxx', os.environ.get('CXX', 'g++')) @@ -91,9 +99,7 @@ libs = [] if platform == 'mingw': cflags.remove('-fvisibility=hidden'); - cflags.append('-Igtest-1.6.0/include') - ldflags.append('-Lgtest-1.6.0/lib/.libs') - ldflags.extend(['-static']) + ldflags.append('-static') else: if options.profile == 'gmon': cflags.append('-pg') @@ -115,7 +121,7 @@ n.rule('cxx', description='CXX $out') n.newline() -if platform != 'mingw': +if host != 'mingw': n.rule('ar', command='rm -f $out && $ar crs $out $in', description='AR $out') @@ -147,16 +153,25 @@ if platform != 'mingw': n.comment('the depfile parser is generated using re2c.') n.rule('re2c', - command='re2c -b --no-generation-date -o $out $in', + command='re2c -b -i --no-generation-date -o $out $in', description='RE2C $out') # Generate the .cc file in the source directory so we can check it in. n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc')) n.newline() n.comment('Core source files all build into ninja library.') -for name in ['build', 'build_log', 'clean', 'edit_distance', 'eval_env', - 'graph', 'graphviz', 'parsers', 'util', 'depfile_parser', - 'disk_interface', 'state']: +for name in ['build', + 'build_log', + 'clean', + 'depfile_parser', + 'disk_interface', + 'edit_distance', + 'eval_env', + 'graph', + 'graphviz', + 'parsers', + 'state', + 'util']: objs += cxx(name) if platform == 'mingw': objs += cxx('subprocess-win32') @@ -169,11 +184,8 @@ libs.append('-lninja') n.comment('Main executable is library plus main() function.') objs = cxx('ninja') -binary = 'ninja' -if platform == 'mingw': - binary = 'ninja.exe' -n.build(binary, 'link', objs, implicit=ninja_lib, - variables=[('libs', libs)]) +ninja = n.build(binary('ninja'), 'link', objs, implicit=ninja_lib, + variables=[('libs', libs)]) n.newline() n.comment('Tests all build into ninja_test executable.') @@ -181,18 +193,27 @@ n.comment('Tests all build into ninja_test executable.') variables = [] test_cflags = None test_ldflags = None +test_libs = libs +objs = [] if options.with_gtest: path = options.with_gtest + + gtest_all_incs = '-I%s -I%s' % (path, os.path.join(path, 'include')) + objs += n.build(built('gtest-all.o'), 'cxx', + os.path.join(path, 'src/gtest-all.cc'), + variables=[('cflags', gtest_all_incs)]) + objs += n.build(built('gtest_main.o'), 'cxx', + os.path.join(path, 'src/gtest_main.cc'), + variables=[('cflags', gtest_all_incs)]) + test_cflags = cflags + ['-I%s' % os.path.join(path, 'include')] - test_libs = libs + [os.path.join(path, 'lib/.libs/lib%s.a' % lib) - for lib in ['gtest_main', 'gtest']] else: - test_libs = libs + ['-lgtest_main', '-lgtest'] + test_libs.extend(['-lgtest_main', '-lgtest']) -objs = [] for name in ['build_log_test', 'build_test', 'clean_test', + 'depfile_parser_test', 'disk_interface_test', 'edit_distance_test', 'eval_env_test', @@ -206,14 +227,14 @@ for name in ['build_log_test', if platform != 'mingw': test_libs.append('-lpthread') -n.build('ninja_test', 'link', objs, implicit=ninja_lib, +n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib, variables=[('ldflags', test_ldflags), ('libs', test_libs)]) n.newline() n.comment('Perftest executable.') objs = cxx('parser_perftest') -n.build('parser_perftest', 'link', objs, implicit=ninja_lib, +n.build(binary('parser_perftest'), 'link', objs, implicit=ninja_lib, variables=[('libs', '-L$builddir -lninja')]) n.newline() @@ -251,7 +272,7 @@ n.build('doxygen', 'doxygen', doc('doxygen.config'), implicit=mainpage) n.newline() -if platform != 'mingw': +if host != 'mingw': n.comment('Regenerate build files if build script changes.') n.rule('configure', command=options.with_python + ' configure.py $configure_args', @@ -261,6 +282,6 @@ if platform != 'mingw': n.newline() n.comment('Build only the main binary by default.') -n.default(binary) +n.default(ninja) print 'wrote %s.' % BUILD_FILENAME |