5 kx #!/usr/bin/env python
5 kx #
5 kx # Copyright 2001 Google Inc. All Rights Reserved.
5 kx #
5 kx # Licensed under the Apache License, Version 2.0 (the "License");
5 kx # you may not use this file except in compliance with the License.
5 kx # You may obtain a copy of the License at
5 kx #
5 kx # http://www.apache.org/licenses/LICENSE-2.0
5 kx #
5 kx # Unless required by applicable law or agreed to in writing, software
5 kx # distributed under the License is distributed on an "AS IS" BASIS,
5 kx # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 kx # See the License for the specific language governing permissions and
5 kx # limitations under the License.
5 kx
5 kx """Script that generates the build.ninja for ninja itself.
5 kx
5 kx Projects that use ninja themselves should either write a similar script
5 kx or use a meta-build system that supports Ninja output."""
5 kx
5 kx from __future__ import print_function
5 kx
5 kx from optparse import OptionParser
5 kx import os
5 kx import pipes
5 kx import string
5 kx import subprocess
5 kx import sys
5 kx
5 kx sourcedir = os.path.dirname(os.path.realpath(__file__))
5 kx sys.path.insert(0, os.path.join(sourcedir, 'misc'))
5 kx import ninja_syntax
5 kx
5 kx
5 kx class Platform(object):
5 kx """Represents a host/target platform and its specific build attributes."""
5 kx def __init__(self, platform):
5 kx self._platform = platform
5 kx if self._platform is not None:
5 kx return
5 kx self._platform = sys.platform
5 kx if self._platform.startswith('linux'):
5 kx self._platform = 'linux'
5 kx elif self._platform.startswith('freebsd'):
5 kx self._platform = 'freebsd'
5 kx elif self._platform.startswith('gnukfreebsd'):
5 kx self._platform = 'freebsd'
5 kx elif self._platform.startswith('openbsd'):
5 kx self._platform = 'openbsd'
5 kx elif self._platform.startswith('solaris') or self._platform == 'sunos5':
5 kx self._platform = 'solaris'
5 kx elif self._platform.startswith('mingw'):
5 kx self._platform = 'mingw'
5 kx elif self._platform.startswith('win'):
5 kx self._platform = 'msvc'
5 kx elif self._platform.startswith('bitrig'):
5 kx self._platform = 'bitrig'
5 kx elif self._platform.startswith('netbsd'):
5 kx self._platform = 'netbsd'
5 kx elif self._platform.startswith('aix'):
5 kx self._platform = 'aix'
5 kx elif self._platform.startswith('os400'):
5 kx self._platform = 'os400'
5 kx elif self._platform.startswith('dragonfly'):
5 kx self._platform = 'dragonfly'
5 kx
5 kx @staticmethod
5 kx def known_platforms():
5 kx return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
5 kx 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd', 'aix',
5 kx 'dragonfly']
5 kx
5 kx def platform(self):
5 kx return self._platform
5 kx
5 kx def is_linux(self):
5 kx return self._platform == 'linux'
5 kx
5 kx def is_mingw(self):
5 kx return self._platform == 'mingw'
5 kx
5 kx def is_msvc(self):
5 kx return self._platform == 'msvc'
5 kx
5 kx def msvc_needs_fs(self):
5 kx popen = subprocess.Popen(['cl', '/nologo', '/?'],
5 kx stdout=subprocess.PIPE,
5 kx stderr=subprocess.PIPE)
5 kx out, err = popen.communicate()
5 kx return b'/FS' in out
5 kx
5 kx def is_windows(self):
5 kx return self.is_mingw() or self.is_msvc()
5 kx
5 kx def is_solaris(self):
5 kx return self._platform == 'solaris'
5 kx
5 kx def is_aix(self):
5 kx return self._platform == 'aix'
5 kx
5 kx def is_os400_pase(self):
5 kx return self._platform == 'os400' or os.uname().sysname.startswith('OS400')
5 kx
5 kx def uses_usr_local(self):
5 kx return self._platform in ('freebsd', 'openbsd', 'bitrig', 'dragonfly', 'netbsd')
5 kx
5 kx def supports_ppoll(self):
5 kx return self._platform in ('freebsd', 'linux', 'openbsd', 'bitrig',
5 kx 'dragonfly')
5 kx
5 kx def supports_ninja_browse(self):
5 kx return (not self.is_windows()
5 kx and not self.is_solaris()
5 kx and not self.is_aix())
5 kx
5 kx def can_rebuild_in_place(self):
5 kx return not (self.is_windows() or self.is_aix())
5 kx
5 kx class Bootstrap:
5 kx """API shim for ninja_syntax.Writer that instead runs the commands.
5 kx
5 kx Used to bootstrap Ninja from scratch. In --bootstrap mode this
5 kx class is used to execute all the commands to build an executable.
5 kx It also proxies all calls to an underlying ninja_syntax.Writer, to
5 kx behave like non-bootstrap mode.
5 kx """
5 kx def __init__(self, writer, verbose=False):
5 kx self.writer = writer
5 kx self.verbose = verbose
5 kx # Map of variable name => expanded variable value.
5 kx self.vars = {}
5 kx # Map of rule name => dict of rule attributes.
5 kx self.rules = {
5 kx 'phony': {}
5 kx }
5 kx
5 kx def comment(self, text):
5 kx return self.writer.comment(text)
5 kx
5 kx def newline(self):
5 kx return self.writer.newline()
5 kx
5 kx def variable(self, key, val):
5 kx # In bootstrap mode, we have no ninja process to catch /showIncludes
5 kx # output.
5 kx self.vars[key] = self._expand(val).replace('/showIncludes', '')
5 kx return self.writer.variable(key, val)
5 kx
5 kx def rule(self, name, **kwargs):
5 kx self.rules[name] = kwargs
5 kx return self.writer.rule(name, **kwargs)
5 kx
5 kx def build(self, outputs, rule, inputs=None, **kwargs):
5 kx ruleattr = self.rules[rule]
5 kx cmd = ruleattr.get('command')
5 kx if cmd is None: # A phony rule, for example.
5 kx return
5 kx
5 kx # Implement just enough of Ninja variable expansion etc. to
5 kx # make the bootstrap build work.
5 kx local_vars = {
5 kx 'in': self._expand_paths(inputs),
5 kx 'out': self._expand_paths(outputs)
5 kx }
5 kx for key, val in kwargs.get('variables', []):
5 kx local_vars[key] = ' '.join(ninja_syntax.as_list(val))
5 kx
5 kx self._run_command(self._expand(cmd, local_vars))
5 kx
5 kx return self.writer.build(outputs, rule, inputs, **kwargs)
5 kx
5 kx def default(self, paths):
5 kx return self.writer.default(paths)
5 kx
5 kx def _expand_paths(self, paths):
5 kx """Expand $vars in an array of paths, e.g. from a 'build' block."""
5 kx paths = ninja_syntax.as_list(paths)
5 kx return ' '.join(map(self._shell_escape, (map(self._expand, paths))))
5 kx
5 kx def _expand(self, str, local_vars={}):
5 kx """Expand $vars in a string."""
5 kx return ninja_syntax.expand(str, self.vars, local_vars)
5 kx
5 kx def _shell_escape(self, path):
5 kx """Quote paths containing spaces."""
5 kx return '"%s"' % path if ' ' in path else path
5 kx
5 kx def _run_command(self, cmdline):
5 kx """Run a subcommand, quietly. Prints the full command on error."""
5 kx try:
5 kx if self.verbose:
5 kx print(cmdline)
5 kx subprocess.check_call(cmdline, shell=True)
5 kx except subprocess.CalledProcessError:
5 kx print('when running: ', cmdline)
5 kx raise
5 kx
5 kx
5 kx parser = OptionParser()
5 kx profilers = ['gmon', 'pprof']
5 kx parser.add_option('--bootstrap', action='store_true',
5 kx help='bootstrap a ninja binary from nothing')
5 kx parser.add_option('--verbose', action='store_true',
5 kx help='enable verbose build')
5 kx parser.add_option('--platform',
5 kx help='target platform (' +
5 kx '/'.join(Platform.known_platforms()) + ')',
5 kx choices=Platform.known_platforms())
5 kx parser.add_option('--host',
5 kx help='host platform (' +
5 kx '/'.join(Platform.known_platforms()) + ')',
5 kx choices=Platform.known_platforms())
5 kx parser.add_option('--debug', action='store_true',
5 kx help='enable debugging extras',)
5 kx parser.add_option('--profile', metavar='TYPE',
5 kx choices=profilers,
5 kx help='enable profiling (' + '/'.join(profilers) + ')',)
5 kx parser.add_option('--with-gtest', metavar='PATH', help='ignored')
5 kx parser.add_option('--with-python', metavar='EXE',
5 kx help='use EXE as the Python interpreter',
5 kx default=os.path.basename(sys.executable))
5 kx parser.add_option('--force-pselect', action='store_true',
5 kx help='ppoll() is used by default where available, '
5 kx 'but some platforms may need to use pselect instead',)
5 kx (options, args) = parser.parse_args()
5 kx if args:
5 kx print('ERROR: extra unparsed command-line arguments:', args)
5 kx sys.exit(1)
5 kx
5 kx platform = Platform(options.platform)
5 kx if options.host:
5 kx host = Platform(options.host)
5 kx else:
5 kx host = platform
5 kx
5 kx BUILD_FILENAME = 'build.ninja'
5 kx ninja_writer = ninja_syntax.Writer(open(BUILD_FILENAME, 'w'))
5 kx n = ninja_writer
5 kx
5 kx if options.bootstrap:
5 kx # Make the build directory.
5 kx try:
5 kx os.mkdir('build')
5 kx except OSError:
5 kx pass
5 kx # Wrap ninja_writer with the Bootstrapper, which also executes the
5 kx # commands.
5 kx print('bootstrapping ninja...')
5 kx n = Bootstrap(n, verbose=options.verbose)
5 kx
5 kx n.comment('This file is used to build ninja itself.')
5 kx n.comment('It is generated by ' + os.path.basename(__file__) + '.')
5 kx n.newline()
5 kx
5 kx n.variable('ninja_required_version', '1.3')
5 kx n.newline()
5 kx
5 kx n.comment('The arguments passed to configure.py, for rerunning it.')
5 kx configure_args = sys.argv[1:]
5 kx if '--bootstrap' in configure_args:
5 kx configure_args.remove('--bootstrap')
5 kx n.variable('configure_args', ' '.join(configure_args))
5 kx env_keys = set(['CXX', 'AR', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS'])
5 kx configure_env = dict((k, os.environ[k]) for k in os.environ if k in env_keys)
5 kx if configure_env:
5 kx config_str = ' '.join([k + '=' + pipes.quote(configure_env[k])
5 kx for k in configure_env])
5 kx n.variable('configure_env', config_str + '$ ')
5 kx n.newline()
5 kx
5 kx CXX = configure_env.get('CXX', 'c++')
5 kx objext = '.o'
5 kx if platform.is_msvc():
5 kx CXX = 'cl'
5 kx objext = '.obj'
5 kx
5 kx def src(filename):
5 kx return os.path.join('$root', 'src', filename)
5 kx def built(filename):
5 kx return os.path.join('$builddir', filename)
5 kx def doc(filename):
5 kx return os.path.join('$root', 'doc', filename)
5 kx def cc(name, **kwargs):
5 kx return n.build(built(name + objext), 'cxx', src(name + '.c'), **kwargs)
5 kx def cxx(name, **kwargs):
5 kx return n.build(built(name + objext), 'cxx', src(name + '.cc'), **kwargs)
5 kx def binary(name):
5 kx if platform.is_windows():
5 kx exe = name + '.exe'
5 kx n.build(name, 'phony', exe)
5 kx return exe
5 kx return name
5 kx
5 kx root = sourcedir
5 kx if root == os.getcwd():
5 kx # In the common case where we're building directly in the source
5 kx # tree, simplify all the paths to just be cwd-relative.
5 kx root = '.'
5 kx n.variable('root', root)
5 kx n.variable('builddir', 'build')
5 kx n.variable('cxx', CXX)
5 kx if platform.is_msvc():
5 kx n.variable('ar', 'link')
5 kx else:
5 kx n.variable('ar', configure_env.get('AR', 'ar'))
5 kx
5 kx if platform.is_msvc():
5 kx cflags = ['/showIncludes',
5 kx '/nologo', # Don't print startup banner.
5 kx '/Zi', # Create pdb with debug info.
5 kx '/W4', # Highest warning level.
5 kx '/WX', # Warnings as errors.
5 kx '/wd4530', '/wd4100', '/wd4706', '/wd4244',
5 kx '/wd4512', '/wd4800', '/wd4702', '/wd4819',
5 kx # Disable warnings about constant conditional expressions.
5 kx '/wd4127',
5 kx # Disable warnings about passing "this" during initialization.
5 kx '/wd4355',
5 kx # Disable warnings about ignored typedef in DbgHelp.h
5 kx '/wd4091',
5 kx '/GR-', # Disable RTTI.
5 kx # Disable size_t -> int truncation warning.
5 kx # We never have strings or arrays larger than 2**31.
5 kx '/wd4267',
5 kx '/DNOMINMAX', '/D_CRT_SECURE_NO_WARNINGS',
5 kx '/D_HAS_EXCEPTIONS=0',
5 kx '/DNINJA_PYTHON="%s"' % options.with_python]
5 kx if platform.msvc_needs_fs():
5 kx cflags.append('/FS')
5 kx ldflags = ['/DEBUG', '/libpath:$builddir']
5 kx if not options.debug:
5 kx cflags += ['/Ox', '/DNDEBUG', '/GL']
5 kx ldflags += ['/LTCG', '/OPT:REF', '/OPT:ICF']
5 kx else:
5 kx cflags = ['-g', '-Wall', '-Wextra',
5 kx '-Wno-deprecated',
5 kx '-Wno-missing-field-initializers',
5 kx '-Wno-unused-parameter',
5 kx '-fno-rtti',
5 kx '-fno-exceptions',
5 kx '-fvisibility=hidden', '-pipe',
5 kx '-DNINJA_PYTHON="%s"' % options.with_python]
5 kx if options.debug:
5 kx cflags += ['-D_GLIBCXX_DEBUG', '-D_GLIBCXX_DEBUG_PEDANTIC']
5 kx cflags.remove('-fno-rtti') # Needed for above pedanticness.
5 kx else:
5 kx cflags += ['-O2', '-DNDEBUG']
5 kx try:
5 kx proc = subprocess.Popen(
5 kx [CXX, '-fdiagnostics-color', '-c', '-x', 'c++', '/dev/null',
5 kx '-o', '/dev/null'],
5 kx stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
5 kx if proc.wait() == 0:
5 kx cflags += ['-fdiagnostics-color']
5 kx except:
5 kx pass
5 kx if platform.is_mingw():
5 kx cflags += ['-D_WIN32_WINNT=0x0601', '-D__USE_MINGW_ANSI_STDIO=1']
5 kx ldflags = ['-L$builddir']
5 kx if platform.uses_usr_local():
5 kx cflags.append('-I/usr/local/include')
5 kx ldflags.append('-L/usr/local/lib')
5 kx if platform.is_aix():
5 kx # printf formats for int64_t, uint64_t; large file support
5 kx cflags.append('-D__STDC_FORMAT_MACROS')
5 kx cflags.append('-D_LARGE_FILES')
5 kx
5 kx
5 kx libs = []
5 kx
5 kx if platform.is_mingw():
5 kx cflags.remove('-fvisibility=hidden');
5 kx ldflags.append('-static')
5 kx elif platform.is_solaris():
5 kx cflags.remove('-fvisibility=hidden')
5 kx elif platform.is_aix():
5 kx cflags.remove('-fvisibility=hidden')
5 kx elif platform.is_msvc():
5 kx pass
5 kx else:
5 kx if options.profile == 'gmon':
5 kx cflags.append('-pg')
5 kx ldflags.append('-pg')
5 kx elif options.profile == 'pprof':
5 kx cflags.append('-fno-omit-frame-pointer')
5 kx libs.extend(['-Wl,--no-as-needed', '-lprofiler'])
5 kx
5 kx if platform.supports_ppoll() and not options.force_pselect:
5 kx cflags.append('-DUSE_PPOLL')
5 kx if platform.supports_ninja_browse():
5 kx cflags.append('-DNINJA_HAVE_BROWSE')
5 kx
5 kx # Search for generated headers relative to build dir.
5 kx cflags.append('-I.')
5 kx
5 kx def shell_escape(str):
5 kx """Escape str such that it's interpreted as a single argument by
5 kx the shell."""
5 kx
5 kx # This isn't complete, but it's just enough to make NINJA_PYTHON work.
5 kx if platform.is_windows():
5 kx return str
5 kx if '"' in str:
5 kx return "'%s'" % str.replace("'", "\\'")
5 kx return str
5 kx
5 kx if 'CFLAGS' in configure_env:
5 kx cflags.append(configure_env['CFLAGS'])
5 kx ldflags.append(configure_env['CFLAGS'])
5 kx if 'CXXFLAGS' in configure_env:
5 kx cflags.append(configure_env['CXXFLAGS'])
5 kx ldflags.append(configure_env['CXXFLAGS'])
5 kx n.variable('cflags', ' '.join(shell_escape(flag) for flag in cflags))
5 kx if 'LDFLAGS' in configure_env:
5 kx ldflags.append(configure_env['LDFLAGS'])
5 kx n.variable('ldflags', ' '.join(shell_escape(flag) for flag in ldflags))
5 kx n.newline()
5 kx
5 kx if platform.is_msvc():
5 kx n.rule('cxx',
5 kx command='$cxx $cflags -c $in /Fo$out /Fd' + built('$pdb'),
5 kx description='CXX $out',
5 kx deps='msvc' # /showIncludes is included in $cflags.
5 kx )
5 kx else:
5 kx n.rule('cxx',
5 kx command='$cxx -MMD -MT $out -MF $out.d $cflags -c $in -o $out',
5 kx depfile='$out.d',
5 kx deps='gcc',
5 kx description='CXX $out')
5 kx n.newline()
5 kx
5 kx if host.is_msvc():
5 kx n.rule('ar',
5 kx command='lib /nologo /ltcg /out:$out $in',
5 kx description='LIB $out')
5 kx elif host.is_mingw():
5 kx n.rule('ar',
5 kx command='$ar crs $out $in',
5 kx description='AR $out')
5 kx else:
5 kx n.rule('ar',
5 kx command='rm -f $out && $ar crs $out $in',
5 kx description='AR $out')
5 kx n.newline()
5 kx
5 kx if platform.is_msvc():
5 kx n.rule('link',
5 kx command='$cxx $in $libs /nologo /link $ldflags /out:$out',
5 kx description='LINK $out')
5 kx else:
5 kx n.rule('link',
5 kx command='$cxx $ldflags -o $out $in $libs',
5 kx description='LINK $out')
5 kx n.newline()
5 kx
5 kx objs = []
5 kx
5 kx if platform.supports_ninja_browse():
5 kx n.comment('browse_py.h is used to inline browse.py.')
5 kx n.rule('inline',
5 kx command='"%s"' % src('inline.sh') + ' $varname < $in > $out',
5 kx description='INLINE $out')
5 kx n.build(built('browse_py.h'), 'inline', src('browse.py'),
5 kx implicit=src('inline.sh'),
5 kx variables=[('varname', 'kBrowsePy')])
5 kx n.newline()
5 kx
5 kx objs += cxx('browse', order_only=built('browse_py.h'))
5 kx n.newline()
5 kx
5 kx n.comment('the depfile parser and ninja lexers are generated using re2c.')
5 kx def has_re2c():
5 kx try:
5 kx proc = subprocess.Popen(['re2c', '-V'], stdout=subprocess.PIPE)
5 kx return int(proc.communicate()[0], 10) >= 1103
5 kx except OSError:
5 kx return False
5 kx if has_re2c():
5 kx n.rule('re2c',
5 kx command='re2c -b -i --no-generation-date -o $out $in',
5 kx description='RE2C $out')
5 kx # Generate the .cc files in the source directory so we can check them in.
5 kx n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc'))
5 kx n.build(src('lexer.cc'), 're2c', src('lexer.in.cc'))
5 kx else:
5 kx print("warning: A compatible version of re2c (>= 0.11.3) was not found; "
5 kx "changes to src/*.in.cc will not affect your build.")
5 kx n.newline()
5 kx
5 kx n.comment('Core source files all build into ninja library.')
5 kx cxxvariables = []
5 kx if platform.is_msvc():
5 kx cxxvariables = [('pdb', 'ninja.pdb')]
5 kx for name in ['build',
5 kx 'build_log',
5 kx 'clean',
5 kx 'clparser',
5 kx 'debug_flags',
5 kx 'depfile_parser',
5 kx 'deps_log',
5 kx 'disk_interface',
5 kx 'dyndep',
5 kx 'dyndep_parser',
5 kx 'edit_distance',
5 kx 'eval_env',
5 kx 'graph',
5 kx 'graphviz',
5 kx 'lexer',
5 kx 'line_printer',
5 kx 'manifest_parser',
5 kx 'metrics',
5 kx 'parser',
5 kx 'state',
5 kx 'string_piece_util',
5 kx 'tokenpool-gnu-make',
5 kx 'util',
5 kx 'version']:
5 kx objs += cxx(name, variables=cxxvariables)
5 kx if platform.is_windows():
5 kx for name in ['subprocess-win32',
5 kx 'tokenpool-gnu-make-win32',
5 kx 'includes_normalize-win32',
5 kx 'msvc_helper-win32',
5 kx 'msvc_helper_main-win32']:
5 kx objs += cxx(name, variables=cxxvariables)
5 kx if platform.is_msvc():
5 kx objs += cxx('minidump-win32', variables=cxxvariables)
5 kx objs += cc('getopt')
5 kx else:
5 kx for name in ['subprocess-posix',
5 kx 'tokenpool-gnu-make-posix']:
5 kx objs += cxx(name)
5 kx if platform.is_aix():
5 kx objs += cc('getopt')
5 kx if platform.is_msvc():
5 kx ninja_lib = n.build(built('ninja.lib'), 'ar', objs)
5 kx else:
5 kx ninja_lib = n.build(built('libninja.a'), 'ar', objs)
5 kx n.newline()
5 kx
5 kx if platform.is_msvc():
5 kx libs.append('ninja.lib')
5 kx else:
5 kx libs.append('-lninja')
5 kx
5 kx if platform.is_aix() and not platform.is_os400_pase():
5 kx libs.append('-lperfstat')
5 kx
5 kx all_targets = []
5 kx
5 kx n.comment('Main executable is library plus main() function.')
5 kx objs = cxx('ninja', variables=cxxvariables)
5 kx ninja = n.build(binary('ninja'), 'link', objs, implicit=ninja_lib,
5 kx variables=[('libs', libs)])
5 kx n.newline()
5 kx all_targets += ninja
5 kx
5 kx if options.bootstrap:
5 kx # We've built the ninja binary. Don't run any more commands
5 kx # through the bootstrap executor, but continue writing the
5 kx # build.ninja file.
5 kx n = ninja_writer
5 kx
5 kx n.comment('Tests all build into ninja_test executable.')
5 kx
5 kx objs = []
5 kx if platform.is_msvc():
5 kx cxxvariables = [('pdb', 'ninja_test.pdb')]
5 kx
5 kx for name in ['build_log_test',
5 kx 'build_test',
5 kx 'clean_test',
5 kx 'clparser_test',
5 kx 'depfile_parser_test',
5 kx 'deps_log_test',
5 kx 'dyndep_parser_test',
5 kx 'disk_interface_test',
5 kx 'edit_distance_test',
5 kx 'graph_test',
5 kx 'lexer_test',
5 kx 'manifest_parser_test',
5 kx 'ninja_test',
5 kx 'state_test',
5 kx 'string_piece_util_test',
5 kx 'subprocess_test',
5 kx 'test',
5 kx 'tokenpool_test',
5 kx 'util_test']:
5 kx objs += cxx(name, variables=cxxvariables)
5 kx if platform.is_windows():
5 kx for name in ['includes_normalize_test', 'msvc_helper_test']:
5 kx objs += cxx(name, variables=cxxvariables)
5 kx
5 kx ninja_test = n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib,
5 kx variables=[('libs', libs)])
5 kx n.newline()
5 kx all_targets += ninja_test
5 kx
5 kx
5 kx n.comment('Ancillary executables.')
5 kx
5 kx if platform.is_aix() and '-maix64' not in ldflags:
5 kx # Both hash_collision_bench and manifest_parser_perftest require more
5 kx # memory than will fit in the standard 32-bit AIX shared stack/heap (256M)
5 kx libs.append('-Wl,-bmaxdata:0x80000000')
5 kx
5 kx for name in ['build_log_perftest',
5 kx 'canon_perftest',
5 kx 'depfile_parser_perftest',
5 kx 'hash_collision_bench',
5 kx 'manifest_parser_perftest',
5 kx 'clparser_perftest']:
5 kx if platform.is_msvc():
5 kx cxxvariables = [('pdb', name + '.pdb')]
5 kx objs = cxx(name, variables=cxxvariables)
5 kx all_targets += n.build(binary(name), 'link', objs,
5 kx implicit=ninja_lib, variables=[('libs', libs)])
5 kx
5 kx n.newline()
5 kx
5 kx n.comment('Generate a graph using the "graph" tool.')
5 kx n.rule('gendot',
5 kx command='./ninja -t graph all > $out')
5 kx n.rule('gengraph',
5 kx command='dot -Tpng $in > $out')
5 kx dot = n.build(built('graph.dot'), 'gendot', ['ninja', 'build.ninja'])
5 kx n.build('graph.png', 'gengraph', dot)
5 kx n.newline()
5 kx
5 kx n.comment('Generate the manual using asciidoc.')
5 kx n.rule('asciidoc',
5 kx command='asciidoc -b docbook -d book -o $out $in',
5 kx description='ASCIIDOC $out')
5 kx n.rule('xsltproc',
5 kx command='xsltproc --nonet doc/docbook.xsl $in > $out',
5 kx description='XSLTPROC $out')
5 kx docbookxml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc'))
5 kx manual = n.build(doc('manual.html'), 'xsltproc', docbookxml,
5 kx implicit=[doc('style.css'), doc('docbook.xsl')])
5 kx n.build('manual', 'phony',
5 kx order_only=manual)
5 kx n.newline()
5 kx
5 kx n.rule('dblatex',
5 kx command='dblatex -q -o $out -p doc/dblatex.xsl $in',
5 kx description='DBLATEX $out')
5 kx n.build(doc('manual.pdf'), 'dblatex', docbookxml,
5 kx implicit=[doc('dblatex.xsl')])
5 kx
5 kx n.comment('Generate Doxygen.')
5 kx n.rule('doxygen',
5 kx command='doxygen $in',
5 kx description='DOXYGEN $in')
5 kx n.variable('doxygen_mainpage_generator',
5 kx src('gen_doxygen_mainpage.sh'))
5 kx n.rule('doxygen_mainpage',
5 kx command='$doxygen_mainpage_generator $in > $out',
5 kx description='DOXYGEN_MAINPAGE $out')
5 kx mainpage = n.build(built('doxygen_mainpage'), 'doxygen_mainpage',
5 kx ['README.md', 'COPYING'],
5 kx implicit=['$doxygen_mainpage_generator'])
5 kx n.build('doxygen', 'doxygen', doc('doxygen.config'),
5 kx implicit=mainpage)
5 kx n.newline()
5 kx
5 kx if not host.is_mingw():
5 kx n.comment('Regenerate build files if build script changes.')
5 kx n.rule('configure',
5 kx command='${configure_env}%s $root/configure.py $configure_args' %
5 kx options.with_python,
5 kx generator=True)
5 kx n.build('build.ninja', 'configure',
5 kx implicit=['$root/configure.py',
5 kx os.path.normpath('$root/misc/ninja_syntax.py')])
5 kx n.newline()
5 kx
5 kx n.default(ninja)
5 kx n.newline()
5 kx
5 kx if host.is_linux():
5 kx n.comment('Packaging')
5 kx n.rule('rpmbuild',
5 kx command="misc/packaging/rpmbuild.sh",
5 kx description='Building rpms..')
5 kx n.build('rpm', 'rpmbuild')
5 kx n.newline()
5 kx
5 kx n.build('all', 'phony', all_targets)
5 kx
5 kx n.close()
5 kx print('wrote %s.' % BUILD_FILENAME)
5 kx
5 kx if options.bootstrap:
5 kx print('bootstrap complete. rebuilding...')
5 kx
5 kx rebuild_args = []
5 kx
5 kx if platform.can_rebuild_in_place():
5 kx rebuild_args.append('./ninja')
5 kx else:
5 kx if platform.is_windows():
5 kx bootstrap_exe = 'ninja.bootstrap.exe'
5 kx final_exe = 'ninja.exe'
5 kx else:
5 kx bootstrap_exe = './ninja.bootstrap'
5 kx final_exe = './ninja'
5 kx
5 kx if os.path.exists(bootstrap_exe):
5 kx os.unlink(bootstrap_exe)
5 kx os.rename(final_exe, bootstrap_exe)
5 kx
5 kx rebuild_args.append(bootstrap_exe)
5 kx
5 kx if options.verbose:
5 kx rebuild_args.append('-v')
5 kx
5 kx subprocess.check_call(rebuild_args)