2 # Copyright 2011 Google Inc. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from optparse import OptionParser
24 parser = OptionParser()
25 parser.add_option('--verbose', action='store_true',
26 help='enable verbose build',)
27 (options, conf_args) = parser.parse_args()
29 def run(*args, **kwargs):
31 subprocess.check_call(*args, **kwargs)
32 except subprocess.CalledProcessError, e:
33 sys.exit(e.returncode)
35 # Compute system-specific CFLAGS/LDFLAGS as used in both in the below
36 # g++ call as well as in the later configure.py.
37 cflags = os.environ.get('CFLAGS', '').split()
38 ldflags = os.environ.get('LDFLAGS', '').split()
39 if sys.platform.startswith('freebsd'):
40 cflags.append('-I/usr/local/include')
41 ldflags.append('-L/usr/local/lib')
43 print 'Building ninja manually...'
48 if e.errno != errno.EEXIST:
52 for src in glob.glob('src/*.cc'):
53 if src.endswith('test.cc') or src.endswith('.in.cc'):
56 filename = os.path.basename(src)
57 if filename == 'browse.cc': # Depends on generated header.
60 if sys.platform.startswith('win32'):
61 if filename == 'subprocess.cc':
64 if src.endswith('-win32.cc'):
69 if sys.platform.startswith('win32'):
70 sources.append('src/getopt.c')
72 vcdir = os.environ.get('VCINSTALLDIR')
74 args = [os.path.join(vcdir, 'bin', 'cl.exe'), '/nologo', '/EHsc', '/DNOMINMAX']
76 args = shlex.split(os.environ.get('CXX', 'g++'))
77 args.extend(['-Wno-deprecated',
78 '-DNINJA_PYTHON="' + sys.executable + '"',
82 binary = 'ninja.bootstrap'
83 if sys.platform.startswith('win32'):
84 binary = 'ninja.bootstrap.exe'
87 args.extend(['/link', '/out:' + binary])
89 args.extend(['-o', binary])
100 print 'Building ninja using itself...'
101 run([sys.executable, 'configure.py'] + conf_args)
102 run(['./' + binary] + verbose)