Merge mozilla-b2g34 to 2.1s. a=merge
[gecko.git] / config / expandlibs_gen.py
blobb1de63cd02b8b50d28726d75ef76ce9ab47e347d
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 '''Given a list of object files and library names, prints a library
6 descriptor to standard output'''
8 from __future__ import with_statement
9 import sys
10 import os
11 import expandlibs_config as conf
12 from expandlibs import LibDescriptor, isObject, ensureParentDir
13 from optparse import OptionParser
15 def generate(args):
16 desc = LibDescriptor()
17 for arg in args:
18 if isObject(arg):
19 if os.path.exists(arg):
20 desc['OBJS'].append(os.path.abspath(arg))
21 else:
22 raise Exception("File not found: %s" % arg)
23 elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
24 if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
25 desc['LIBS'].append(os.path.abspath(arg))
26 else:
27 raise Exception("File not found: %s" % arg)
28 return desc
30 if __name__ == '__main__':
31 parser = OptionParser()
32 parser.add_option("-o", dest="output", metavar="FILE",
33 help="send output to the given file")
35 (options, args) = parser.parse_args()
36 if not options.output:
37 raise Exception("Missing option: -o")
39 ensureParentDir(options.output)
40 with open(options.output, 'w') as outfile:
41 print >>outfile, generate(args)