BUG_URL = 'http://gonacl.com/reportissue' GIT_BASE_URL = 'https://chromium.googlesource.com/native_client' TAR_XV = ['tar', '-x', '-v'] EXTRACT_STRIP_TGZ = TAR_XV + ['--gzip', '--strip-components=1', '-f'] EXTRACT_STRIP_TBZ2 = TAR_XV + ['--bzip2', '--strip-components=1', '-f'] CONFIGURE_CMD = ['sh', '%(src)s/configure'] MAKE_PARALLEL_CMD = ['make', '-j%(cores)s'] MAKE_CHECK_CMD = MAKE_PARALLEL_CMD + ['check'] MAKE_DESTDIR_CMD = ['make', 'DESTDIR=%(abs_output)s'] # This file gets installed by multiple packages' install steps, but it is # never useful when installed in isolation. So we remove it from the # installation directories before packaging up. REMOVE_INFO_DIR = command.Remove(os.path.join('%(output)s', 'share', 'info', 'dir')) CONFIGURE_HOST_ARCH = [] if sys.platform.startswith('linux'): cc = ['gcc'] cxx = ['g++', '-static-libstdc++'] if any(platform.machine().lower().startswith(machine) for machine in ['x86_64', 'amd64', 'x64', 'i686']): # We build the tools for x86-32 hosts so they will run on either x86-32 # or x86-64 hosts (with the right compatibility libraries installed). cc += ['-m32'] cxx += ['-m32'] CONFIGURE_HOST_ARCH += ['--build=i686-linux'] CONFIGURE_HOST_ARCH += [ 'CC=' + ' '.join(cc), 'CXX=' + ' '.join(cxx),
def TargetLibs(target): lib_deps = ['binutils_' + target, 'gcc_' + target] # We have to populate the newlib source tree with the "exported" form of # some headers from the native_client source tree. The newlib build # needs these to be in the expected place. By doing this in the # 'unpack_commands' stage, these files will be part of the input hash and # so we don't need to do anything else to keep track of when they might # have changed in the native_client source tree. newlib_sys_nacl = os.path.join('%(src)s', 'newlib', 'libc', 'sys', 'nacl') newlib_unpack = [command.RemoveDirectory(os.path.join(newlib_sys_nacl, dirname)) for dirname in ['bits', 'sys', 'machine']] newlib_unpack.append(command.Command([ 'python', os.path.join('%(top_srcdir)s', 'src', 'trusted', 'service_runtime', 'export_header.py'), os.path.join('%(top_srcdir)s', 'src', 'trusted', 'service_runtime', 'include'), newlib_sys_nacl, ])) def NewlibFile(subdir, name): return os.path.join('%(output)s', target + '-nacl', subdir, name) newlib_sysroot = '%(abs_newlib_' + target + ')s' newlib_tooldir = '%s/%s-nacl' % (newlib_sysroot, target) # See the comment at ConfigureTargetPrep, above. newlib_install_data = ' '.join(['STRIPPROG=%(cwd)s/strip_for_target', '%(abs_src)s/install-sh', '-c', '-s', '-m', '644']) libs = { 'newlib_' + target: { 'dependencies': lib_deps, 'git_url': GIT_BASE_URL + '/nacl-newlib.git', 'git_revision': GIT_REVISIONS['newlib'], 'unpack_commands': newlib_unpack, 'commands': ConfigureTargetPrep(target) + TargetCommands(target, [ CONFIGURE_CMD + CONFIGURE_HOST_TOOL + ConfigureTargetArgs(target) + [ '--disable-libgloss', '--enable-newlib-iconv', '--enable-newlib-io-long-long', '--enable-newlib-io-long-double', '--enable-newlib-io-c99-formats', '--enable-newlib-mb', 'CFLAGS=-O2', 'CFLAGS_FOR_TARGET=' + NewlibTargetCflags(target), 'INSTALL_DATA=' + newlib_install_data, ], MAKE_PARALLEL_CMD, MAKE_DESTDIR_CMD + ['install-strip'], ]) + [ command.Remove(NewlibFile('include', 'pthread.h')), command.Rename(NewlibFile('lib', 'libc.a'), NewlibFile('lib', 'libcrt_common.a')), command.WriteData(NewlibLibcScript(target), NewlibFile('lib', 'libc.a')), ] + InstallDocFiles('newlib', ['COPYING.NEWLIB']), }, 'gcc_libs_' + target: { 'dependencies': lib_deps + ['newlib_' + target] + HOST_GCC_LIBS_DEPS, 'git_url': GCC_GIT_URL, 'git_revision': GIT_REVISIONS['gcc'], # This actually builds the compiler again and uses that compiler # to build the target libraries. That's by far the easiest thing # to get going given the interdependencies of the target # libraries (especially libgcc) on the gcc subdirectory, and # building the compiler doesn't really take all that long in the # grand scheme of things. # TODO(mcgrathr): If upstream ever cleans up all their # interdependencies better, unpack the compiler, configure with # --disable-gcc, and just build all-target. 'commands': ConfigureTargetPrep(target) + [ ConfigureGccCommand(target, [ '--with-build-sysroot=' + newlib_sysroot, ]), GccCommand(target, MAKE_PARALLEL_CMD + [ 'build_tooldir=' + newlib_tooldir, 'all-target', ]), GccCommand(target, MAKE_DESTDIR_CMD + ['install-strip-target']), REMOVE_INFO_DIR, ], }, } return libs
def BitcodeLibs(host, bias_arch): def H(component_name): return Mangle(component_name, host) def B(component_name): return Mangle(component_name, bias_arch) def BcSubdir(subdir, bias_arch): if bias_arch == 'portable': return subdir else: return subdir + '-bc-' + bias_arch libs = { B('newlib'): { 'type': 'build', 'output_subdir': BcSubdir('usr', bias_arch), 'dependencies': ['newlib_src', H('llvm'), H('binutils_pnacl')], 'inputs': { 'driver': os.path.join(NACL_DIR, 'pnacl', 'driver') }, 'commands': CopyDriverForTargetLib(host) + [ command.SkipForIncrementalCommand( ['sh', '%(newlib_src)s/configure'] + TARGET_TOOLS + [ 'CFLAGS_FOR_TARGET=' + TargetBCLibCflags(bias_arch) + ' -allow-asm', '--disable-multilib', '--prefix=', '--disable-newlib-supplied-syscalls', '--disable-texinfo', '--disable-libgloss', '--enable-newlib-iconv', '--enable-newlib-iconv-from-encodings=' + 'UTF-8,UTF-16LE,UCS-4LE,UTF-16,UCS-4', '--enable-newlib-iconv-to-encodings=' + 'UTF-8,UTF-16LE,UCS-4LE,UTF-16,UCS-4', '--enable-newlib-io-long-long', '--enable-newlib-io-long-double', '--enable-newlib-io-c99-formats', '--enable-newlib-mb', '--target=le32-nacl' ]), command.Command(MakeCommand()), command.Command(['make', 'DESTDIR=%(abs_output)s', 'install']), command.CopyTree( command.path.join('%(output)s', 'le32-nacl', 'lib'), command.path.join('%(output)s', 'lib')), command.CopyTree( command.path.join('%(output)s', 'le32-nacl', 'include'), command.path.join('%(output)s', 'include')), command.RemoveDirectory( command.path.join('%(output)s', 'le32-nacl')), command.Mkdir(os.path.join('%(output)s', 'include', 'nacl')), # Copy nacl_random.h, used by libc++. It uses the IRT, so should # be safe to include in the toolchain. command.Copy( os.path.join('%(top_srcdir)s', 'src', 'untrusted', 'nacl', 'nacl_random.h'), os.path.join('%(output)s', 'include', 'nacl', 'nacl_random.h')), ], }, B('libcxx'): { 'type': 'build', 'output_subdir': BcSubdir('usr', bias_arch), 'dependencies': [ 'libcxx_src', 'libcxxabi_src', 'llvm_src', 'gcc_src', H('llvm'), H('binutils_pnacl'), B('newlib') ], 'inputs': { 'driver': os.path.join(NACL_DIR, 'pnacl', 'driver') }, 'commands': CopyDriverForTargetLib(host) + [ command.SkipForIncrementalCommand([ 'cmake', '-G', 'Unix Makefiles', '-DCMAKE_C_COMPILER_WORKS=1', '-DCMAKE_CXX_COMPILER_WORKS=1', '-DCMAKE_INSTALL_PREFIX=', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_C_COMPILER=' + PnaclTool('clang'), '-DCMAKE_CXX_COMPILER=' + PnaclTool('clang++'), '-DCMAKE_AR=' + PnaclTool('ar'), '-DCMAKE_NM=' + PnaclTool('nm'), '-DCMAKE_RANLIB=' + PnaclTool('ranlib'), '-DCMAKE_LD=' + PnaclTool('illegal'), '-DCMAKE_AS=' + PnaclTool('illegal'), '-DCMAKE_OBJDUMP=' + PnaclTool('illegal'), '-DCMAKE_C_FLAGS=-std=gnu11 ' + LibCxxCflags(bias_arch), '-DCMAKE_CXX_FLAGS=-std=gnu++11 ' + LibCxxCflags(bias_arch), '-DLIT_EXECUTABLE=' + command.path.join( '%(llvm_src)s', 'utils', 'lit', 'lit.py'), '-DLLVM_LIT_ARGS=--verbose --param shell_prefix="' + os.path.join(NACL_DIR, 'run.py') + '-arch env --retries=1" ' + '--param exe_suffix=".pexe" --param use_system_lib=true ' + '--param link_flags="-std=gnu++11 --pnacl-exceptions=sjlj"', '-DLIBCXX_ENABLE_CXX0X=0', '-DLIBCXX_ENABLE_SHARED=0', '-DLIBCXX_CXX_ABI=libcxxabi', '-DLIBCXX_LIBCXXABI_INCLUDE_PATHS=' + command.path.join( '%(abs_libcxxabi_src)s', 'include'), '%(libcxx_src)s' ]), command.Copy( os.path.join('%(gcc_src)s', 'gcc', 'unwind-generic.h'), os.path.join('include', 'unwind.h')), command.Command(MakeCommand() + ['VERBOSE=1']), command.Command([ 'make', 'DESTDIR=%(abs_output)s', 'VERBOSE=1', 'install' ]), ], }, B('libstdcxx'): { 'type': 'build', 'output_subdir': BcSubdir('usr', bias_arch), 'dependencies': [ 'gcc_src', 'gcc_src', H('llvm'), H('binutils_pnacl'), B('newlib') ], 'inputs': { 'driver': os.path.join(NACL_DIR, 'pnacl', 'driver') }, 'commands': CopyDriverForTargetLib(host) + [ command.SkipForIncrementalCommand([ 'sh', command.path.join('%(gcc_src)s', 'libstdc++-v3', 'configure') ] + TARGET_TOOLS + [ 'CC_FOR_BUILD=cc', 'CC=' + PnaclTool('clang'), 'CXX=' + PnaclTool('clang++'), 'AR=' + PnaclTool('ar'), 'NM=' + PnaclTool('nm'), 'RAW_CXX_FOR_TARGET=' + PnaclTool('clang++'), 'LD=' + PnaclTool('illegal'), 'RANLIB=' + PnaclTool('ranlib'), 'CFLAGS=' + LibStdcxxCflags(bias_arch), 'CXXFLAGS=' + LibStdcxxCflags(bias_arch), 'CPPFLAGS=' + NewlibIsystemCflags(bias_arch), 'CFLAGS_FOR_TARGET=' + LibStdcxxCflags(bias_arch), 'CXXFLAGS_FOR_TARGET=' + LibStdcxxCflags(bias_arch), '--host=armv7-none-linux-gnueabi', '--prefix=', '--enable-cxx-flags=-D__SIZE_MAX__=4294967295', '--disable-multilib', '--disable-linux-futex', '--disable-libstdcxx-time', '--disable-sjlj-exceptions', '--disable-libstdcxx-pch', '--with-newlib', '--disable-shared', '--disable-rpath' ]), command.Copy( os.path.join('%(gcc_src)s', 'gcc', 'unwind-generic.h'), os.path.join('include', 'unwind.h')), command.Command(MakeCommand()), command.Command( ['make', 'DESTDIR=%(abs_output)s', 'install-data']), command.RemoveDirectory(os.path.join('%(output)s', 'share')), command.Remove( os.path.join('%(output)s', 'lib', 'libstdc++*-gdb.py')), command.Copy(os.path.join('src', '.libs', 'libstdc++.a'), os.path.join('%(output)s', 'lib', 'libstdc++.a')), ], }, B('libs_support_bitcode'): { 'type': 'build', 'output_subdir': BcSubdir('lib', bias_arch), 'dependencies': [B('newlib'), H('llvm'), H('binutils_pnacl')], 'inputs': { 'src': os.path.join(NACL_DIR, 'pnacl', 'support', 'bitcode'), 'driver': os.path.join(NACL_DIR, 'pnacl', 'driver') }, 'commands': CopyDriverForTargetLib(host) + [ # Two versions of crt1.x exist, for different scenarios (with and # without EH). See: # https://code.google.com/p/nativeclient/issues/detail?id=3069 command.Copy(command.path.join('%(src)s', 'crt1.x'), command.path.join('%(output)s', 'crt1.x')), command.Copy(command.path.join('%(src)s', 'crt1_for_eh.x'), command.path.join('%(output)s', 'crt1_for_eh.x')), # Install crti.bc (empty _init/_fini) BuildTargetBitcodeCmd('crti.c', 'crti.bc', bias_arch), # Install crtbegin bitcode (__cxa_finalize for C++) BuildTargetBitcodeCmd('crtbegin.c', 'crtbegin.bc', bias_arch), # Stubs for _Unwind_* functions when libgcc_eh is not included in # the native link). BuildTargetBitcodeCmd('unwind_stubs.c', 'unwind_stubs.bc', bias_arch), BuildTargetBitcodeCmd('sjlj_eh_redirect.c', 'sjlj_eh_redirect.bc', bias_arch), # libpnaclmm.a (__atomic_* library functions). BuildTargetBitcodeCmd('pnaclmm.c', 'pnaclmm.bc', bias_arch), command.Command([ PnaclTool('ar'), 'rc', command.path.join('%(output)s', 'libpnaclmm.a'), command.path.join('%(output)s', 'pnaclmm.bc') ]), ], }, } return libs