X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=configure.py;h=43904349a89b078cf863f6235f67039310b1acfc;hb=eefa3095b147dd7b0da9c91caf55373e8f773283;hp=6d4c4d40bb6bf31ac54ba445eea7484c17cdf5d5;hpb=60e8da125b20548a224239451314a1b20c9bccf7;p=platform%2Fupstream%2Fninja.git diff --git a/configure.py b/configure.py index 6d4c4d4..4390434 100755 --- a/configure.py +++ b/configure.py @@ -28,7 +28,8 @@ import string import subprocess import sys -sys.path.insert(0, 'misc') +sourcedir = os.path.dirname(os.path.realpath(__file__)) +sys.path.insert(0, os.path.join(sourcedir, 'misc')) import ninja_syntax @@ -57,11 +58,18 @@ class Platform(object): self._platform = 'bitrig' elif self._platform.startswith('netbsd'): self._platform = 'netbsd' + elif self._platform.startswith('aix'): + self._platform = 'aix' + elif self._platform.startswith('os400'): + self._platform = 'os400' + elif self._platform.startswith('dragonfly'): + self._platform = 'dragonfly' @staticmethod def known_platforms(): return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5', - 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd'] + 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd', 'aix', + 'dragonfly'] def platform(self): return self._platform @@ -76,11 +84,11 @@ class Platform(object): return self._platform == 'msvc' def msvc_needs_fs(self): - popen = subprocess.Popen(['cl', '/nologo', '/?'], + popen = subprocess.Popen(['cl', '/nologo', '/help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = popen.communicate() - return '/FS ' in str(out) + return b'/FS' in out def is_windows(self): return self.is_mingw() or self.is_msvc() @@ -88,12 +96,26 @@ class Platform(object): def is_solaris(self): return self._platform == 'solaris' + def is_aix(self): + return self._platform == 'aix' + + def is_os400_pase(self): + return self._platform == 'os400' or os.uname().sysname.startswith('OS400') + def uses_usr_local(self): - return self._platform in ('freebsd', 'openbsd', 'bitrig') + return self._platform in ('freebsd', 'openbsd', 'bitrig', 'dragonfly', 'netbsd') def supports_ppoll(self): - return self._platform in ('linux', 'openbsd', 'bitrig') + return self._platform in ('freebsd', 'linux', 'openbsd', 'bitrig', + 'dragonfly') + def supports_ninja_browse(self): + return (not self.is_windows() + and not self.is_solaris() + and not self.is_aix()) + + def can_rebuild_in_place(self): + return not (self.is_windows() or self.is_aix()) class Bootstrap: """API shim for ninja_syntax.Writer that instead runs the commands. @@ -103,8 +125,9 @@ class Bootstrap: It also proxies all calls to an underlying ninja_syntax.Writer, to behave like non-bootstrap mode. """ - def __init__(self, writer): + def __init__(self, writer, verbose=False): self.writer = writer + self.verbose = verbose # Map of variable name => expanded variable value. self.vars = {} # Map of rule name => dict of rule attributes. @@ -119,7 +142,9 @@ class Bootstrap: return self.writer.newline() def variable(self, key, val): - self.vars[key] = self._expand(val) + # In bootstrap mode, we have no ninja process to catch /showIncludes + # output. + self.vars[key] = self._expand(val).replace('/showIncludes', '') return self.writer.variable(key, val) def rule(self, name, **kwargs): @@ -151,17 +176,23 @@ class Bootstrap: def _expand_paths(self, paths): """Expand $vars in an array of paths, e.g. from a 'build' block.""" paths = ninja_syntax.as_list(paths) - return ' '.join(map(self._expand, paths)) + return ' '.join(map(self._shell_escape, (map(self._expand, paths)))) def _expand(self, str, local_vars={}): """Expand $vars in a string.""" return ninja_syntax.expand(str, self.vars, local_vars) + def _shell_escape(self, path): + """Quote paths containing spaces.""" + return '"%s"' % path if ' ' in path else path + def _run_command(self, cmdline): """Run a subcommand, quietly. Prints the full command on error.""" try: + if self.verbose: + print(cmdline) subprocess.check_call(cmdline, shell=True) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError: print('when running: ', cmdline) raise @@ -170,6 +201,8 @@ parser = OptionParser() profilers = ['gmon', 'pprof'] parser.add_option('--bootstrap', action='store_true', help='bootstrap a ninja binary from nothing') +parser.add_option('--verbose', action='store_true', + help='enable verbose build') parser.add_option('--platform', help='target platform (' + '/'.join(Platform.known_platforms()) + ')', @@ -214,7 +247,7 @@ if options.bootstrap: # Wrap ninja_writer with the Bootstrapper, which also executes the # commands. print('bootstrapping ninja...') - n = Bootstrap(n) + n = Bootstrap(n, verbose=options.verbose) n.comment('This file is used to build ninja itself.') n.comment('It is generated by ' + os.path.basename(__file__) + '.') @@ -228,7 +261,7 @@ configure_args = sys.argv[1:] if '--bootstrap' in configure_args: configure_args.remove('--bootstrap') n.variable('configure_args', ' '.join(configure_args)) -env_keys = set(['CXX', 'AR', 'CFLAGS', 'LDFLAGS']) +env_keys = set(['CXX', 'AR', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS']) configure_env = dict((k, os.environ[k]) for k in os.environ if k in env_keys) if configure_env: config_str = ' '.join([k + '=' + pipes.quote(configure_env[k]) @@ -236,18 +269,18 @@ if configure_env: n.variable('configure_env', config_str + '$ ') n.newline() -CXX = configure_env.get('CXX', 'g++') +CXX = configure_env.get('CXX', 'c++') objext = '.o' if platform.is_msvc(): CXX = 'cl' objext = '.obj' def src(filename): - return os.path.join('src', filename) + return os.path.join('$root', 'src', filename) def built(filename): return os.path.join('$builddir', filename) def doc(filename): - return os.path.join('doc', filename) + return os.path.join('$root', 'doc', filename) def cc(name, **kwargs): return n.build(built(name + objext), 'cxx', src(name + '.c'), **kwargs) def cxx(name, **kwargs): @@ -259,6 +292,12 @@ def binary(name): return exe return name +root = sourcedir +if root == os.getcwd(): + # In the common case where we're building directly in the source + # tree, simplify all the paths to just be cwd-relative. + root = '.' +n.variable('root', root) n.variable('builddir', 'build') n.variable('cxx', CXX) if platform.is_msvc(): @@ -272,21 +311,21 @@ if platform.is_msvc(): '/Zi', # Create pdb with debug info. '/W4', # Highest warning level. '/WX', # Warnings as errors. - '/wd4530', '/wd4100', '/wd4706', + '/wd4530', '/wd4100', '/wd4706', '/wd4244', '/wd4512', '/wd4800', '/wd4702', '/wd4819', + # Disable warnings about constant conditional expressions. + '/wd4127', # Disable warnings about passing "this" during initialization. '/wd4355', + # Disable warnings about ignored typedef in DbgHelp.h + '/wd4091', '/GR-', # Disable RTTI. # Disable size_t -> int truncation warning. # We never have strings or arrays larger than 2**31. '/wd4267', '/DNOMINMAX', '/D_CRT_SECURE_NO_WARNINGS', - '/D_VARIADIC_MAX=10', + '/D_HAS_EXCEPTIONS=0', '/DNINJA_PYTHON="%s"' % options.with_python] - if options.bootstrap: - # In bootstrap mode, we have no ninja process to catch /showIncludes - # output. - cflags.remove('/showIncludes') if platform.msvc_needs_fs(): cflags.append('/FS') ldflags = ['/DEBUG', '/libpath:$builddir'] @@ -296,25 +335,37 @@ if platform.is_msvc(): else: cflags = ['-g', '-Wall', '-Wextra', '-Wno-deprecated', + '-Wno-missing-field-initializers', '-Wno-unused-parameter', '-fno-rtti', '-fno-exceptions', '-fvisibility=hidden', '-pipe', - '-Wno-missing-field-initializers', '-DNINJA_PYTHON="%s"' % options.with_python] if options.debug: cflags += ['-D_GLIBCXX_DEBUG', '-D_GLIBCXX_DEBUG_PEDANTIC'] cflags.remove('-fno-rtti') # Needed for above pedanticness. else: cflags += ['-O2', '-DNDEBUG'] - if 'clang' in os.path.basename(CXX): - cflags += ['-fcolor-diagnostics'] + try: + proc = subprocess.Popen( + [CXX, '-fdiagnostics-color', '-c', '-x', 'c++', '/dev/null', + '-o', '/dev/null'], + stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT) + if proc.wait() == 0: + cflags += ['-fdiagnostics-color'] + except: + pass if platform.is_mingw(): - cflags += ['-D_WIN32_WINNT=0x0501'] + cflags += ['-D_WIN32_WINNT=0x0601', '-D__USE_MINGW_ANSI_STDIO=1'] ldflags = ['-L$builddir'] if platform.uses_usr_local(): cflags.append('-I/usr/local/include') ldflags.append('-L/usr/local/lib') + if platform.is_aix(): + # printf formats for int64_t, uint64_t; large file support + cflags.append('-D__STDC_FORMAT_MACROS') + cflags.append('-D_LARGE_FILES') + libs = [] @@ -323,6 +374,8 @@ if platform.is_mingw(): ldflags.append('-static') elif platform.is_solaris(): cflags.remove('-fvisibility=hidden') +elif platform.is_aix(): + cflags.remove('-fvisibility=hidden') elif platform.is_msvc(): pass else: @@ -335,11 +388,12 @@ else: if platform.supports_ppoll() and not options.force_pselect: cflags.append('-DUSE_PPOLL') - -have_browse = not platform.is_windows() and not platform.is_solaris() -if have_browse: +if platform.supports_ninja_browse(): cflags.append('-DNINJA_HAVE_BROWSE') +# Search for generated headers relative to build dir. +cflags.append('-I.') + def shell_escape(str): """Escape str such that it's interpreted as a single argument by the shell.""" @@ -353,6 +407,10 @@ def shell_escape(str): if 'CFLAGS' in configure_env: cflags.append(configure_env['CFLAGS']) + ldflags.append(configure_env['CFLAGS']) +if 'CXXFLAGS' in configure_env: + cflags.append(configure_env['CXXFLAGS']) + ldflags.append(configure_env['CXXFLAGS']) n.variable('cflags', ' '.join(shell_escape(flag) for flag in cflags)) if 'LDFLAGS' in configure_env: ldflags.append(configure_env['LDFLAGS']) @@ -361,7 +419,7 @@ n.newline() if platform.is_msvc(): n.rule('cxx', - command='$cxx $cflags -c $in /Fo$out', + command='$cxx $cflags -c $in /Fo$out /Fd' + built('$pdb'), description='CXX $out', deps='msvc' # /showIncludes is included in $cflags. ) @@ -379,7 +437,7 @@ if host.is_msvc(): description='LIB $out') elif host.is_mingw(): n.rule('ar', - command='cmd /c $ar cqs $out.tmp $in && move /Y $out.tmp $out', + command='$ar crs $out $in', description='AR $out') else: n.rule('ar', @@ -399,13 +457,13 @@ n.newline() objs = [] -if have_browse: +if platform.supports_ninja_browse(): n.comment('browse_py.h is used to inline browse.py.') n.rule('inline', - command='src/inline.sh $varname < $in > $out', + command='"%s"' % src('inline.sh') + ' $varname < $in > $out', description='INLINE $out') n.build(built('browse_py.h'), 'inline', src('browse.py'), - implicit='src/inline.sh', + implicit=src('inline.sh'), variables=[('varname', 'kBrowsePy')]) n.newline() @@ -421,7 +479,7 @@ def has_re2c(): return False if has_re2c(): n.rule('re2c', - command='re2c -b -i --no-generation-date -o $out $in', + command='re2c -b -i --no-generation-date --no-version -o $out $in', description='RE2C $out') # Generate the .cc files in the source directory so we can check them in. n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc')) @@ -432,36 +490,49 @@ else: n.newline() n.comment('Core source files all build into ninja library.') +cxxvariables = [] +if platform.is_msvc(): + cxxvariables = [('pdb', 'ninja.pdb')] for name in ['build', 'build_log', 'clean', + 'clparser', 'debug_flags', 'depfile_parser', 'deps_log', 'disk_interface', + 'dyndep', + 'dyndep_parser', 'edit_distance', 'eval_env', 'graph', 'graphviz', + 'json', 'lexer', 'line_printer', 'manifest_parser', 'metrics', + 'missing_deps', + 'parser', 'state', + 'status', + 'string_piece_util', 'util', 'version']: - objs += cxx(name) + objs += cxx(name, variables=cxxvariables) if platform.is_windows(): for name in ['subprocess-win32', 'includes_normalize-win32', 'msvc_helper-win32', 'msvc_helper_main-win32']: - objs += cxx(name) + objs += cxx(name, variables=cxxvariables) if platform.is_msvc(): - objs += cxx('minidump-win32') + objs += cxx('minidump-win32', variables=cxxvariables) objs += cc('getopt') else: objs += cxx('subprocess-posix') +if platform.is_aix(): + objs += cc('getopt') if platform.is_msvc(): ninja_lib = n.build(built('ninja.lib'), 'ar', objs) else: @@ -473,10 +544,13 @@ if platform.is_msvc(): else: libs.append('-lninja') +if platform.is_aix() and not platform.is_os400_pase(): + libs.append('-lperfstat') + all_targets = [] n.comment('Main executable is library plus main() function.') -objs = cxx('ninja') +objs = cxx('ninja', variables=cxxvariables) ninja = n.build(binary('ninja'), 'link', objs, implicit=ninja_lib, variables=[('libs', libs)]) n.newline() @@ -490,53 +564,61 @@ if options.bootstrap: n.comment('Tests all build into ninja_test executable.') -test_libs = libs objs = [] +if platform.is_msvc(): + cxxvariables = [('pdb', 'ninja_test.pdb')] for name in ['build_log_test', 'build_test', 'clean_test', + 'clparser_test', 'depfile_parser_test', 'deps_log_test', + 'dyndep_parser_test', 'disk_interface_test', 'edit_distance_test', 'graph_test', + 'json_test', 'lexer_test', 'manifest_parser_test', + 'missing_deps_test', 'ninja_test', 'state_test', + 'status_test', + 'string_piece_util_test', 'subprocess_test', 'test', 'util_test']: - objs += cxx(name) + objs += cxx(name, variables=cxxvariables) if platform.is_windows(): for name in ['includes_normalize_test', 'msvc_helper_test']: - objs += cxx(name) + objs += cxx(name, variables=cxxvariables) -if not platform.is_windows(): - test_libs.append('-lpthread') ninja_test = n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib, - variables=[('libs', test_libs)]) + variables=[('libs', libs)]) n.newline() all_targets += ninja_test n.comment('Ancillary executables.') -objs = cxx('build_log_perftest') -all_targets += n.build(binary('build_log_perftest'), 'link', objs, - implicit=ninja_lib, variables=[('libs', libs)]) -objs = cxx('canon_perftest') -all_targets += n.build(binary('canon_perftest'), 'link', objs, - implicit=ninja_lib, variables=[('libs', libs)]) -objs = cxx('depfile_parser_perftest') -all_targets += n.build(binary('depfile_parser_perftest'), 'link', objs, - implicit=ninja_lib, variables=[('libs', libs)]) -objs = cxx('hash_collision_bench') -all_targets += n.build(binary('hash_collision_bench'), 'link', objs, - implicit=ninja_lib, variables=[('libs', libs)]) -objs = cxx('manifest_parser_perftest') -all_targets += n.build(binary('manifest_parser_perftest'), 'link', objs, - implicit=ninja_lib, variables=[('libs', libs)]) + +if platform.is_aix() and '-maix64' not in ldflags: + # Both hash_collision_bench and manifest_parser_perftest require more + # memory than will fit in the standard 32-bit AIX shared stack/heap (256M) + libs.append('-Wl,-bmaxdata:0x80000000') + +for name in ['build_log_perftest', + 'canon_perftest', + 'depfile_parser_perftest', + 'hash_collision_bench', + 'manifest_parser_perftest', + 'clparser_perftest']: + if platform.is_msvc(): + cxxvariables = [('pdb', name + '.pdb')] + objs = cxx(name, variables=cxxvariables) + all_targets += n.build(binary(name), 'link', objs, + implicit=ninja_lib, variables=[('libs', libs)]) + n.newline() n.comment('Generate a graph using the "graph" tool.') @@ -555,13 +637,19 @@ n.rule('asciidoc', n.rule('xsltproc', command='xsltproc --nonet doc/docbook.xsl $in > $out', description='XSLTPROC $out') -xml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc')) -manual = n.build(doc('manual.html'), 'xsltproc', xml, - implicit=doc('style.css')) +docbookxml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc')) +manual = n.build(doc('manual.html'), 'xsltproc', docbookxml, + implicit=[doc('style.css'), doc('docbook.xsl')]) n.build('manual', 'phony', order_only=manual) n.newline() +n.rule('dblatex', + command='dblatex -q -o $out -p doc/dblatex.xsl $in', + description='DBLATEX $out') +n.build(doc('manual.pdf'), 'dblatex', docbookxml, + implicit=[doc('dblatex.xsl')]) + n.comment('Generate Doxygen.') n.rule('doxygen', command='doxygen $in', @@ -572,7 +660,7 @@ n.rule('doxygen_mainpage', command='$doxygen_mainpage_generator $in > $out', description='DOXYGEN_MAINPAGE $out') mainpage = n.build(built('doxygen_mainpage'), 'doxygen_mainpage', - ['README', 'COPYING'], + ['README.md', 'COPYING'], implicit=['$doxygen_mainpage_generator']) n.build('doxygen', 'doxygen', doc('doxygen.config'), implicit=mainpage) @@ -581,11 +669,12 @@ n.newline() 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' % + command='${configure_env}%s $root/configure.py $configure_args' % options.with_python, generator=True) n.build('build.ninja', 'configure', - implicit=['configure.py', os.path.normpath('misc/ninja_syntax.py')]) + implicit=['$root/configure.py', + os.path.normpath('$root/misc/ninja_syntax.py')]) n.newline() n.default(ninja) @@ -606,11 +695,26 @@ print('wrote %s.' % BUILD_FILENAME) if options.bootstrap: print('bootstrap complete. rebuilding...') - if platform.is_windows(): - bootstrap_exe = 'ninja.bootstrap.exe' + + rebuild_args = [] + + if platform.can_rebuild_in_place(): + rebuild_args.append('./ninja') + else: + if platform.is_windows(): + bootstrap_exe = 'ninja.bootstrap.exe' + final_exe = 'ninja.exe' + else: + bootstrap_exe = './ninja.bootstrap' + final_exe = './ninja' + if os.path.exists(bootstrap_exe): os.unlink(bootstrap_exe) - os.rename('ninja.exe', bootstrap_exe) - subprocess.check_call('ninja.bootstrap.exe', shell=True) - else: - subprocess.check_call('./ninja', shell=True) + os.rename(final_exe, bootstrap_exe) + + rebuild_args.append(bootstrap_exe) + + if options.verbose: + rebuild_args.append('-v') + + subprocess.check_call(rebuild_args)