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 os.chdir(os.path.dirname(sys.argv[0]))
26 parser = OptionParser()
27 parser.add_option('--verbose', action='store_true',
28 help='enable verbose build',)
29 (options, conf_args) = parser.parse_args()
31 def run(*args, **kwargs):
32 returncode = subprocess.call(*args, **kwargs)
36 # Compute system-specific CFLAGS/LDFLAGS as used in both in the below
37 # g++ call as well as in the later configure.py.
38 cflags = os.environ.get('CFLAGS', '').split()
39 ldflags = os.environ.get('LDFLAGS', '').split()
40 if sys.platform.startswith('freebsd'):
41 cflags.append('-I/usr/local/include')
42 ldflags.append('-L/usr/local/lib')
44 print 'Building ninja manually...'
49 if e.errno != errno.EEXIST:
53 for src in glob.glob('src/*.cc'):
54 if src.endswith('test.cc') or src.endswith('.in.cc'):
57 filename = os.path.basename(src)
58 if filename == 'browse.cc': # Depends on generated header.
61 if sys.platform.startswith('win32'):
62 if filename == 'subprocess.cc':
65 if src.endswith('-win32.cc'):
70 if sys.platform.startswith('win32'):
71 sources.append('src/getopt.c')
73 vcdir = os.environ.get('VCINSTALLDIR')
75 args = [os.path.join(vcdir, 'bin', 'cl.exe'), '/nologo', '/EHsc', '/DNOMINMAX']
77 args = shlex.split(os.environ.get('CXX', 'g++'))
78 args.extend(['-Wno-deprecated',
79 '-DNINJA_PYTHON="' + sys.executable + '"',
83 binary = 'ninja.bootstrap'
84 if sys.platform.startswith('win32'):
85 binary = 'ninja.bootstrap.exe'
88 args.extend(['/link', '/out:' + binary])
90 args.extend(['-o', binary])
101 print 'Building ninja using itself...'
102 run([sys.executable, 'configure.py'] + conf_args)
103 run(['./' + binary] + verbose)