Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 631 lines (551 sloc) 21.049 kB
f20e002 @martine Revert "Merge pull request #143 from cipriancraciun/patches/python2"
authored
1 #!/usr/bin/env python
d7bd4a2 @martine check in a script that generates build.ninja
authored
2 #
3 # Copyright 2001 Google Inc. All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """Script that generates the build.ninja for ninja itself.
18
19 Projects that use ninja themselves should either write a similar script
20 or use a meta-build system that supports Ninja output."""
21
f4b1133 @zchothia Python scripts: use built-in print function.
zchothia authored
22 from __future__ import print_function
23
f685c54 @martine make platform a command-line arg to configure
authored
24 from optparse import OptionParser
d7bd4a2 @martine check in a script that generates build.ninja
authored
25 import os
13dfea4 @nico Make auto-reconfiguring work if CFLAGS contains more than one flag.
nico authored
26 import pipes
dcd41dc @martine add a --bootstrap mode for configure.py
authored
27 import string
28 import subprocess
d7bd4a2 @martine check in a script that generates build.ninja
authored
29 import sys
30
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
31 sys.path.insert(0, 'misc')
9611c8a @rlarocque2 Update configure.py for ninja module rename
rlarocque2 authored
32 import ninja_syntax
d7bd4a2 @martine check in a script that generates build.ninja
authored
33
dcd41dc @martine add a --bootstrap mode for configure.py
authored
34
684bf38 @martine merge platform_helper into configure script
authored
35 class Platform(object):
36 """Represents a host/target platform and its specific build attributes."""
37 def __init__(self, platform):
38 self._platform = platform
39 if self._platform is not None:
40 return
41 self._platform = sys.platform
42 if self._platform.startswith('linux'):
43 self._platform = 'linux'
44 elif self._platform.startswith('freebsd'):
45 self._platform = 'freebsd'
46 elif self._platform.startswith('gnukfreebsd'):
47 self._platform = 'freebsd'
48 elif self._platform.startswith('openbsd'):
49 self._platform = 'openbsd'
50 elif self._platform.startswith('solaris') or self._platform == 'sunos5':
51 self._platform = 'solaris'
52 elif self._platform.startswith('mingw'):
53 self._platform = 'mingw'
54 elif self._platform.startswith('win'):
55 self._platform = 'msvc'
56 elif self._platform.startswith('bitrig'):
57 self._platform = 'bitrig'
58 elif self._platform.startswith('netbsd'):
59 self._platform = 'netbsd'
60
61 @staticmethod
62 def known_platforms():
63 return ['linux', 'darwin', 'freebsd', 'openbsd', 'solaris', 'sunos5',
64 'mingw', 'msvc', 'gnukfreebsd', 'bitrig', 'netbsd']
65
66 def platform(self):
67 return self._platform
68
69 def is_linux(self):
70 return self._platform == 'linux'
71
72 def is_mingw(self):
73 return self._platform == 'mingw'
74
75 def is_msvc(self):
76 return self._platform == 'msvc'
77
78 def msvc_needs_fs(self):
79 popen = subprocess.Popen(['cl', '/nologo', '/?'],
80 stdout=subprocess.PIPE,
81 stderr=subprocess.PIPE)
82 out, err = popen.communicate()
83 return '/FS ' in str(out)
84
85 def is_windows(self):
86 return self.is_mingw() or self.is_msvc()
87
88 def is_solaris(self):
89 return self._platform == 'solaris'
90
91 def uses_usr_local(self):
92 return self._platform in ('freebsd', 'openbsd', 'bitrig')
93
94 def supports_ppoll(self):
95 return self._platform in ('linux', 'openbsd', 'bitrig')
96
0bf1bd3 @nico Make browse detection consistent with other platform checks.
nico authored
97 def supports_ninja_browse(self):
13bd84f @nico Fix Windows build after #862. Thanks to @harig for the report.
nico authored
98 return not self.is_windows() and not self.is_solaris()
0bf1bd3 @nico Make browse detection consistent with other platform checks.
nico authored
99
684bf38 @martine merge platform_helper into configure script
authored
100
dcd41dc @martine add a --bootstrap mode for configure.py
authored
101 class Bootstrap:
102 """API shim for ninja_syntax.Writer that instead runs the commands.
103
104 Used to bootstrap Ninja from scratch. In --bootstrap mode this
105 class is used to execute all the commands to build an executable.
106 It also proxies all calls to an underlying ninja_syntax.Writer, to
107 behave like non-bootstrap mode.
108 """
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
109 def __init__(self, writer, verbose=False):
dcd41dc @martine add a --bootstrap mode for configure.py
authored
110 self.writer = writer
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
111 self.verbose = verbose
dcd41dc @martine add a --bootstrap mode for configure.py
authored
112 # Map of variable name => expanded variable value.
113 self.vars = {}
114 # Map of rule name => dict of rule attributes.
115 self.rules = {
116 'phony': {}
117 }
118
119 def comment(self, text):
120 return self.writer.comment(text)
121
122 def newline(self):
123 return self.writer.newline()
124
125 def variable(self, key, val):
126 self.vars[key] = self._expand(val)
127 return self.writer.variable(key, val)
128
129 def rule(self, name, **kwargs):
130 self.rules[name] = kwargs
131 return self.writer.rule(name, **kwargs)
132
133 def build(self, outputs, rule, inputs=None, **kwargs):
134 ruleattr = self.rules[rule]
135 cmd = ruleattr.get('command')
136 if cmd is None: # A phony rule, for example.
137 return
138
139 # Implement just enough of Ninja variable expansion etc. to
140 # make the bootstrap build work.
141 local_vars = {
142 'in': self._expand_paths(inputs),
143 'out': self._expand_paths(outputs)
144 }
145 for key, val in kwargs.get('variables', []):
146 local_vars[key] = ' '.join(ninja_syntax.as_list(val))
147
148 self._run_command(self._expand(cmd, local_vars))
149
150 return self.writer.build(outputs, rule, inputs, **kwargs)
151
152 def default(self, paths):
153 return self.writer.default(paths)
154
155 def _expand_paths(self, paths):
156 """Expand $vars in an array of paths, e.g. from a 'build' block."""
157 paths = ninja_syntax.as_list(paths)
158 return ' '.join(map(self._expand, paths))
159
160 def _expand(self, str, local_vars={}):
161 """Expand $vars in a string."""
162 return ninja_syntax.expand(str, self.vars, local_vars)
163
164 def _run_command(self, cmdline):
165 """Run a subcommand, quietly. Prints the full command on error."""
166 try:
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
167 if self.verbose:
168 print(cmdline)
dcd41dc @martine add a --bootstrap mode for configure.py
authored
169 subprocess.check_call(cmdline, shell=True)
475918a @nico Make configure.py work with Python. Fixes issue #877.
nico authored
170 except subprocess.CalledProcessError:
dcd41dc @martine add a --bootstrap mode for configure.py
authored
171 print('when running: ', cmdline)
172 raise
173
174
f685c54 @martine make platform a command-line arg to configure
authored
175 parser = OptionParser()
5d697b9 @martine make --profile take an argument to use either gmon or google-pprof
authored
176 profilers = ['gmon', 'pprof']
dcd41dc @martine add a --bootstrap mode for configure.py
authored
177 parser.add_option('--bootstrap', action='store_true',
178 help='bootstrap a ninja binary from nothing')
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
179 parser.add_option('--verbose', action='store_true',
180 help='enable verbose build')
f685c54 @martine make platform a command-line arg to configure
authored
181 parser.add_option('--platform',
3aa641e @nico Wrap to 79 colums. No functionality change.
nico authored
182 help='target platform (' +
684bf38 @martine merge platform_helper into configure script
authored
183 '/'.join(Platform.known_platforms()) + ')',
184 choices=Platform.known_platforms())
8ecbf84 @martine fix mingw cross-compile
authored
185 parser.add_option('--host',
3aa641e @nico Wrap to 79 colums. No functionality change.
nico authored
186 help='host platform (' +
684bf38 @martine merge platform_helper into configure script
authored
187 '/'.join(Platform.known_platforms()) + ')',
188 choices=Platform.known_platforms())
f506c49 @martine add a --debug option to configure
authored
189 parser.add_option('--debug', action='store_true',
3253f66 @martine clarify a flag in configure.py
authored
190 help='enable debugging extras',)
5d697b9 @martine make --profile take an argument to use either gmon or google-pprof
authored
191 parser.add_option('--profile', metavar='TYPE',
69fe05f @nicolasdespres Fix duplicated list of profilers.
nicolasdespres authored
192 choices=profilers,
5d697b9 @martine make --profile take an argument to use either gmon or google-pprof
authored
193 help='enable profiling (' + '/'.join(profilers) + ')',)
b2fe56c @nico Use a small, standalone testing framework instead of googletest.
nico authored
194 parser.add_option('--with-gtest', metavar='PATH', help='ignored')
121f36d @ehird Support non-standard Python executable names
ehird authored
195 parser.add_option('--with-python', metavar='EXE',
196 help='use EXE as the Python interpreter',
197 default=os.path.basename(sys.executable))
4db8e5d @tru Added bootstrap/configure option to force pselect
tru authored
198 parser.add_option('--force-pselect', action='store_true',
3aa641e @nico Wrap to 79 colums. No functionality change.
nico authored
199 help='ppoll() is used by default where available, '
200 'but some platforms may need to use pselect instead',)
f685c54 @martine make platform a command-line arg to configure
authored
201 (options, args) = parser.parse_args()
77e215d @martine warn on accidental args to configure
authored
202 if args:
f4b1133 @zchothia Python scripts: use built-in print function.
zchothia authored
203 print('ERROR: extra unparsed command-line arguments:', args)
77e215d @martine warn on accidental args to configure
authored
204 sys.exit(1)
f685c54 @martine make platform a command-line arg to configure
authored
205
684bf38 @martine merge platform_helper into configure script
authored
206 platform = Platform(options.platform)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
207 if options.host:
684bf38 @martine merge platform_helper into configure script
authored
208 host = Platform(options.host)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
209 else:
210 host = platform
4be3bce @martine generate mingw build files if requested
authored
211
3a48d10 @martine rename gen-build-file to configure
authored
212 BUILD_FILENAME = 'build.ninja'
dcd41dc @martine add a --bootstrap mode for configure.py
authored
213 ninja_writer = ninja_syntax.Writer(open(BUILD_FILENAME, 'w'))
214 n = ninja_writer
215
216 if options.bootstrap:
217 # Make the build directory.
218 try:
219 os.mkdir('build')
220 except OSError:
221 pass
222 # Wrap ninja_writer with the Bootstrapper, which also executes the
223 # commands.
224 print('bootstrapping ninja...')
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
225 n = Bootstrap(n, verbose=options.verbose)
dcd41dc @martine add a --bootstrap mode for configure.py
authored
226
d7bd4a2 @martine check in a script that generates build.ninja
authored
227 n.comment('This file is used to build ninja itself.')
228 n.comment('It is generated by ' + os.path.basename(__file__) + '.')
229 n.newline()
230
43c33d7 @martine require version 1.3 for building ninja itself
authored
231 n.variable('ninja_required_version', '1.3')
232 n.newline()
233
b41da21 @martine preserve configure.py params across re-runs
authored
234 n.comment('The arguments passed to configure.py, for rerunning it.')
dcd41dc @martine add a --bootstrap mode for configure.py
authored
235 configure_args = sys.argv[1:]
236 if '--bootstrap' in configure_args:
237 configure_args.remove('--bootstrap')
238 n.variable('configure_args', ' '.join(configure_args))
aeeb99e @nico Let configure.py remember its environment for rerunning.
nico authored
239 env_keys = set(['CXX', 'AR', 'CFLAGS', 'LDFLAGS'])
33098cf @nico Do not access os.environ directly.
nico authored
240 configure_env = dict((k, os.environ[k]) for k in os.environ if k in env_keys)
b4c27cb @nico Fix configure.py on windows, which does not permit a leading space.
nico authored
241 if configure_env:
13dfea4 @nico Make auto-reconfiguring work if CFLAGS contains more than one flag.
nico authored
242 config_str = ' '.join([k + '=' + pipes.quote(configure_env[k])
243 for k in configure_env])
b4c27cb @nico Fix configure.py on windows, which does not permit a leading space.
nico authored
244 n.variable('configure_env', config_str + '$ ')
f570d49 @martine more whitespace in build output
authored
245 n.newline()
b41da21 @martine preserve configure.py params across re-runs
authored
246
4544786 @nico Produce colored diagnostics when building ninja with clang.
nico authored
247 CXX = configure_env.get('CXX', 'g++')
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
248 objext = '.o'
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
249 if platform.is_msvc():
4544786 @nico Produce colored diagnostics when building ninja with clang.
nico authored
250 CXX = 'cl'
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
251 objext = '.obj'
252
d7bd4a2 @martine check in a script that generates build.ninja
authored
253 def src(filename):
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
254 return os.path.join('src', filename)
d7bd4a2 @martine check in a script that generates build.ninja
authored
255 def built(filename):
256 return os.path.join('$builddir', filename)
17a0335 @martine move various doc files out of top-level directory
authored
257 def doc(filename):
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
258 return os.path.join('doc', filename)
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
259 def cc(name, **kwargs):
260 return n.build(built(name + objext), 'cxx', src(name + '.c'), **kwargs)
d7bd4a2 @martine check in a script that generates build.ninja
authored
261 def cxx(name, **kwargs):
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
262 return n.build(built(name + objext), 'cxx', src(name + '.cc'), **kwargs)
9bf145d @martine inline gtest to simplify windows build
authored
263 def binary(name):
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
264 if platform.is_windows():
356f31a @martine create phony rules for all binaries
authored
265 exe = name + '.exe'
266 n.build(name, 'phony', exe)
267 return exe
9bf145d @martine inline gtest to simplify windows build
authored
268 return name
d7bd4a2 @martine check in a script that generates build.ninja
authored
269
270 n.variable('builddir', 'build')
4544786 @nico Produce colored diagnostics when building ninja with clang.
nico authored
271 n.variable('cxx', CXX)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
272 if platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
273 n.variable('ar', 'link')
274 else:
33098cf @nico Do not access os.environ directly.
nico authored
275 n.variable('ar', configure_env.get('AR', 'ar'))
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
276
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
277 if platform.is_msvc():
dcd41dc @martine add a --bootstrap mode for configure.py
authored
278 cflags = ['/showIncludes',
279 '/nologo', # Don't print startup banner.
0312371 @martine doc some cl.exe flags in the configure script
authored
280 '/Zi', # Create pdb with debug info.
281 '/W4', # Highest warning level.
282 '/WX', # Warnings as errors.
283 '/wd4530', '/wd4100', '/wd4706',
284 '/wd4512', '/wd4800', '/wd4702', '/wd4819',
c840cf6 @martine disable a new warning that popped up on Windows
authored
285 # Disable warnings about passing "this" during initialization.
286 '/wd4355',
d1e6a29 @berenm Fix compilation errors on Visual Studio 2015 (_MSC_VER 1900).
berenm authored
287 # Disable warnings about ignored typedef in DbgHelp.h
288 '/wd4091',
0312371 @martine doc some cl.exe flags in the configure script
authored
289 '/GR-', # Disable RTTI.
09775f0 @martine windows: fix integer truncation issues for helper binaries
authored
290 # Disable size_t -> int truncation warning.
291 # We never have strings or arrays larger than 2**31.
292 '/wd4267',
5359825 Add NOMINMAX macro to fix a compilation error on Win32
Petr Wolf authored
293 '/DNOMINMAX', '/D_CRT_SECURE_NO_WARNINGS',
238b561 @martine mingw: fix quoting of -DNINJA_PYTHON
authored
294 '/DNINJA_PYTHON="%s"' % options.with_python]
dcd41dc @martine add a --bootstrap mode for configure.py
authored
295 if options.bootstrap:
296 # In bootstrap mode, we have no ninja process to catch /showIncludes
297 # output.
298 cflags.remove('/showIncludes')
a90b279 @sgraham Fix compilation on VS2013
sgraham authored
299 if platform.msvc_needs_fs():
300 cflags.append('/FS')
25a3bb0 windows: always generate PDB
Scott Graham authored
301 ldflags = ['/DEBUG', '/libpath:$builddir']
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
302 if not options.debug:
25a3bb0 windows: always generate PDB
Scott Graham authored
303 cflags += ['/Ox', '/DNDEBUG', '/GL']
304 ldflags += ['/LTCG', '/OPT:REF', '/OPT:ICF']
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
305 else:
306 cflags = ['-g', '-Wall', '-Wextra',
307 '-Wno-deprecated',
308 '-Wno-unused-parameter',
28ef3b7 @martine drop rtti via -fno-rtti; we don't use it
authored
309 '-fno-rtti',
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
310 '-fno-exceptions',
311 '-fvisibility=hidden', '-pipe',
7c3b845 @jonforums Silence bothersome warning from -Wextra
jonforums authored
312 '-Wno-missing-field-initializers',
238b561 @martine mingw: fix quoting of -DNINJA_PYTHON
authored
313 '-DNINJA_PYTHON="%s"' % options.with_python]
dc759f9 @martine enable libstd++ debugging in debug mode
authored
314 if options.debug:
315 cflags += ['-D_GLIBCXX_DEBUG', '-D_GLIBCXX_DEBUG_PEDANTIC']
703dcff @martine fix --debug for glibc pedantic mode
authored
316 cflags.remove('-fno-rtti') # Needed for above pedanticness.
dc759f9 @martine enable libstd++ debugging in debug mode
authored
317 else:
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
318 cflags += ['-O2', '-DNDEBUG']
160af7d @kirbyfan64 Test for Clang by checking --version
kirbyfan64 authored
319 try:
00a061c @nico Make diagnostics colored with new gccs (4.9+) too.
nico authored
320 proc = subprocess.Popen(
321 [CXX, '-fdiagnostics-color', '-c', '-x', 'c++', '/dev/null'],
322 stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
51f06fa @nico Simplify. No behavior change.
nico authored
323 if proc.wait() == 0:
00a061c @nico Make diagnostics colored with new gccs (4.9+) too.
nico authored
324 cflags += ['-fdiagnostics-color']
160af7d @kirbyfan64 Test for Clang by checking --version
kirbyfan64 authored
325 except:
326 pass
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
327 if platform.is_mingw():
69d9473 @martine mingw: specify _WIN32_WINNT also in configure.py
authored
328 cflags += ['-D_WIN32_WINNT=0x0501']
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
329 ldflags = ['-L$builddir']
684bf38 @martine merge platform_helper into configure script
authored
330 if platform.uses_usr_local():
331 cflags.append('-I/usr/local/include')
332 ldflags.append('-L/usr/local/lib')
333
3285595 @martine allow --with-gtest flag to use unpacked gtest dir
authored
334 libs = []
757c74f @martine configure.py: windows updates
authored
335
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
336 if platform.is_mingw():
47b3541 @luislavena visibility=hidden should not be used for Windows
luislavena authored
337 cflags.remove('-fvisibility=hidden');
8ecbf84 @martine fix mingw cross-compile
authored
338 ldflags.append('-static')
fa62cd4 @nico Fix building on Solaris.
nico authored
339 elif platform.is_solaris():
7504ab4 @cmoore Fixes the build on OpenIndiana
cmoore authored
340 cflags.remove('-fvisibility=hidden')
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
341 elif platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
342 pass
4be3bce @martine generate mingw build files if requested
authored
343 else:
5d697b9 @martine make --profile take an argument to use either gmon or google-pprof
authored
344 if options.profile == 'gmon':
2bdf6b9 @martine add --profile configure flag
authored
345 cflags.append('-pg')
346 ldflags.append('-pg')
5d697b9 @martine make --profile take an argument to use either gmon or google-pprof
authored
347 elif options.profile == 'pprof':
c511483 @martine fix --profile=pprof on newer ubuntus
authored
348 cflags.append('-fno-omit-frame-pointer')
349 libs.extend(['-Wl,--no-as-needed', '-lprofiler'])
2f289b8 @martine windows: successfully link tests
authored
350
684bf38 @martine merge platform_helper into configure script
authored
351 if platform.supports_ppoll() and not options.force_pselect:
4db8e5d @tru Added bootstrap/configure option to force pselect
tru authored
352 cflags.append('-DUSE_PPOLL')
0bf1bd3 @nico Make browse detection consistent with other platform checks.
nico authored
353 if platform.supports_ninja_browse():
a39b957 @nico Make sure configure.py and ninja.cc always agree on if -t browse is i…
nico authored
354 cflags.append('-DNINJA_HAVE_BROWSE')
355
a08b8c8 @martine rearrange shell quoting in configure.py
authored
356 def shell_escape(str):
3249938 @martine wrap some overlong lines
authored
357 """Escape str such that it's interpreted as a single argument by
358 the shell."""
359
a08b8c8 @martine rearrange shell quoting in configure.py
authored
360 # This isn't complete, but it's just enough to make NINJA_PYTHON work.
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
361 if platform.is_windows():
9ef56fd @sgraham fix win32 compile, fix BuildLogTest.WriteRead on 2nd run
sgraham authored
362 return str
a08b8c8 @martine rearrange shell quoting in configure.py
authored
363 if '"' in str:
1a87142 @martine fix quoting thinko
authored
364 return "'%s'" % str.replace("'", "\\'")
a08b8c8 @martine rearrange shell quoting in configure.py
authored
365 return str
366
33098cf @nico Do not access os.environ directly.
nico authored
367 if 'CFLAGS' in configure_env:
368 cflags.append(configure_env['CFLAGS'])
a08b8c8 @martine rearrange shell quoting in configure.py
authored
369 n.variable('cflags', ' '.join(shell_escape(flag) for flag in cflags))
33098cf @nico Do not access os.environ directly.
nico authored
370 if 'LDFLAGS' in configure_env:
371 ldflags.append(configure_env['LDFLAGS'])
a08b8c8 @martine rearrange shell quoting in configure.py
authored
372 n.variable('ldflags', ' '.join(shell_escape(flag) for flag in ldflags))
d7bd4a2 @martine check in a script that generates build.ninja
authored
373 n.newline()
374
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
375 if platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
376 n.rule('cxx',
dcd41dc @martine add a --bootstrap mode for configure.py
authored
377 command='$cxx $cflags -c $in /Fo$out',
58c7139 @martine windows: drop use of msvc helper in build
authored
378 description='CXX $out',
dcd41dc @martine add a --bootstrap mode for configure.py
authored
379 deps='msvc' # /showIncludes is included in $cflags.
380 )
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
381 else:
382 n.rule('cxx',
83146da @usovalx Explicitly specify target name for gcc depfiles
usovalx authored
383 command='$cxx -MMD -MT $out -MF $out.d $cflags -c $in -o $out',
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
384 depfile='$out.d',
461fec2 @martine build ninja itself in deps mode
authored
385 deps='gcc',
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
386 description='CXX $out')
d7bd4a2 @martine check in a script that generates build.ninja
authored
387 n.newline()
388
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
389 if host.is_msvc():
757c74f @martine configure.py: windows updates
authored
390 n.rule('ar',
25a3bb0 windows: always generate PDB
Scott Graham authored
391 command='lib /nologo /ltcg /out:$out $in',
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
392 description='LIB $out')
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
393 elif host.is_mingw():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
394 n.rule('ar',
395 command='cmd /c $ar cqs $out.tmp $in && move /Y $out.tmp $out',
757c74f @martine configure.py: windows updates
authored
396 description='AR $out')
397 else:
398 n.rule('ar',
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
399 command='rm -f $out && $ar crs $out $in',
757c74f @martine configure.py: windows updates
authored
400 description='AR $out')
d7bd4a2 @martine check in a script that generates build.ninja
authored
401 n.newline()
402
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
403 if platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
404 n.rule('link',
405 command='$cxx $in $libs /nologo /link $ldflags /out:$out',
406 description='LINK $out')
407 else:
408 n.rule('link',
409 command='$cxx $ldflags -o $out $in $libs',
410 description='LINK $out')
d7bd4a2 @martine check in a script that generates build.ninja
authored
411 n.newline()
412
413 objs = []
414
0bf1bd3 @nico Make browse detection consistent with other platform checks.
nico authored
415 if platform.supports_ninja_browse():
4be3bce @martine generate mingw build files if requested
authored
416 n.comment('browse_py.h is used to inline browse.py.')
417 n.rule('inline',
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
418 command='src/inline.sh $varname < $in > $out',
4be3bce @martine generate mingw build files if requested
authored
419 description='INLINE $out')
420 n.build(built('browse_py.h'), 'inline', src('browse.py'),
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
421 implicit='src/inline.sh',
4be3bce @martine generate mingw build files if requested
authored
422 variables=[('varname', 'kBrowsePy')])
423 n.newline()
424
d838f8e @martine fix TODO: correct dependencies for inline.sh
authored
425 objs += cxx('browse', order_only=built('browse_py.h'))
4be3bce @martine generate mingw build files if requested
authored
426 n.newline()
d7bd4a2 @martine check in a script that generates build.ninja
authored
427
8a0c960 @martine switch the core ninja parser to use re2c for the lexer
authored
428 n.comment('the depfile parser and ninja lexers are generated using re2c.')
6c7fae2 @nico Only write re2c rules if a re2c binary is found in the PATH.
nico authored
429 def has_re2c():
0b531af @martine use 4 space tabs in configure.py, warn on re2c missing
authored
430 try:
547f959 @riannucci Fix re2c detection which breaks win32 w/ gnuwin32
riannucci authored
431 proc = subprocess.Popen(['re2c', '-V'], stdout=subprocess.PIPE)
432 return int(proc.communicate()[0], 10) >= 1103
0b531af @martine use 4 space tabs in configure.py, warn on re2c missing
authored
433 except OSError:
434 return False
6c7fae2 @nico Only write re2c rules if a re2c binary is found in the PATH.
nico authored
435 if has_re2c():
0b531af @martine use 4 space tabs in configure.py, warn on re2c missing
authored
436 n.rule('re2c',
437 command='re2c -b -i --no-generation-date -o $out $in',
438 description='RE2C $out')
439 # Generate the .cc files in the source directory so we can check them in.
440 n.build(src('depfile_parser.cc'), 're2c', src('depfile_parser.in.cc'))
441 n.build(src('lexer.cc'), 're2c', src('lexer.in.cc'))
6c7fae2 @nico Only write re2c rules if a re2c binary is found in the PATH.
nico authored
442 else:
f4b1133 @zchothia Python scripts: use built-in print function.
zchothia authored
443 print("warning: A compatible version of re2c (>= 0.11.3) was not found; "
547f959 @riannucci Fix re2c detection which breaks win32 w/ gnuwin32
riannucci authored
444 "changes to src/*.in.cc will not affect your build.")
bf72e45 @martine use re2c to parse depfiles
authored
445 n.newline()
446
d7bd4a2 @martine check in a script that generates build.ninja
authored
447 n.comment('Core source files all build into ninja library.')
bd39f01 @tfarina Put the list of core source files in alphabetical order.
tfarina authored
448 for name in ['build',
449 'build_log',
450 'clean',
cc89c1a @sgraham add -d keeprsp to preserve @rsp files on success on windows
sgraham authored
451 'debug_flags',
bd39f01 @tfarina Put the list of core source files in alphabetical order.
tfarina authored
452 'depfile_parser',
b6a9a1c @martine add DepsLog, a new data structure for dependency information
authored
453 'deps_log',
bd39f01 @tfarina Put the list of core source files in alphabetical order.
tfarina authored
454 'disk_interface',
455 'edit_distance',
456 'eval_env',
457 'graph',
458 'graphviz',
8a0c960 @martine switch the core ninja parser to use re2c for the lexer
authored
459 'lexer',
10d1c93 @nico move single-line printing to new class
nico authored
460 'line_printer',
3baedf1 @tfarina Rename parsers.* to manifest_parser.*
tfarina authored
461 'manifest_parser',
d5165ba @martine add a '-d stats' flag for detailed timings
authored
462 'metrics',
bd39f01 @tfarina Put the list of core source files in alphabetical order.
tfarina authored
463 'state',
10f3e17 @martine add syntax for checking versions
authored
464 'util',
465 'version']:
d7bd4a2 @martine check in a script that generates build.ninja
authored
466 objs += cxx(name)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
467 if platform.is_windows():
3b3e1c8 @jonforums Give MinGW builds MSVC build helper superpowers
jonforums authored
468 for name in ['subprocess-win32',
469 'includes_normalize-win32',
470 'msvc_helper-win32',
471 'msvc_helper_main-win32']:
472 objs += cxx(name)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
473 if platform.is_msvc():
bb6da9a @martine rearrange minidump patch to match ninja code style
authored
474 objs += cxx('minidump-win32')
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
475 objs += cc('getopt')
ce42df5 @martine windows: build win32 subprocess file on windows
authored
476 else:
f4b8c75 @martine rename subprocess.cc to reflex its posixness
authored
477 objs += cxx('subprocess-posix')
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
478 if platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
479 ninja_lib = n.build(built('ninja.lib'), 'ar', objs)
480 else:
481 ninja_lib = n.build(built('libninja.a'), 'ar', objs)
d7bd4a2 @martine check in a script that generates build.ninja
authored
482 n.newline()
483
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
484 if platform.is_msvc():
6d33806 windows: make bootstrap.py/configure.py work with MSVC
Scott Graham authored
485 libs.append('ninja.lib')
486 else:
487 libs.append('-lninja')
3285595 @martine allow --with-gtest flag to use unpacked gtest dir
authored
488
c6a0c1e @martine add an "all" target to build all binaries
authored
489 all_targets = []
490
d7bd4a2 @martine check in a script that generates build.ninja
authored
491 n.comment('Main executable is library plus main() function.')
492 objs = cxx('ninja')
9bf145d @martine inline gtest to simplify windows build
authored
493 ninja = n.build(binary('ninja'), 'link', objs, implicit=ninja_lib,
494 variables=[('libs', libs)])
939597f @martine add a test program for evaluating depfile parse speed
authored
495 n.newline()
c6a0c1e @martine add an "all" target to build all binaries
authored
496 all_targets += ninja
d7bd4a2 @martine check in a script that generates build.ninja
authored
497
dcd41dc @martine add a --bootstrap mode for configure.py
authored
498 if options.bootstrap:
499 # We've built the ninja binary. Don't run any more commands
500 # through the bootstrap executor, but continue writing the
501 # build.ninja file.
502 n = ninja_writer
503
d7bd4a2 @martine check in a script that generates build.ninja
authored
504 n.comment('Tests all build into ninja_test executable.')
3285595 @martine allow --with-gtest flag to use unpacked gtest dir
authored
505
9bf145d @martine inline gtest to simplify windows build
authored
506 objs = []
507
b39616b @tfarina Split ninja_test.cc into state_test.cc and disk_interface_test.cc
tfarina authored
508 for name in ['build_log_test',
509 'build_test',
510 'clean_test',
8b929cf @martine split out depfile parser tests into new file
authored
511 'depfile_parser_test',
b6a9a1c @martine add DepsLog, a new data structure for dependency information
authored
512 'deps_log_test',
b39616b @tfarina Split ninja_test.cc into state_test.cc and disk_interface_test.cc
tfarina authored
513 'disk_interface_test',
d0a3c5c @nico Add a EditDistance() function based on the one in llvm/lib/Support/St…
nico authored
514 'edit_distance_test',
b39616b @tfarina Split ninja_test.cc into state_test.cc and disk_interface_test.cc
tfarina authored
515 'graph_test',
8a0c960 @martine switch the core ninja parser to use re2c for the lexer
authored
516 'lexer_test',
3baedf1 @tfarina Rename parsers.* to manifest_parser.*
tfarina authored
517 'manifest_parser_test',
94f999b @nico Make gtest output more silent, ninja issue #528.
nico authored
518 'ninja_test',
b39616b @tfarina Split ninja_test.cc into state_test.cc and disk_interface_test.cc
tfarina authored
519 'state_test',
520 'subprocess_test',
521 'test',
522 'util_test']:
b2fe56c @nico Use a small, standalone testing framework instead of googletest.
nico authored
523 objs += cxx(name)
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
524 if platform.is_windows():
0af67f1 @sgraham add functions for normalizing win32 include paths
sgraham authored
525 for name in ['includes_normalize_test', 'msvc_helper_test']:
b2fe56c @nico Use a small, standalone testing framework instead of googletest.
nico authored
526 objs += cxx(name)
3285595 @martine allow --with-gtest flag to use unpacked gtest dir
authored
527
c6a0c1e @martine add an "all" target to build all binaries
authored
528 ninja_test = n.build(binary('ninja_test'), 'link', objs, implicit=ninja_lib,
9870d3b @nico Remove now-unused variable test_libs.
nico authored
529 variables=[('libs', libs)])
d7bd4a2 @martine check in a script that generates build.ninja
authored
530 n.newline()
c6a0c1e @martine add an "all" target to build all binaries
authored
531 all_targets += ninja_test
d7bd4a2 @martine check in a script that generates build.ninja
authored
532
b240b07 @nico Provide 'ninja_test' as alias for 'ninja_test.exe' on windows.
nico authored
533
39aac33 @mo Fix two spelling errors
mo authored
534 n.comment('Ancillary executables.')
1e9124b @nico Add a BuildLog loading perftest.
nico authored
535 objs = cxx('build_log_perftest')
d59e82c @nico Add a hash collision benchmark.
nico authored
536 all_targets += n.build(binary('build_log_perftest'), 'link', objs,
537 implicit=ninja_lib, variables=[('libs', libs)])
993566a @nico add canon_perftest
nico authored
538 objs = cxx('canon_perftest')
d59e82c @nico Add a hash collision benchmark.
nico authored
539 all_targets += n.build(binary('canon_perftest'), 'link', objs,
540 implicit=ninja_lib, variables=[('libs', libs)])
993803e @nico Add a simple manifest parsing perftest.
nico authored
541 objs = cxx('depfile_parser_perftest')
542 all_targets += n.build(binary('depfile_parser_perftest'), 'link', objs,
543 implicit=ninja_lib, variables=[('libs', libs)])
d59e82c @nico Add a hash collision benchmark.
nico authored
544 objs = cxx('hash_collision_bench')
545 all_targets += n.build(binary('hash_collision_bench'), 'link', objs,
546 implicit=ninja_lib, variables=[('libs', libs)])
993803e @nico Add a simple manifest parsing perftest.
nico authored
547 objs = cxx('manifest_parser_perftest')
548 all_targets += n.build(binary('manifest_parser_perftest'), 'link', objs,
549 implicit=ninja_lib, variables=[('libs', libs)])
939597f @martine add a test program for evaluating depfile parse speed
authored
550 n.newline()
551
d7bd4a2 @martine check in a script that generates build.ninja
authored
552 n.comment('Generate a graph using the "graph" tool.')
553 n.rule('gendot',
d442b1c @martine show all in graph
authored
554 command='./ninja -t graph all > $out')
d7bd4a2 @martine check in a script that generates build.ninja
authored
555 n.rule('gengraph',
556 command='dot -Tpng $in > $out')
557 dot = n.build(built('graph.dot'), 'gendot', ['ninja', 'build.ninja'])
558 n.build('graph.png', 'gengraph', dot)
559 n.newline()
560
561 n.comment('Generate the manual using asciidoc.')
562 n.rule('asciidoc',
d3c4cf1 @martine move from asciidoc html to asciidoc -> docbook -> html
authored
563 command='asciidoc -b docbook -d book -o $out $in',
564 description='ASCIIDOC $out')
565 n.rule('xsltproc',
566 command='xsltproc --nonet doc/docbook.xsl $in > $out',
567 description='XSLTPROC $out')
568 xml = n.build(built('manual.xml'), 'asciidoc', doc('manual.asciidoc'))
569 manual = n.build(doc('manual.html'), 'xsltproc', xml,
570 implicit=doc('style.css'))
d7bd4a2 @martine check in a script that generates build.ninja
authored
571 n.build('manual', 'phony',
17a0335 @martine move various doc files out of top-level directory
authored
572 order_only=manual)
d7bd4a2 @martine check in a script that generates build.ninja
authored
573 n.newline()
574
575 n.comment('Generate Doxygen.')
576 n.rule('doxygen',
577 command='doxygen $in',
578 description='DOXYGEN $in')
579 n.variable('doxygen_mainpage_generator',
17a0335 @martine move various doc files out of top-level directory
authored
580 src('gen_doxygen_mainpage.sh'))
d7bd4a2 @martine check in a script that generates build.ninja
authored
581 n.rule('doxygen_mainpage',
582 command='$doxygen_mainpage_generator $in > $out',
583 description='DOXYGEN_MAINPAGE $out')
584 mainpage = n.build(built('doxygen_mainpage'), 'doxygen_mainpage',
5fe8c13 @martine drop HACKING from doxygen
authored
585 ['README', 'COPYING'],
d7bd4a2 @martine check in a script that generates build.ninja
authored
586 implicit=['$doxygen_mainpage_generator'])
17a0335 @martine move various doc files out of top-level directory
authored
587 n.build('doxygen', 'doxygen', doc('doxygen.config'),
e00f0b1 @martine remove order-only hacks now that semantics changed
authored
588 implicit=mainpage)
d7bd4a2 @martine check in a script that generates build.ninja
authored
589 n.newline()
590
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
591 if not host.is_mingw():
757c74f @martine configure.py: windows updates
authored
592 n.comment('Regenerate build files if build script changes.')
593 n.rule('configure',
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
594 command='${configure_env}%s configure.py $configure_args' %
aeeb99e @nico Let configure.py remember its environment for rerunning.
nico authored
595 options.with_python,
757c74f @martine configure.py: windows updates
authored
596 generator=True)
597 n.build('build.ninja', 'configure',
4256ff4 @nico Revert "Bootstrap out of source"
nico authored
598 implicit=['configure.py', os.path.normpath('misc/ninja_syntax.py')])
757c74f @martine configure.py: windows updates
authored
599 n.newline()
46d1b2c @martine build only the main binary by default
authored
600
9bf145d @martine inline gtest to simplify windows build
authored
601 n.default(ninja)
c6a0c1e @martine add an "all" target to build all binaries
authored
602 n.newline()
603
4c552c2 @TheOneRing share platform support between configure/bootstrap
TheOneRing authored
604 if host.is_linux():
0cd552c packaging: added basic RPM building
Maxim Kalaev authored
605 n.comment('Packaging')
606 n.rule('rpmbuild',
1cdfae5 packaging: refactored rpm building
Maxim Kalaev authored
607 command="misc/packaging/rpmbuild.sh",
608 description='Building rpms..')
609 n.build('rpm', 'rpmbuild')
0cd552c packaging: added basic RPM building
Maxim Kalaev authored
610 n.newline()
611
c6a0c1e @martine add an "all" target to build all binaries
authored
612 n.build('all', 'phony', all_targets)
3a48d10 @martine rename gen-build-file to configure
authored
613
dcd41dc @martine add a --bootstrap mode for configure.py
authored
614 n.close()
f4b1133 @zchothia Python scripts: use built-in print function.
zchothia authored
615 print('wrote %s.' % BUILD_FILENAME)
dcd41dc @martine add a --bootstrap mode for configure.py
authored
616
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
617 verbose = ''
618 if options.verbose:
619 verbose = ' -v'
620
dcd41dc @martine add a --bootstrap mode for configure.py
authored
621 if options.bootstrap:
622 print('bootstrap complete. rebuilding...')
623 if platform.is_windows():
624 bootstrap_exe = 'ninja.bootstrap.exe'
625 if os.path.exists(bootstrap_exe):
626 os.unlink(bootstrap_exe)
627 os.rename('ninja.exe', bootstrap_exe)
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
628 subprocess.check_call('ninja.bootstrap.exe%s' % verbose, shell=True)
dcd41dc @martine add a --bootstrap mode for configure.py
authored
629 else:
54d8235 @mathstuf configure: add a verbose mode
mathstuf authored
630 subprocess.check_call('./ninja%s' % verbose, shell=True)
Something went wrong with that request. Please try again.