1#!/usr/bin/env python 2 3# Copyright (c) 2012 The Chromium Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6# 7# This script takes libcmt.lib for VS2005/08/10/12/13 and removes the allocation 8# related functions from it. 9# 10# Usage: prep_libc.py <VCLibDir> <OutputDir> <arch> 11# 12# VCLibDir is the path where VC is installed, something like: 13# C:\Program Files\Microsoft Visual Studio 8\VC\lib 14# OutputDir is the directory where the modified libcmt file should be stored. 15# arch is either 'ia32' or 'x64' 16 17import os 18import shutil 19import subprocess 20import sys 21 22def run(command, filter=None): 23 """Run |command|, removing any lines that match |filter|. The filter is 24 to remove the echoing of input filename that 'lib' does.""" 25 popen = subprocess.Popen( 26 command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 27 out, _ = popen.communicate() 28 for line in out.splitlines(): 29 if filter and line.strip() != filter: 30 print line 31 return popen.returncode 32 33def main(): 34 bindir = 'SELF_X86' 35 objdir = 'INTEL' 36 vs_install_dir = sys.argv[1] 37 outdir = sys.argv[2] 38 if "x64" in sys.argv[3]: 39 bindir = 'SELF_64_amd64' 40 objdir = 'amd64' 41 vs_install_dir = os.path.join(vs_install_dir, 'amd64') 42 output_lib = os.path.join(outdir, 'libcmt.lib') 43 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.lib'), output_lib) 44 shutil.copyfile(os.path.join(vs_install_dir, 'libcmt.pdb'), 45 os.path.join(outdir, 'libcmt.pdb')) 46 47 vspaths = [ 48 'build\\intel\\mt_obj\\', 49 'f:\\dd\\vctools\\crt_bld\\' + bindir + \ 50 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\', 51 'F:\\dd\\vctools\\crt_bld\\' + bindir + \ 52 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\nativec\\\\', 53 'F:\\dd\\vctools\\crt_bld\\' + bindir + \ 54 '\\crt\\src\\build\\' + objdir + '\\mt_obj\\nativecpp\\\\', 55 'f:\\binaries\\Intermediate\\vctools\\crt_bld\\' + bindir + \ 56 '\\crt\\prebuild\\build\\INTEL\\mt_obj\\cpp_obj\\\\', 57 ] 58 59 objfiles = ['malloc', 'free', 'realloc', 'new', 'delete', 'new2', 'delete2', 60 'align', 'msize', 'heapinit', 'expand', 'heapchk', 'heapwalk', 61 'heapmin', 'sbheap', 'calloc', 'recalloc', 'calloc_impl', 62 'new_mode', 'newopnt', 'newaopnt'] 63 for obj in objfiles: 64 for vspath in vspaths: 65 cmd = ('lib /nologo /ignore:4006,4014,4221 /remove:%s%s.obj %s' % 66 (vspath, obj, output_lib)) 67 run(cmd, obj + '.obj') 68 69if __name__ == "__main__": 70 sys.exit(main()) 71