| #!/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. |
| |
| """Tools for using Make to build bionic projects such as libc |
| """ |
| |
| import process |
| import sys |
| |
| from bionic_dirs import * |
| from file_update import Mkdir, Rmdir, Symlink, UpdateText |
| from replace import ReplaceArch, ReplaceText |
| |
| |
| def GetProjectPaths(out_dir, arch, project): |
| srcpath = os.path.join(BIONIC_SRC, project) |
| workpath = os.path.join(out_dir, 'bionic_$GCC_work') |
| toolpath = os.path.join(out_dir, 'bionic_install') |
| clangpath = os.path.join(toolpath, 'lib', 'clang', '3.4', 'lib') |
| |
| workpath = ReplaceArch(os.path.join(workpath, project), arch) |
| instpath = ReplaceArch(os.path.join(toolpath, '$LIB'), arch) |
| gccpath = ReplaceArch(os.path.join(clangpath, '$GCC-nacl'), arch) |
| out = { |
| 'bionic': BIONIC_SRC, |
| 'src': srcpath, |
| 'work': workpath, |
| 'ins': instpath, |
| 'gcc': gccpath, |
| 'tc': toolpath, |
| } |
| return out |
| |
| |
| def ConfigureProject(arch, project, clobber=False): |
| paths = GetProjectPaths(OUTPUT_ROOT, arch, project) |
| |
| MAKEFILE_TEMPLATE = """ |
| # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # GNU Makefile based on shared rules provided by the Native Client SDK. |
| # See README.Makefiles for more details. |
| |
| NATIVE_CLIENT_PATH?=$(nacl_path) |
| TOOLCHAIN_PATH?=$(tc_path) |
| TOOLCHAIN_PREFIX:=$(TOOLCHAIN_PATH)/bin/$NACL- |
| |
| CC:=$(TOOLCHAIN_PREFIX)clang |
| CXX:=$(TOOLCHAIN_PREFIX)clang++ |
| AR:=$(TOOLCHAIN_PREFIX)ar |
| LD:=$(TOOLCHAIN_PREFIX)clang++ |
| |
| SRC_ROOT=$(src_path) |
| DST_ROOT=$(dst_path) |
| INS_ROOT=$(ins_path) |
| GCC_ROOT=$(gcc_path) |
| |
| NACL_ARCH=$NACL |
| GCC_ARCH=$GCC |
| |
| MAKEFILE_DEPS:=$(bionic_path)/tc_bionic.mk |
| MAKEFILE_DEPS+=$(src_path)/Makefile |
| |
| include $(bionic_path)/tc_bionic.mk |
| include $(src_path)/Makefile |
| """ |
| remap = { |
| '$(src_path)': paths['src'], |
| '$(dst_path)': paths['work'], |
| '$(gcc_path)': paths['gcc'], |
| '$(ins_path)': paths['ins'], |
| '$(tc_path)': paths['tc'], |
| '$(bionic_path)': paths['bionic'], |
| '$(build_tc_path)': TOOLCHAIN_BUILD_DIR, |
| '$(nacl_path)': NATIVE_CLIENT_DIR, |
| } |
| text = ReplaceText(MAKEFILE_TEMPLATE, [remap]) |
| text = ReplaceArch(text, arch) |
| |
| if clobber: |
| print 'Clobbering Bionic project directory: ' + paths['work'] |
| Rmdir(paths['work']) |
| |
| Mkdir(paths['work']) |
| Mkdir(paths['ins']) |
| UpdateText(os.path.join(paths['work'], 'Makefile'), text) |
| |
| |
| def MakeProject(arch, project, targets=None, clobber=False): |
| paths = GetProjectPaths(OUTPUT_ROOT, arch, project) |
| workpath = paths['work'] |
| targets = targets or [] |
| targetlist = ' '.join(targets) |
| print 'Building %s for %s at %s %s.' % (project, arch, workpath, targetlist) |
| if clobber: |
| args = ['make', '-j12', 'V=1', 'clean'] |
| if process.Run(args, cwd=workpath, outfile=sys.stdout): |
| raise RuntimeError('Failed to clean %s for %s.\n' % (project, arch)) |
| |
| args = ['make', '-j12', 'V=1'] + targets |
| if process.Run(args, cwd=workpath, outfile=sys.stdout): |
| print "Building at: " + workpath |
| args = ['make', '-j1', 'V=1'] + targets |
| process.Run(args, cwd=workpath, outfile=sys.stdout) |
| raise RuntimeError('Failed to build %s for %s.\n' % (project, arch)) |
| print 'Done with %s for %s.\n' % (project, arch) |
| |