diff options
author | Daniel Dunbar <daniel@zuster.org> | 2011-11-03 22:46:19 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2011-11-03 22:46:19 +0000 |
commit | 02271a7b42ab658115c19d5041eaed2001b9537c (patch) | |
tree | 6f08e2c6605dbe2488a0980e39bba11d4cfd3e18 /utils/llvm-build | |
parent | 65fd6564b8aedd053845c81ede1ac594acb470e4 (diff) |
llvm-build: Add initial code for --write-make-fragment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143661 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/llvm-build')
-rw-r--r-- | utils/llvm-build/llvmbuild/main.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py index f52b2b1e24..063dadc8f7 100644 --- a/utils/llvm-build/llvmbuild/main.py +++ b/utils/llvm-build/llvmbuild/main.py @@ -286,6 +286,94 @@ class LLVMProjectInfo(object): print >>f, '};' f.close() + def write_make_fragment(self, output_path): + """ + write_make_fragment(output_path) -> None + + Generate a Makefile fragment which includes all of the collated + LLVMBuild information in a format that is easily digestible by a + Makefile. The exact contents of this are closely tied to how the LLVM + Makefiles integrate LLVMBuild, see Makefile.rules in the top-level. + """ + + # Construct a list of all the dependencies of the Makefile fragment + # itself. These include all the LLVMBuild files themselves, as well as + # all of our own sources. + dependencies = [] + for ci in self.component_infos: + dependencies.append(os.path.join(self.source_root, ci.subpath[1:])) + + # Gather the list of necessary sources by just finding all loaded + # modules that are inside the LLVM source tree. + for module in sys.modules.values(): + # Find the module path. + if not hasattr(module, '__file__'): + continue + path = getattr(module, '__file__') + if not path: + continue + + # Strip off any compiled suffix. + if os.path.splitext(path)[1] in ['.pyc', '.pyo', '.pyd']: + path = path[:-1] + + # If the path exists and is in the source tree, consider it a + # dependency. + if (path.startswith(self.source_root) and os.path.exists(path)): + dependencies.append(path) + + # Write out the Makefile fragment. + f = open(output_path, 'w') + + # Write the header. + header_fmt = '\ +#===-- %s - LLVMBuild Configuration for LLVM %s-*- Makefile -*--===#' + header_name = os.path.basename(output_path) + header_pad = '-' * (80 - len(header_fmt % (header_name, ''))) + header_string = header_fmt % (header_name, header_pad) + print >>f, """\ +%s +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# +# +# This file contains the LLVMBuild project information in a format easily +# consumed by the Makefile based build system. +# +# This file is autogenerated by llvm-build, do not edit! +# +#===------------------------------------------------------------------------===# +""" % header_string + + # Write the dependencies for the fragment. + # + # FIXME: Technically, we need to properly quote for Make here. + print >>f, """\ +# Clients must explicitly enable LLVMBUILD_INCLUDE_DEPENDENCIES to get +# these dependencies. This is a compromise to help improve the +# performance of recursive Make systems.""" + print >>f, 'ifeq ($(LLVMBUILD_INCLUDE_DEPENDENCIES),1)' + print >>f, "# The dependencies for this Makefile fragment itself." + print >>f, "%s: \\" % (output_path,) + for dep in dependencies: + print >>f, "\t%s \\" % (dep,) + print >>f + + # Generate dummy rules for each of the dependencies, so that things + # continue to work correctly if any of those files are moved or removed. + print >>f, """\ +# The dummy targets to allow proper regeneration even when files are moved or +# removed.""" + for dep in dependencies: + print >>f, "%s:" % (dep,) + print >>f, 'endif' + + f.close() + def main(): from optparse import OptionParser, OptionGroup parser = OptionParser("usage: %prog [options]") @@ -302,6 +390,10 @@ def main(): dest="write_library_table", metavar="PATH", help="Write the C++ library dependency table to PATH", action="store", default=None) + parser.add_option("", "--write-make-fragment", + dest="write_make_fragment", metavar="PATH", + help="Write the Makefile project information to PATH", + action="store", default=None) parser.add_option("", "--llvmbuild-source-root", dest="llvmbuild_source_root", help=( @@ -342,5 +434,9 @@ def main(): if opts.write_library_table: project_info.write_library_table(opts.write_library_table) + # Write out the required librariy, if requested. + if opts.write_make_fragment: + project_info.write_make_fragment(opts.write_make_fragment) + if __name__=='__main__': main() |