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