config/expandlibs_gen.py
author Matt Woodrow <mwoodrow@mozilla.com>
Wed, 07 Nov 2012 19:56:56 +1300
changeset 120458 8083f88251535741731f6485c77f895e09b5d78b
parent 101131 b7f3236f127b6f8d455efa6ad75f82a3a3c5f3d4
child 133841 8f83edc05fa4d458d82668a95853c907544d0b8d
permissions -rw-r--r--
Bug 808469 - Use gfxQuartzSurface for OMTC drawing on mac. r=cjones

# 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/.

'''Given a list of object files and library names, prints a library
descriptor to standard output'''

from __future__ import with_statement
import sys
import os
import expandlibs_config as conf
from expandlibs import LibDescriptor, isObject, ensureParentDir, ExpandLibsDeps
from optparse import OptionParser

def generate(args):
    desc = LibDescriptor()
    for arg in args:
        if isObject(arg):
            if os.path.exists(arg):
                desc['OBJS'].append(os.path.abspath(arg))
            else:
                raise Exception("File not found: %s" % arg)
        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:
                raise Exception("File not found: %s" % arg)
    return desc

if __name__ == '__main__':
    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:
        print >>outfile, generate(args)
    if options.depend:
        ensureParentDir(options.depend)
        with open(options.depend, 'w') as depfile:
            depfile.write("%s : %s\n" % (options.output, ' '.join(ExpandLibsDeps(args))))