From 02271a7b42ab658115c19d5041eaed2001b9537c Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 3 Nov 2011 22:46:19 +0000 Subject: 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 --- utils/llvm-build/llvmbuild/main.py | 96 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'utils/llvm-build') 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() -- cgit v1.2.3