7from __future__
import print_function
16 print(
'Usage: merge_static_libs OUTPUT_LIB INPUT_LIB [INPUT_LIB]*')
21 """ Merges multiple static libraries into one.
23 in_libs: list of paths to static libraries to be merged
24 out_lib: path to the static library which will be created from in_libs
26 if os.name ==
'posix':
27 tempdir = tempfile.mkdtemp()
29 for in_lib
in in_libs:
30 abs_in_libs.append(os.path.abspath(in_lib))
34 ar = os.environ.get(
'AR',
'ar')
35 for in_lib
in abs_in_libs:
36 proc = subprocess.Popen([ar,
'-t', in_lib], stdout=subprocess.PIPE)
38 obj_str = proc.communicate()[0]
39 current_objects = obj_str.rstrip().split(
'\n')
40 proc = subprocess.Popen([ar,
'-x', in_lib], stdout=subprocess.PIPE,
41 stderr=subprocess.STDOUT)
45 for obj
in current_objects:
46 objects.append(os.path.abspath(obj))
47 elif 'thin archive' in proc.communicate()[0]:
49 for obj
in current_objects:
52 raise Exception(
'Failed to extract objects from %s.' % in_lib)
54 if not subprocess.call([ar,
'-crs', out_lib] + objects) == 0:
55 raise Exception(
'Failed to add object files to %s' % out_lib)
56 shutil.rmtree(tempdir)
58 subprocess.call([
'lib',
'/OUT:%s' % out_lib] + in_libs)
60 raise Exception(
'Error: Your platform is not supported')
67 in_libs = sys.argv[2:]
71if '__main__' == __name__:
def print(*args, **kwargs)