|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright 2011 Google Inc. All Rights Reserved. |
| 3 | +# |
| 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 |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 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. |
| 15 | + |
| 16 | +import re |
| 17 | +import sys |
| 18 | +import os |
| 19 | +import glob |
| 20 | +import errno |
| 21 | +import subprocess |
| 22 | + |
| 23 | +def run(*args, **kwargs): |
| 24 | + try: |
| 25 | + subprocess.check_call(*args, **kwargs) |
| 26 | + except subprocess.CalledProcessError, e: |
| 27 | + sys.exit(e.returncode) |
| 28 | + |
| 29 | +# Compute system-specific CFLAGS/LDFLAGS as used in both in the below |
| 30 | +# g++ call as well as in the later configure.py. |
| 31 | +cflags = os.environ.get('CFLAGS', '') |
| 32 | +ldflags = os.environ.get('LDFLAGS', '') |
| 33 | +if sys.platform.startswith('freebsd'): |
| 34 | + cflags += ' -I/usr/local/include' |
| 35 | + ldflags += ' -L/usr/local/lib' |
| 36 | + |
| 37 | +print 'Building ninja manually...' |
| 38 | + |
| 39 | +try: |
| 40 | + os.mkdir('build') |
| 41 | +except OSError, e: |
| 42 | + if e.errno != errno.EEXIST: |
| 43 | + raise |
| 44 | + |
| 45 | +with open('src/browse.py') as browse_py: |
| 46 | + with open('build/browse_py.h', 'w') as browse_py_h: |
| 47 | + run(['./src/inline.sh', 'kBrowsePy'], |
| 48 | + stdin=browse_py, stdout=browse_py_h) |
| 49 | + |
| 50 | +pattern = r'test\.cc$|\.in\.cc$' |
| 51 | + |
| 52 | +if sys.platform.startswith('win32'): |
| 53 | + pattern += r'|/browse\.cc$|/subprocess\.cc$' |
| 54 | +else: |
| 55 | + pattern += r'|-win32\.cc$' |
| 56 | + |
| 57 | +sources = [src for src in glob.glob('src/*.cc') if not re.search(pattern, src)] |
| 58 | + |
| 59 | +args = [os.environ.get('CXX', 'g++'), '-Wno-deprecated', |
| 60 | + '-DNINJA_PYTHON="' + sys.executable + '"'] |
| 61 | +args.extend(cflags.split()) |
| 62 | +args.extend(ldflags.split()) |
| 63 | +args.extend(['-o', 'ninja.bootstrap']) |
| 64 | +args.extend(sources) |
| 65 | +run(args) |
| 66 | + |
| 67 | +print 'Building ninja using itself...' |
| 68 | +run([sys.executable, 'configure.py'] + sys.argv[1:]) |
| 69 | +run(['./ninja.bootstrap']) |
| 70 | +os.unlink('ninja.bootstrap') |
| 71 | + |
| 72 | +print 'Done!' |
0 commit comments