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
25 os.chdir(os.path.dirname(os.path.abspath(__file__)))
27 parser = OptionParser()
28 parser.add_option('--verbose', action='store_true',
29 help='enable verbose build',)
30 parser.add_option('--x64', action='store_true',
31 help='force 64-bit build (Windows)',)
32 (options, conf_args) = parser.parse_args()
34 def run(*args, **kwargs):
35 returncode = subprocess.call(*args, **kwargs)
39 # Compute system-specific CFLAGS/LDFLAGS as used in both in the below
40 # g++ call as well as in the later configure.py.
41 cflags = os.environ.get('CFLAGS', '').split()
42 ldflags = os.environ.get('LDFLAGS', '').split()
43 if sys.platform.startswith('freebsd'):
44 cflags.append('-I/usr/local/include')
45 ldflags.append('-L/usr/local/lib')
47 print 'Building ninja manually...'
52 if e.errno != errno.EEXIST:
56 for src in glob.glob('src/*.cc'):
57 if src.endswith('test.cc') or src.endswith('.in.cc'):
59 if src.endswith('bench.cc'):
62 filename = os.path.basename(src)
63 if filename == 'browse.cc': # Depends on generated header.
66 if sys.platform.startswith('win32'):
67 if src.endswith('-posix.cc'):
70 if src.endswith('-win32.cc'):
75 if sys.platform.startswith('win32'):
76 sources.append('src/getopt.c')
78 vcdir = os.environ.get('VCINSTALLDIR')
81 cl = [os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')]
83 cl = [os.path.join(vcdir, 'bin', 'cl.exe')]
84 args = cl + ['/nologo', '/EHsc', '/DNOMINMAX']
86 args = shlex.split(os.environ.get('CXX', 'g++'))
87 cflags.extend(['-Wno-deprecated',
88 '-DNINJA_PYTHON="' + sys.executable + '"',
90 if sys.platform.startswith('win32'):
91 cflags.append('-D_WIN32_WINNT=0x0501')
96 binary = 'ninja.bootstrap'
97 if sys.platform.startswith('win32'):
98 binary = 'ninja.bootstrap.exe'
101 args.extend(['/link', '/out:' + binary])
103 args.extend(['-o', binary])
114 if sys.platform.startswith('win32'):
115 print 'Building ninja using itself...'
116 run([sys.executable, 'configure.py', '--with-ninja=%s' % binary] +
118 run(['./' + binary] + verbose)
120 # Copy the new executable over the bootstrap one.
121 shutil.copyfile('ninja.exe', binary)
124 for obj in glob.glob('*.obj'):
130 Note: to work around Windows file locking, where you can't rebuild an
131 in-use binary, to run ninja after making any changes to build ninja itself
132 you should run ninja.bootstrap instead. Your build is also configured to
133 use ninja.bootstrap.exe as the MSVC helper; see the --with-ninja flag of
134 the --help output of configure.py."""
136 print 'Building ninja using itself...'
137 run([sys.executable, 'configure.py'] + conf_args)
138 run(['./' + binary] + verbose)