2012-05-21 15:12:37 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2013-03-06 14:11:43 +04:00
|
|
|
|
2011-02-25 17:05:08 +03:00
|
|
|
'''Given a list of object files and library names, prints a library
|
|
|
|
descriptor to standard output'''
|
|
|
|
|
2013-03-06 14:11:43 +04:00
|
|
|
from __future__ import with_statement
|
2011-02-25 17:05:08 +03:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import expandlibs_config as conf
|
2012-06-11 03:44:50 +04:00
|
|
|
from expandlibs import LibDescriptor, isObject, ensureParentDir, ExpandLibsDeps
|
|
|
|
from optparse import OptionParser
|
2011-02-25 17:05:08 +03:00
|
|
|
|
|
|
|
def generate(args):
|
|
|
|
desc = LibDescriptor()
|
|
|
|
for arg in args:
|
2012-01-25 13:34:14 +04:00
|
|
|
if isObject(arg):
|
2012-04-06 12:16:25 +04:00
|
|
|
if os.path.exists(arg):
|
|
|
|
desc['OBJS'].append(os.path.abspath(arg))
|
|
|
|
else:
|
2013-03-06 14:11:43 +04:00
|
|
|
raise Exception("File not found: %s" % arg)
|
2012-04-06 12:16:25 +04:00
|
|
|
elif os.path.splitext(arg)[1] == conf.LIB_SUFFIX:
|
|
|
|
if os.path.exists(arg) or os.path.exists(arg + conf.LIBS_DESC_SUFFIX):
|
|
|
|
desc['LIBS'].append(os.path.abspath(arg))
|
|
|
|
else:
|
2013-03-06 14:11:43 +04:00
|
|
|
raise Exception("File not found: %s" % arg)
|
2011-02-25 17:05:08 +03:00
|
|
|
return desc
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-06-11 03:44:50 +04:00
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("--depend", dest="depend", metavar="FILE",
|
|
|
|
help="generate dependencies for the given execution and store it in the given file")
|
|
|
|
parser.add_option("-o", dest="output", metavar="FILE",
|
|
|
|
help="send output to the given file")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if not options.output:
|
|
|
|
raise Exception("Missing option: -o")
|
|
|
|
|
|
|
|
ensureParentDir(options.output)
|
|
|
|
with open(options.output, 'w') as outfile:
|
2013-03-06 14:11:43 +04:00
|
|
|
print >>outfile, generate(args)
|
2012-06-11 03:44:50 +04:00
|
|
|
if options.depend:
|
|
|
|
ensureParentDir(options.depend)
|
|
|
|
with open(options.depend, 'w') as depfile:
|
2013-04-10 02:10:25 +04:00
|
|
|
deps = ExpandLibsDeps(args)
|
|
|
|
depfile.write("%s : %s\n" % (options.output, ' '.join(deps)))
|
|
|
|
for dep in deps:
|
|
|
|
depfile.write("%s :\n" % dep)
|