blob: 31c5efbd9b4c6863b1d7fd1bf2b27e0720c9d522 [file] [log] [blame]
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +00001#!/usr/bin/env python
2
3# Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4#
5# Use of this source code is governed by a BSD-style license
6# that can be found in the LICENSE file in the root of the source
7# tree. An additional intellectual property rights grant can be found
8# in the file PATENTS. All contributing project authors may
9# be found in the AUTHORS file in the root of the source tree.
10
11# Searches for libraries and/or object files on the specified path and
12# merges them into a single library.
13
14import subprocess
15import sys
16
17if __name__ == '__main__':
18 if len(sys.argv) != 3:
19 sys.stderr.write('Usage: ' + sys.argv[0] + ' <search_path> <output_lib>\n')
20 sys.exit(2)
21
22 search_path = sys.argv[1]
23 output_lib = sys.argv[2]
24
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000025 from subprocess import call, PIPE
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +000026 if sys.platform.startswith('linux'):
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000027 call(["rm -f " + output_lib], shell=True)
28 call(["rm -rf " + search_path + "/obj.target/*do_not_use*"], shell=True)
29 call(["ar crs " + output_lib + " $(find " + search_path +
andrew@webrtc.orge858d132011-12-20 22:07:48 +000030 "/obj.target -name *\.o)"], shell=True)
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000031 call(["ar crs " + output_lib + " $(find " + search_path +
andrew@webrtc.orge858d132011-12-20 22:07:48 +000032 "/obj/gen -name *\.o)"], shell=True)
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +000033
34 elif sys.platform == 'darwin':
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000035 call(["rm -f " + output_lib], shell=True)
36 call(["rm -f " + search_path + "/*do_not_use*"], shell=True)
37 call(["libtool -static -v -o " + output_lib + " " + search_path + "/*.a"],
38 shell=True)
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +000039
40 elif sys.platform == 'win32':
41 # We need to execute a batch file to set some environment variables for the
andrew@webrtc.orge858d132011-12-20 22:07:48 +000042 # lib command. VS 8 uses vsvars.bat and VS 9 uses vsvars32.bat. It's
43 # required that at least one of them is in the system PATH. We try both and
44 # suppress stderr and stdout to fail silently.
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000045 call(["vsvars.bat"], stderr=PIPE, stdout=PIPE, shell=True)
46 call(["vsvars32.bat"], stderr=PIPE, stdout=PIPE, shell=True)
47 call(["del " + output_lib], shell=True)
48 call(["del /F /S /Q " + search_path + "/lib/*do_not_use*"],
andrew@webrtc.orge858d132011-12-20 22:07:48 +000049 shell=True)
andrew@webrtc.orgf33dfa82012-01-20 01:32:16 +000050 call(["lib /OUT:" + output_lib + " " + search_path + "/lib/*.lib"],
51 shell=True)
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +000052
53 else:
54 sys.stderr.write('Platform not supported: %r\n\n' % sys.platform)
55 sys.exit(1)
56
andrew@webrtc.orge858d132011-12-20 22:07:48 +000057 sys.exit(0)
zakkhoyt@google.comd9e11b42011-09-01 00:54:32 +000058