summaryrefslogtreecommitdiffstats
path: root/configure.py
diff options
context:
space:
mode:
Diffstat (limited to 'configure.py')
-rwxr-xr-xconfigure.py104
1 files changed, 46 insertions, 58 deletions
diff --git a/configure.py b/configure.py
index 10c6994..1284deb 100755
--- a/configure.py
+++ b/configure.py
@@ -24,19 +24,19 @@ from __future__ import print_function
from optparse import OptionParser
import os
import sys
+import platform_helper
sys.path.insert(0, 'misc')
import ninja_syntax
parser = OptionParser()
-platforms = ['linux', 'freebsd', 'solaris', 'mingw', 'windows']
profilers = ['gmon', 'pprof']
parser.add_option('--platform',
- help='target platform (' + '/'.join(platforms) + ')',
- choices=platforms)
+ help='target platform (' + '/'.join(platform_helper.platforms()) + ')',
+ choices=platform_helper.platforms())
parser.add_option('--host',
- help='host platform (' + '/'.join(platforms) + ')',
- choices=platforms)
+ help='host platform (' + '/'.join(platform_helper.platforms()) + ')',
+ choices=platform_helper.platforms())
parser.add_option('--debug', action='store_true',
help='enable debugging extras',)
parser.add_option('--profile', metavar='TYPE',
@@ -47,28 +47,16 @@ parser.add_option('--with-gtest', metavar='PATH',
parser.add_option('--with-python', metavar='EXE',
help='use EXE as the Python interpreter',
default=os.path.basename(sys.executable))
-parser.add_option('--with-ninja', metavar='NAME',
- help="name for ninja binary for -t msvc (MSVC only)",
- default="ninja")
(options, args) = parser.parse_args()
if args:
print('ERROR: extra unparsed command-line arguments:', args)
sys.exit(1)
-platform = options.platform
-if platform is None:
- platform = sys.platform
- if platform.startswith('linux'):
- platform = 'linux'
- elif platform.startswith('freebsd'):
- platform = 'freebsd'
- elif platform.startswith('solaris'):
- platform = 'solaris'
- elif platform.startswith('mingw'):
- platform = 'mingw'
- elif platform.startswith('win'):
- platform = 'windows'
-host = options.host or platform
+platform = platform_helper.Platform(options.platform)
+if options.host:
+ host = platform_helper.Platform(options.host)
+else:
+ host = platform
BUILD_FILENAME = 'build.ninja'
buildfile = open(BUILD_FILENAME, 'w')
@@ -88,7 +76,7 @@ n.newline()
CXX = configure_env.get('CXX', 'g++')
objext = '.o'
-if platform == 'windows':
+if platform.is_msvc():
CXX = 'cl'
objext = '.obj'
@@ -103,7 +91,7 @@ def cc(name, **kwargs):
def cxx(name, **kwargs):
return n.build(built(name + objext), 'cxx', src(name + '.cc'), **kwargs)
def binary(name):
- if platform in ('mingw', 'windows'):
+ if platform.is_windows():
exe = name + '.exe'
n.build(name, 'phony', exe)
return exe
@@ -111,12 +99,12 @@ def binary(name):
n.variable('builddir', 'build')
n.variable('cxx', CXX)
-if platform == 'windows':
+if platform.is_msvc():
n.variable('ar', 'link')
else:
n.variable('ar', configure_env.get('AR', 'ar'))
-if platform == 'windows':
+if platform.is_msvc():
cflags = ['/nologo', # Don't print startup banner.
'/Zi', # Create pdb with debug info.
'/W4', # Highest warning level.
@@ -130,6 +118,7 @@ if platform == 'windows':
# We never have strings or arrays larger than 2**31.
'/wd4267',
'/DNOMINMAX', '/D_CRT_SECURE_NO_WARNINGS',
+ '/D_VARIADIC_MAX=10',
'/DNINJA_PYTHON="%s"' % options.with_python]
ldflags = ['/DEBUG', '/libpath:$builddir']
if not options.debug:
@@ -151,31 +140,32 @@ else:
cflags += ['-O2', '-DNDEBUG']
if 'clang' in os.path.basename(CXX):
cflags += ['-fcolor-diagnostics']
- if platform == 'mingw':
+ if platform.is_mingw():
cflags += ['-D_WIN32_WINNT=0x0501']
ldflags = ['-L$builddir']
libs = []
-if platform == 'mingw':
+if platform.is_mingw():
cflags.remove('-fvisibility=hidden');
ldflags.append('-static')
-elif platform == 'sunos5':
+elif platform.is_sunos5():
cflags.remove('-fvisibility=hidden')
-elif platform == 'windows':
+elif platform.is_msvc():
pass
else:
if options.profile == 'gmon':
cflags.append('-pg')
ldflags.append('-pg')
elif options.profile == 'pprof':
- libs.append('-lprofiler')
+ cflags.append('-fno-omit-frame-pointer')
+ libs.extend(['-Wl,--no-as-needed', '-lprofiler'])
def shell_escape(str):
"""Escape str such that it's interpreted as a single argument by
the shell."""
# This isn't complete, but it's just enough to make NINJA_PYTHON work.
- if platform in ('windows', 'mingw'):
+ if platform.is_windows():
return str
if '"' in str:
return "'%s'" % str.replace("'", "\\'")
@@ -189,27 +179,24 @@ if 'LDFLAGS' in configure_env:
n.variable('ldflags', ' '.join(shell_escape(flag) for flag in ldflags))
n.newline()
-if platform == 'windows':
- compiler = '$cxx'
- if options.with_ninja:
- compiler = ('%s -t msvc -o $out -- $cxx /showIncludes' %
- options.with_ninja)
+if platform.is_msvc():
n.rule('cxx',
- command='%s $cflags -c $in /Fo$out' % compiler,
- depfile='$out.d',
- description='CXX $out')
+ command='$cxx /showIncludes $cflags -c $in /Fo$out',
+ description='CXX $out',
+ deps='msvc')
else:
n.rule('cxx',
command='$cxx -MMD -MT $out -MF $out.d $cflags -c $in -o $out',
depfile='$out.d',
+ deps='gcc',
description='CXX $out')
n.newline()
-if host == 'windows':
+if host.is_msvc():
n.rule('ar',
command='lib /nologo /ltcg /out:$out $in',
description='LIB $out')
-elif host == 'mingw':
+elif host.is_mingw():
n.rule('ar',
command='cmd /c $ar cqs $out.tmp $in && move /Y $out.tmp $out',
description='AR $out')
@@ -219,7 +206,7 @@ else:
description='AR $out')
n.newline()
-if platform == 'windows':
+if platform.is_msvc():
n.rule('link',
command='$cxx $in $libs /nologo /link $ldflags /out:$out',
description='LINK $out')
@@ -231,7 +218,7 @@ n.newline()
objs = []
-if platform not in ('solaris', 'mingw', 'windows'):
+if not platform.is_windows() and not platform.is_solaris():
n.comment('browse_py.h is used to inline browse.py.')
n.rule('inline',
command='src/inline.sh $varname < $in > $out',
@@ -269,6 +256,7 @@ for name in ['build',
'build_log',
'clean',
'depfile_parser',
+ 'deps_log',
'disk_interface',
'edit_distance',
'eval_env',
@@ -276,30 +264,31 @@ for name in ['build',
'graph',
'graphviz',
'lexer',
+ 'line_printer',
'manifest_parser',
'metrics',
'state',
'util',
'version']:
objs += cxx(name)
-if platform in ('mingw', 'windows'):
+if platform.is_windows():
for name in ['subprocess-win32',
'includes_normalize-win32',
'msvc_helper-win32',
'msvc_helper_main-win32']:
objs += cxx(name)
- if platform == 'windows':
+ if platform.is_msvc():
objs += cxx('minidump-win32')
objs += cc('getopt')
else:
objs += cxx('subprocess-posix')
-if platform == 'windows':
+if platform.is_msvc():
ninja_lib = n.build(built('ninja.lib'), 'ar', objs)
else:
ninja_lib = n.build(built('libninja.a'), 'ar', objs)
n.newline()
-if platform == 'windows':
+if platform.is_msvc():
libs.append('ninja.lib')
else:
libs.append('-lninja')
@@ -324,21 +313,18 @@ if options.with_gtest:
path = options.with_gtest
gtest_all_incs = '-I%s -I%s' % (path, os.path.join(path, 'include'))
- if platform == 'windows':
- gtest_cflags = '/nologo /EHsc /Zi ' + gtest_all_incs
+ if platform.is_msvc():
+ gtest_cflags = '/nologo /EHsc /Zi /D_VARIADIC_MAX=10 ' + gtest_all_incs
else:
gtest_cflags = '-fvisibility=hidden ' + gtest_all_incs
objs += n.build(built('gtest-all' + objext), 'cxx',
os.path.join(path, 'src', 'gtest-all.cc'),
variables=[('cflags', gtest_cflags)])
- objs += n.build(built('gtest_main' + objext), 'cxx',
- os.path.join(path, 'src', 'gtest_main.cc'),
- variables=[('cflags', gtest_cflags)])
test_cflags.append('-I%s' % os.path.join(path, 'include'))
else:
# Use gtest from system.
- if platform == 'windows':
+ if platform.is_msvc():
test_libs.extend(['gtest_main.lib', 'gtest.lib'])
else:
test_libs.extend(['-lgtest_main', '-lgtest'])
@@ -348,21 +334,23 @@ for name in ['build_log_test',
'build_test',
'clean_test',
'depfile_parser_test',
+ 'deps_log_test',
'disk_interface_test',
'edit_distance_test',
'graph_test',
'lexer_test',
'manifest_parser_test',
+ 'ninja_test',
'state_test',
'subprocess_test',
'test',
'util_test']:
objs += cxx(name, variables=[('cflags', '$test_cflags')])
-if platform in ('windows', 'mingw'):
+if platform.is_windows():
for name in ['includes_normalize_test', 'msvc_helper_test']:
objs += cxx(name, variables=[('cflags', test_cflags)])
-if platform != 'mingw' and platform != 'windows':
+if not platform.is_windows():
test_libs.append('-lpthread')
ninja_test = n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib,
variables=[('ldflags', test_ldflags),
@@ -425,7 +413,7 @@ n.build('doxygen', 'doxygen', doc('doxygen.config'),
implicit=mainpage)
n.newline()
-if host != 'mingw':
+if not host.is_mingw():
n.comment('Regenerate build files if build script changes.')
n.rule('configure',
command='${configure_env}%s configure.py $configure_args' %
@@ -438,7 +426,7 @@ if host != 'mingw':
n.default(ninja)
n.newline()
-if host == 'linux':
+if host.is_linux():
n.comment('Packaging')
n.rule('rpmbuild',
command="misc/packaging/rpmbuild.sh",