[llvm-commits] [llvm] r143661 - in /llvm/trunk: docs/CommandGuide/llvm-build.pod utils/llvm-build/llvmbuild/main.py

Daniel Dunbar daniel at zuster.org
Thu Nov 3 15:46:19 PDT 2011


Author: ddunbar
Date: Thu Nov  3 17:46:19 2011
New Revision: 143661

URL: http://llvm.org/viewvc/llvm-project?rev=143661&view=rev
Log:
llvm-build: Add initial code for --write-make-fragment.

Modified:
    llvm/trunk/docs/CommandGuide/llvm-build.pod
    llvm/trunk/utils/llvm-build/llvmbuild/main.py

Modified: llvm/trunk/docs/CommandGuide/llvm-build.pod
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-build.pod?rev=143661&r1=143660&r2=143661&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-build.pod (original)
+++ llvm/trunk/docs/CommandGuide/llvm-build.pod Thu Nov  3 17:46:19 2011
@@ -48,6 +48,13 @@
 Write out new I<LLVMBuild.txt> files based on the loaded components. This is
 useful for auto-upgrading the schema of the files.
 
+=item B<--write-make-fragment>
+
+Write out the LLVMBuild in the form of a Makefile fragment, so it can easily be
+consumed by a Make based build system. The exact contents and format of this
+file are closely tied to how LLVMBuild is integrated with the Makefiles, see
+LLVM's Makefile.rules.
+
 =item B<--llvmbuild-source-root>=I<PATH>
 
 If given, expect the I<LLVMBuild> files for the project to be rooted at the

Modified: llvm/trunk/utils/llvm-build/llvmbuild/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/llvm-build/llvmbuild/main.py?rev=143661&r1=143660&r2=143661&view=diff
==============================================================================
--- llvm/trunk/utils/llvm-build/llvmbuild/main.py (original)
+++ llvm/trunk/utils/llvm-build/llvmbuild/main.py Thu Nov  3 17:46:19 2011
@@ -286,6 +286,94 @@
         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 @@
                       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 @@
     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()





More information about the llvm-commits mailing list