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(os.path.abspath(__file__)))
26 parser = OptionParser()
27 parser.add_option('--verbose', action='store_true',
28 help='enable verbose build',)
29 parser.add_option('--x64', action='store_true',
30 help='force 64-bit build (Windows)',)
31 (options, conf_args) = parser.parse_args()
33 def run(*args, **kwargs):
34 returncode = subprocess.call(*args, **kwargs)
38 # Compute system-specific CFLAGS/LDFLAGS as used in both in the below
39 # g++ call as well as in the later configure.py.
40 cflags = os.environ.get('CFLAGS', '').split()
41 ldflags = os.environ.get('LDFLAGS', '').split()
42 if sys.platform.startswith('freebsd'):
43 cflags.append('-I/usr/local/include')
44 ldflags.append('-L/usr/local/lib')
46 print 'Building ninja manually...'
51 if e.errno != errno.EEXIST:
55 for src in glob.glob('src/*.cc'):
56 if src.endswith('test.cc') or src.endswith('.in.cc'):
58 if src.endswith('bench.cc'):
61 filename = os.path.basename(src)
62 if filename == 'browse.cc': # Depends on generated header.
65 if sys.platform.startswith('win32'):
66 if src.endswith('-posix.cc'):
69 if src.endswith('-win32.cc'):
74 if sys.platform.startswith('win32'):
75 sources.append('src/getopt.c')
77 vcdir = os.environ.get('VCINSTALLDIR')
80 cl = [os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')]
82 cl = [os.path.join(vcdir, 'bin', 'cl.exe')]
83 args = cl + ['/nologo', '/EHsc', '/DNOMINMAX']
85 args = shlex.split(os.environ.get('CXX', 'g++'))
86 cflags.extend(['-Wno-deprecated',
87 '-DNINJA_PYTHON="' + sys.executable + '"',
89 if sys.platform.startswith('win32'):
90 cflags.append('-D_WIN32_WINNT=0x0501')
95 binary = 'ninja.bootstrap'
96 if sys.platform.startswith('win32'):
97 binary = 'ninja.bootstrap.exe'
100 args.extend(['/link', '/out:' + binary])
102 args.extend(['-o', binary])
113 print 'Building ninja using itself...'
114 run([sys.executable, 'configure.py'] + conf_args)
115 run(['./' + binary] + verbose)
118 if sys.platform.startswith('win32'):
119 for obj in glob.glob('*.obj'):