blob: d29590826c945313b46069925a07a80078fd0ba5 [file] [log] [blame]
#!/usr/bin/python
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Native Client SDK with Bionic
"""
import argparse
import fnmatch
import os
import stat
import shutil
import StringIO
import sys
sys.path.append('tools')
import process
from bionic_dirs import *
from file_update import Mkdir, Rmdir, Symlink
from file_update import NeedsUpdate, UpdateFromTo, UpdateText
from make_tools import ConfigureProject, MakeProject
from replace import ReplaceArch, ReplaceText
CPU_TYPES = ['x86_64']
ARCH_TYPES = ['i686', 'x86_64']
def BuildPNaCl(options):
tc_args = ['python', 'toolchain_build_pnacl.py',
'--install', os.path.join(options.output, 'bionic_work')]
if options.no_cache:
tc_args += ['--no-use-cached-results', '--no-use-remote-cache']
print 'Building PNaCl: ' + ' '.join(tc_args)
process.Run(tc_args, cwd=TOOLCHAIN_BUILD_DIR, outfile=sys.stdout)
def BuildSCons(options):
scons_args = ['./scons', '--mode=nacl,dbg-linux', '-j20']
for arch in ['arm', 'x86_64', 'x86_32']:
platform = 'platform=' + arch
irt = 'scons-out/nacl_irt-%s/staging/irt_core.nexe' % arch.replace('_', '-')
bootstrap = 'nacl_helper_bootstrap'
print 'Building SCons: ' + arch
process.Run(scons_args + [platform, 'sel_ldr', irt, bootstrap],
cwd=NATIVE_CLIENT_DIR, outfile=sys.stdout)
def UpdateBionicToolchain():
print 'Updating Bionic Toolchain.'
COPY_FULL = [
'arm_bc-nacl', 'bin', 'docs',
'i686_bc-nacl', 'include', 'le32-nacl',
'share', 'target_lib_compiler',
'translator', 'x86_64_bc-nacl',
'FEATURE_VERSION', 'README', 'REV',
'lib',
'arm-nacl/bin',
'arm-nacl/lib/ldscripts',
'x86_64-nacl/bin',
'x86_64-nacl/lib/ldscripts'
]
BOGUS = [
'lib/clang/3.4/include',
'lib/clang/3.4/lib/arm_bc-nacl',
'lib/clang/3.4/lib/i686_bc-nacl',
'lib/clang/3.4/lib/le32-nacl',
'lib/clang/3.4/lib/x86_64-nacl',
]
srcpath = os.path.join(OUTPUT_ROOT, 'bionic_work')
dstpath = os.path.join(OUTPUT_ROOT, 'bionic_install')
for dirpath in COPY_FULL:
UpdateFromTo(os.path.join(srcpath, dirpath), os.path.join(dstpath, dirpath))
EMPTY = """/*
* This is a dummy linker script.
* libnacl.a, libcrt_common.a, crt0.o crt1.o crti.o and crtn.o are all
* empty. Instead all the work is done by crtbegin(S).o and crtend(S).o and
* the bionic libc. These are provided for compatability with the newlib
* toolchain binaries.
*/"""
EMPTY_FILES = ['crt0.o', 'crt1.o', 'crti.o', 'crtn.o',
'libnacl.a', 'libcrt_common.a', 'libpthread.a']
for arch in ARCH_TYPES:
# Create empty objects and libraries
libpath = ReplaceArch(os.path.join(dstpath, '$LIB'), arch)
for name in EMPTY_FILES:
UpdateText(os.path.join(libpath, name), EMPTY)
def MungeIRT(src, dst):
replace_map = {
'off_t': 'int64_t',
'native_client/src/untrusted/irt/' : '',
}
if not NeedsUpdate(src,dst):
return
print 'Munging IRT %s -> %s.' % (src,dst)
with open(src, 'r') as srcf:
text = srcf.read()
text = ReplaceText(text, [replace_map])
with open(dst, 'w') as dstf:
dstf.write(text)
def UpdateBionicHeaders():
BIONIC_PAIRS = [
('libc/arch-nacl/syscalls/irt_poll.h', '$INC/irt_poll.h'),
('libc/arch-nacl/syscalls/irt_socket.h', '$INC/irt_socket.h'),
('libc/include', '$INC'),
('libc/arch-nacl/syscalls/nacl_socket.h', '$INC/nacl_socket.h'),
('libc/arch-nacl/syscalls/nacl_stat.h', '$INC/nacl_stat.h'),
('libc/arch-pnacl/include/machine',
'$INC/machine'),
('libc/arch-$MACH/include/machine',
'$INC/machine'),
('libc/kernel/common', '$INC'),
('libc/kernel/arch-$CPU/asm', '$INC/asm'),
# Math Includes
('libm/include', '$INC'),
('libm/$MATH', '$INC'),
# Misc
('safe-iop/include', '$INC'),
('nacl/$INC', '$INC'),
]
for arch in CPU_TYPES:
install_path = os.path.join(OUTPUT_ROOT, 'bionic_install')
Mkdir(install_path)
for src, dst in BIONIC_PAIRS:
srcpath = ReplaceArch(os.path.join(BIONIC_SRC, src), arch)
dstpath = ReplaceArch(os.path.join(install_path, dst), arch)
UpdateFromTo(srcpath, dstpath, filters=['*.S', '*.inc'])
for name in ['irt.h', 'irt_dev.h']:
src = os.path.join(NATIVE_CLIENT_DIR, 'src', 'untrusted', 'irt', name)
dst = os.path.join(install_path, '$INC')
dst = ReplaceArch(dst, arch)
MungeIRT(src, os.path.join(dst, name))
def BuildLibGcc():
for arch in CPU_TYPES:
pass
def main(argv):
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'-v', '--verbose', dest='verbose',
default=False, action='store_true',
help='Produce more output.')
parser.add_argument(
'-c', '--clobber', dest='clobber',
default=False, action='store_true',
help='Clobber working directories before building.')
parser.add_argument(
'-p', '--rebuild-pnacl', dest='rebuild_pnacl',
default=False, action='store_true',
help='Rebuild pnacl step.')
parser.add_argument(
'-s', '--rebuild-scons', dest='rebuild_scons',
default=False, action='store_true',
help='Rebuild sel_ldr, irt, and bootstrap.')
parser.add_argument(
'-t', '--clobber-toolchain', dest='clobber_toolchain',
default=False, action='store_true',
help='Clobber toolchain directory.')
options, leftover_args = parser.parse_known_args(argv)
if options.clobber:
print 'Re-prep this checkout.'
process.Run(['python', 'prep.py', '-c'])
# No need to rebuild after we already built during prep
options.rebuild_pnacl = False
options.rebuild_scons = False
if options.rebuild_pnacl:
BuildPNaCl(options)
if options.rebuild_scons:
BuildSCons(options)
if options.clobber_toolchain:
Rmdir(os.path.join(OUTPUT_ROOT, 'bionic_install'))
UpdateBionicToolchain()
UpdateBionicHeaders()
for arch in ARCH_TYPES:
ConfigureProject(arch, 'libc')
for arch in ARCH_TYPES:
MakeProject(arch, 'libc', ['irt'])
if __name__ == '__main__':
sys.exit(main(sys.argv))