|
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/. |
|
4 |
|
5 '''Given a list of object files and library names, prints a library |
|
6 descriptor to standard output''' |
|
7 |
|
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, ExpandLibsDeps |
|
13 from optparse import OptionParser |
|
14 |
|
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 |
|
29 |
|
30 if __name__ == '__main__': |
|
31 parser = OptionParser() |
|
32 parser.add_option("--depend", dest="depend", metavar="FILE", |
|
33 help="generate dependencies for the given execution and store it in the given file") |
|
34 parser.add_option("-o", dest="output", metavar="FILE", |
|
35 help="send output to the given file") |
|
36 |
|
37 (options, args) = parser.parse_args() |
|
38 if not options.output: |
|
39 raise Exception("Missing option: -o") |
|
40 |
|
41 ensureParentDir(options.output) |
|
42 with open(options.output, 'w') as outfile: |
|
43 print >>outfile, generate(args) |
|
44 if options.depend: |
|
45 ensureParentDir(options.depend) |
|
46 with open(options.depend, 'w') as depfile: |
|
47 deps = ExpandLibsDeps(args) |
|
48 depfile.write("%s : %s\n" % (options.output, ' '.join(deps))) |
|
49 for dep in deps: |
|
50 depfile.write("%s :\n" % dep) |