summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2011-11-03 22:46:19 +0000
committerDaniel Dunbar <daniel@zuster.org>2011-11-03 22:46:19 +0000
commit02271a7b42ab658115c19d5041eaed2001b9537c (patch)
tree6f08e2c6605dbe2488a0980e39bba11d4cfd3e18
parent65fd6564b8aedd053845c81ede1ac594acb470e4 (diff)
downloadllvm-02271a7b42ab658115c19d5041eaed2001b9537c.tar.gz
llvm-02271a7b42ab658115c19d5041eaed2001b9537c.tar.bz2
llvm-02271a7b42ab658115c19d5041eaed2001b9537c.tar.xz
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
-rw-r--r--docs/CommandGuide/llvm-build.pod7
-rw-r--r--utils/llvm-build/llvmbuild/main.py96
2 files changed, 103 insertions, 0 deletions
diff --git a/docs/CommandGuide/llvm-build.pod b/docs/CommandGuide/llvm-build.pod
index 2ccc1a29fe..5ce93a90c0 100644
--- a/docs/CommandGuide/llvm-build.pod
+++ b/docs/CommandGuide/llvm-build.pod
@@ -48,6 +48,13 @@ component combinations.
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
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()