12 def cmake_quote_string(value):
14 cmake_quote_string(value) -> str
16 Return a quoted form of the given value that is suitable for use in CMake
20 # Currently, we only handle escaping backslashes.
21 value = value.replace("\\", "\\\\")
25 def cmake_quote_path(value):
27 cmake_quote_path(value) -> str
29 Return a quoted form of the given value that is suitable for use in CMake
33 # CMake has a bug in it's Makefile generator that doesn't properly quote
34 # strings it generates. So instead of using proper quoting, we just use "/"
35 # style paths. Currently, we only handle escaping backslashes.
36 value = value.replace("\\", "/")
40 def mk_quote_string_for_target(value):
42 mk_quote_string_for_target(target_name) -> str
44 Return a quoted form of the given target_name suitable for including in a
45 Makefile as a target name.
48 # The only quoting we currently perform is for ':', to support msys users.
49 return value.replace(":", "\\:")
51 def make_install_dir(path):
53 make_install_dir(path) -> None
55 Create the given directory path for installation, including any parents.
58 # os.makedirs considers it an error to be called with an existant path.
59 if not os.path.exists(path):
64 class LLVMProjectInfo(object):
66 def load_infos_from_path(llvmbuild_source_root):
68 # Load the LLVMBuild file.
69 llvmbuild_path = os.path.join(llvmbuild_source_root + subpath,
71 if not os.path.exists(llvmbuild_path):
72 fatal("missing LLVMBuild.txt file at: %r" % (llvmbuild_path,))
74 # Parse the components from it.
75 common,info_iter = componentinfo.load_from_path(llvmbuild_path,
77 for info in info_iter:
80 # Recurse into the specified subdirectories.
81 for subdir in common.get_list("subdirectories"):
82 for item in recurse(os.path.join(subpath, subdir)):
88 def load_from_path(source_root, llvmbuild_source_root):
90 LLVMProjectInfo.load_infos_from_path(llvmbuild_source_root))
92 return LLVMProjectInfo(source_root, infos)
94 def __init__(self, source_root, component_infos):
95 # Store our simple ivars.
96 self.source_root = source_root
97 self.component_infos = list(component_infos)
98 self.component_info_map = None
99 self.ordered_component_infos = None
101 def validate_components(self):
102 """validate_components() -> None
104 Validate that the project components are well-defined. Among other
105 things, this checks that:
106 - Components have valid references.
107 - Components references do not form cycles.
109 We also construct the map from component names to info, and the
110 topological ordering of components.
113 # Create the component info map and validate that component names are
115 self.component_info_map = {}
116 for ci in self.component_infos:
117 existing = self.component_info_map.get(ci.name)
118 if existing is not None:
119 # We found a duplicate component name, report it and error out.
120 fatal("found duplicate component %r (at %r and %r)" % (
121 ci.name, ci.subpath, existing.subpath))
122 self.component_info_map[ci.name] = ci
124 # Disallow 'all' as a component name, which is a special case.
125 if 'all' in self.component_info_map:
126 fatal("project is not allowed to define 'all' component")
128 # Add the root component.
129 if '$ROOT' in self.component_info_map:
130 fatal("project is not allowed to define $ROOT component")
131 self.component_info_map['$ROOT'] = componentinfo.GroupComponentInfo(
133 self.component_infos.append(self.component_info_map['$ROOT'])
135 # Topologically order the component information according to their
136 # component references.
137 def visit_component_info(ci, current_stack, current_set):
138 # Check for a cycles.
139 if ci in current_set:
140 # We found a cycle, report it and error out.
141 cycle_description = ' -> '.join(
142 '%r (%s)' % (ci.name, relation)
143 for relation,ci in current_stack)
144 fatal("found cycle to %r after following: %s -> %s" % (
145 ci.name, cycle_description, ci.name))
147 # If we have already visited this item, we are done.
148 if ci not in components_to_visit:
151 # Otherwise, mark the component info as visited and traverse.
152 components_to_visit.remove(ci)
154 # Validate the parent reference, which we treat specially.
155 if ci.parent is not None:
156 parent = self.component_info_map.get(ci.parent)
158 fatal("component %r has invalid reference %r (via %r)" % (
159 ci.name, ci.parent, 'parent'))
160 ci.set_parent_instance(parent)
162 for relation,referent_name in ci.get_component_references():
163 # Validate that the reference is ok.
164 referent = self.component_info_map.get(referent_name)
166 fatal("component %r has invalid reference %r (via %r)" % (
167 ci.name, referent_name, relation))
169 # Visit the reference.
170 current_stack.append((relation,ci))
172 visit_component_info(referent, current_stack, current_set)
173 current_set.remove(ci)
176 # Finally, add the component info to the ordered list.
177 self.ordered_component_infos.append(ci)
179 # FIXME: We aren't actually correctly checking for cycles along the
180 # parent edges. Haven't decided how I want to handle this -- I thought
181 # about only checking cycles by relation type. If we do that, it falls
182 # out easily. If we don't, we should special case the check.
184 self.ordered_component_infos = []
185 components_to_visit = set(self.component_infos)
186 while components_to_visit:
187 visit_component_info(iter(components_to_visit).next(), [], set())
189 # Canonicalize children lists.
190 for c in self.ordered_component_infos:
191 c.children.sort(key = lambda c: c.name)
193 def print_tree(self):
194 def visit(node, depth = 0):
195 print '%s%-40s (%s)' % (' '*depth, node.name, node.type_name)
196 for c in node.children:
198 visit(self.component_info_map['$ROOT'])
200 def write_components(self, output_path):
201 # Organize all the components by the directory their LLVMBuild file
204 for ci in self.component_infos:
205 # Ignore the $ROOT component.
206 if ci.parent is None:
209 info_basedir[ci.subpath] = info_basedir.get(ci.subpath, []) + [ci]
211 # Compute the list of subdirectories to scan.
213 for ci in self.component_infos:
214 # Ignore root components.
215 if ci.subpath == '/':
218 # Otherwise, append this subpath to the parent list.
219 parent_path = os.path.dirname(ci.subpath)
220 subpath_subdirs[parent_path] = parent_list = subpath_subdirs.get(
222 parent_list.add(os.path.basename(ci.subpath))
224 # Generate the build files.
225 for subpath, infos in info_basedir.items():
226 # Order the components by name to have a canonical ordering.
227 infos.sort(key = lambda ci: ci.name)
229 # Format the components into llvmbuild fragments.
232 # Add the common fragments.
233 subdirectories = subpath_subdirs.get(subpath)
237 """ % (" ".join(sorted(subdirectories)),)
238 fragments.append(("common", fragment))
240 # Add the component fragments.
241 num_common_fragments = len(fragments)
243 fragment = ci.get_llvmbuild_fragment()
247 name = "component_%d" % (len(fragments) - num_common_fragments)
248 fragments.append((name, fragment))
253 assert subpath.startswith('/')
254 directory_path = os.path.join(output_path, subpath[1:])
256 # Create the directory if it does not already exist.
257 if not os.path.exists(directory_path):
258 os.makedirs(directory_path)
260 # In an effort to preserve comments (which aren't parsed), read in
261 # the original file and extract the comments. We only know how to
262 # associate comments that prefix a section name.
263 f = open(infos[0]._source_path)
267 if ln.startswith(';'):
269 elif ln.startswith('[') and ln.endswith(']\n'):
270 comments_map[ln[1:-2]] = comment_block
275 # Create the LLVMBuild fil[e.
276 file_path = os.path.join(directory_path, 'LLVMBuild.txt')
277 f = open(file_path, "w")
280 header_fmt = ';===- %s %s-*- Conf -*--===;'
281 header_name = '.' + os.path.join(subpath, 'LLVMBuild.txt')
282 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
283 header_string = header_fmt % (header_name, header_pad)
287 ; The LLVM Compiler Infrastructure
289 ; This file is distributed under the University of Illinois Open Source
290 ; License. See LICENSE.TXT for details.
292 ;===------------------------------------------------------------------------===;
294 ; This is an LLVMBuild description file for the components in this subdirectory.
296 ; For more information on the LLVMBuild system, please see:
298 ; http://llvm.org/docs/LLVMBuild.html
300 ;===------------------------------------------------------------------------===;
303 # Write out each fragment.each component fragment.
304 for name,fragment in fragments:
305 comment = comments_map.get(name)
306 if comment is not None:
308 print >>f, "[%s]" % name
310 if fragment is not fragments[-1][1]:
315 def write_library_table(self, output_path):
316 # Write out the mapping from component names to required libraries.
318 # We do this in topological order so that we know we can append the
319 # dependencies for added library groups.
321 for c in self.ordered_component_infos:
322 # Only certain components are in the table.
323 if c.type_name not in ('Library', 'LibraryGroup', 'TargetGroup'):
326 # Compute the llvm-config "component name". For historical reasons,
327 # this is lowercased based on the library name.
328 llvmconfig_component_name = c.get_llvmconfig_component_name()
330 # Get the library name, or None for LibraryGroups.
331 if c.type_name == 'Library':
332 library_name = c.get_prefixed_library_name()
336 # Get the component names of all the required libraries.
337 required_llvmconfig_component_names = [
338 self.component_info_map[dep].get_llvmconfig_component_name()
339 for dep in c.required_libraries]
341 # Insert the entries for library groups we should add to.
342 for dep in c.add_to_library_groups:
343 entries[dep][2].append(llvmconfig_component_name)
346 entries[c.name] = (llvmconfig_component_name, library_name,
347 required_llvmconfig_component_names)
349 # Convert to a list of entries and sort by name.
350 entries = entries.values()
352 # Create an 'all' pseudo component. We keep the dependency list small by
353 # only listing entries that have no other dependents.
354 root_entries = set(e[0] for e in entries)
355 for _,_,deps in entries:
356 root_entries -= set(deps)
357 entries.append(('all', None, root_entries))
361 # Compute the maximum number of required libraries, plus one so there is
363 max_required_libraries = max(len(deps)
364 for _,_,deps in entries) + 1
366 # Write out the library table.
367 make_install_dir(os.path.dirname(output_path))
368 f = open(output_path, 'w')
370 //===- llvm-build generated file --------------------------------*- C++ -*-===//
372 // Component Library Depenedency Table
374 // Automatically generated file, do not edit!
376 //===----------------------------------------------------------------------===//
378 print >>f, 'struct AvailableComponent {'
379 print >>f, ' /// The name of the component.'
380 print >>f, ' const char *Name;'
382 print >>f, ' /// The name of the library for this component (or NULL).'
383 print >>f, ' const char *Library;'
386 /// The list of libraries required when linking this component.'
387 print >>f, ' const char *RequiredLibraries[%d];' % (
388 max_required_libraries)
389 print >>f, '} AvailableComponents[%d] = {' % len(entries)
390 for name,library_name,required_names in entries:
391 if library_name is None:
392 library_name_as_cstr = '0'
394 library_name_as_cstr = '"lib%s.a"' % library_name
395 print >>f, ' { "%s", %s, { %s } },' % (
396 name, library_name_as_cstr,
397 ', '.join('"%s"' % dep
398 for dep in required_names))
402 def get_required_libraries_for_component(self, ci, traverse_groups = False):
404 get_required_libraries_for_component(component_info) -> iter
406 Given a Library component info descriptor, return an iterator over all
407 of the directly required libraries for linking with this component. If
408 traverse_groups is True, then library and target groups will be
409 traversed to include their required libraries.
412 assert ci.type_name in ('Library', 'LibraryGroup', 'TargetGroup')
414 for name in ci.required_libraries:
415 # Get the dependency info.
416 dep = self.component_info_map[name]
418 # If it is a library, yield it.
419 if dep.type_name == 'Library':
423 # Otherwise if it is a group, yield or traverse depending on what
425 if dep.type_name in ('LibraryGroup', 'TargetGroup'):
426 if not traverse_groups:
430 for res in self.get_required_libraries_for_component(dep, True):
433 def get_fragment_dependencies(self):
435 get_fragment_dependencies() -> iter
437 Compute the list of files (as absolute paths) on which the output
438 fragments depend (i.e., files for which a modification should trigger a
439 rebuild of the fragment).
442 # Construct a list of all the dependencies of the Makefile fragment
443 # itself. These include all the LLVMBuild files themselves, as well as
444 # all of our own sources.
446 # Many components may come from the same file, so we make sure to unique
449 for ci in self.component_infos:
450 p = os.path.join(self.source_root, ci.subpath[1:], 'LLVMBuild.txt')
451 if p not in build_paths:
455 # Gather the list of necessary sources by just finding all loaded
456 # modules that are inside the LLVM source tree.
457 for module in sys.modules.values():
458 # Find the module path.
459 if not hasattr(module, '__file__'):
461 path = getattr(module, '__file__')
465 # Strip off any compiled suffix.
466 if os.path.splitext(path)[1] in ['.pyc', '.pyo', '.pyd']:
469 # If the path exists and is in the source tree, consider it a
471 if (path.startswith(self.source_root) and os.path.exists(path)):
474 def write_cmake_fragment(self, output_path):
476 write_cmake_fragment(output_path) -> None
478 Generate a CMake fragment which includes all of the collated LLVMBuild
479 information in a format that is easily digestible by a CMake. The exact
480 contents of this are closely tied to how the CMake configuration
481 integrates LLVMBuild, see CMakeLists.txt in the top-level.
484 dependencies = list(self.get_fragment_dependencies())
486 # Write out the CMake fragment.
487 make_install_dir(os.path.dirname(output_path))
488 f = open(output_path, 'w')
492 #===-- %s - LLVMBuild Configuration for LLVM %s-*- CMake -*--===#'
493 header_name = os.path.basename(output_path)
494 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
495 header_string = header_fmt % (header_name, header_pad)
499 # The LLVM Compiler Infrastructure
501 # This file is distributed under the University of Illinois Open Source
502 # License. See LICENSE.TXT for details.
504 #===------------------------------------------------------------------------===#
506 # This file contains the LLVMBuild project information in a format easily
507 # consumed by the CMake based build system.
509 # This file is autogenerated by llvm-build, do not edit!
511 #===------------------------------------------------------------------------===#
514 # Write the dependency information in the best way we can.
516 # LLVMBuild CMake fragment dependencies.
518 # CMake has no builtin way to declare that the configuration depends on
519 # a particular file. However, a side effect of configure_file is to add
520 # said input file to CMake's internal dependency list. So, we use that
521 # and a dummy output file to communicate the dependency information to
524 # FIXME: File a CMake RFE to get a properly supported version of this
526 for dep in dependencies:
528 configure_file(\"%s\"
529 ${CMAKE_CURRENT_BINARY_DIR}/DummyConfigureOutput)""" % (
530 cmake_quote_path(dep),)
532 # Write the properties we use to encode the required library dependency
533 # information in a form CMake can easily use directly.
535 # Explicit library dependency information.
537 # The following property assignments effectively create a map from component
538 # names to required libraries, in a way that is easily accessed from CMake."""
539 for ci in self.ordered_component_infos:
540 # We only write the information for libraries currently.
541 if ci.type_name != 'Library':
545 set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)""" % (
546 ci.get_prefixed_library_name(), " ".join(sorted(
547 dep.get_prefixed_library_name()
548 for dep in self.get_required_libraries_for_component(ci))))
552 def write_make_fragment(self, output_path):
554 write_make_fragment(output_path) -> None
556 Generate a Makefile fragment which includes all of the collated
557 LLVMBuild information in a format that is easily digestible by a
558 Makefile. The exact contents of this are closely tied to how the LLVM
559 Makefiles integrate LLVMBuild, see Makefile.rules in the top-level.
562 dependencies = list(self.get_fragment_dependencies())
564 # Write out the Makefile fragment.
565 make_install_dir(os.path.dirname(output_path))
566 f = open(output_path, 'w')
570 #===-- %s - LLVMBuild Configuration for LLVM %s-*- Makefile -*--===#'
571 header_name = os.path.basename(output_path)
572 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
573 header_string = header_fmt % (header_name, header_pad)
577 # The LLVM Compiler Infrastructure
579 # This file is distributed under the University of Illinois Open Source
580 # License. See LICENSE.TXT for details.
582 #===------------------------------------------------------------------------===#
584 # This file contains the LLVMBuild project information in a format easily
585 # consumed by the Makefile based build system.
587 # This file is autogenerated by llvm-build, do not edit!
589 #===------------------------------------------------------------------------===#
592 # Write the dependencies for the fragment.
594 # FIXME: Technically, we need to properly quote for Make here.
596 # Clients must explicitly enable LLVMBUILD_INCLUDE_DEPENDENCIES to get
597 # these dependencies. This is a compromise to help improve the
598 # performance of recursive Make systems."""
599 print >>f, 'ifeq ($(LLVMBUILD_INCLUDE_DEPENDENCIES),1)'
600 print >>f, "# The dependencies for this Makefile fragment itself."
601 print >>f, "%s: \\" % (mk_quote_string_for_target(output_path),)
602 for dep in dependencies:
603 print >>f, "\t%s \\" % (dep,)
606 # Generate dummy rules for each of the dependencies, so that things
607 # continue to work correctly if any of those files are moved or removed.
609 # The dummy targets to allow proper regeneration even when files are moved or
611 for dep in dependencies:
612 print >>f, "%s:" % (mk_quote_string_for_target(dep),)
617 def add_magic_target_components(parser, project, opts):
618 """add_magic_target_components(project, opts) -> None
620 Add the "magic" target based components to the project, which can only be
621 determined based on the target configuration options.
623 This currently is responsible for populating the required_libraries list of
624 the "all-targets", "Native", "NativeCodeGen", and "Engine" components.
627 # Determine the available targets.
628 available_targets = dict((ci.name,ci)
629 for ci in project.component_infos
630 if ci.type_name == 'TargetGroup')
632 # Find the configured native target.
634 # We handle a few special cases of target names here for historical
635 # reasons, as these are the names configure currently comes up with.
636 native_target_name = { 'x86' : 'X86',
638 'Unknown' : None }.get(opts.native_target,
640 if native_target_name is None:
643 native_target = available_targets.get(native_target_name)
644 if native_target is None:
645 parser.error("invalid native target: %r (not in project)" % (
646 opts.native_target,))
647 if native_target.type_name != 'TargetGroup':
648 parser.error("invalid native target: %r (not a target)" % (
649 opts.native_target,))
651 # Find the list of targets to enable.
652 if opts.enable_targets is None:
653 enable_targets = available_targets.values()
655 # We support both space separated and semi-colon separated lists.
656 if ' ' in opts.enable_targets:
657 enable_target_names = opts.enable_targets.split()
659 enable_target_names = opts.enable_targets.split(';')
662 for name in enable_target_names:
663 target = available_targets.get(name)
665 parser.error("invalid target to enable: %r (not in project)" % (
667 if target.type_name != 'TargetGroup':
668 parser.error("invalid target to enable: %r (not a target)" % (
670 enable_targets.append(target)
672 # Find the special library groups we are going to populate. We enforce that
673 # these appear in the project (instead of just adding them) so that they at
674 # least have an explicit representation in the project LLVMBuild files (and
675 # comments explaining how they are populated).
676 def find_special_group(name):
677 info = info_map.get(name)
679 fatal("expected project to contain special %r component" % (
682 if info.type_name != 'LibraryGroup':
683 fatal("special component %r should be a LibraryGroup" % (
686 if info.required_libraries:
687 fatal("special component %r must have empty %r list" % (
688 name, 'required_libraries'))
689 if info.add_to_library_groups:
690 fatal("special component %r must have empty %r list" % (
691 name, 'add_to_library_groups'))
693 info._is_special_group = True
696 info_map = dict((ci.name, ci) for ci in project.component_infos)
697 all_targets = find_special_group('all-targets')
698 native_group = find_special_group('Native')
699 native_codegen_group = find_special_group('NativeCodeGen')
700 engine_group = find_special_group('Engine')
702 # Set the enabled bit in all the target groups, and append to the
704 for ci in enable_targets:
705 all_targets.required_libraries.append(ci.name)
708 # If we have a native target, then that defines the native and
709 # native_codegen libraries.
710 if native_target and native_target.enabled:
711 native_group.required_libraries.append(native_target.name)
712 native_codegen_group.required_libraries.append(
713 '%sCodeGen' % native_target.name)
715 # If we have a native target with a JIT, use that for the engine. Otherwise,
716 # use the interpreter.
717 if native_target and native_target.enabled and native_target.has_jit:
718 engine_group.required_libraries.append('JIT')
719 engine_group.required_libraries.append(native_group.name)
721 engine_group.required_libraries.append('Interpreter')
724 from optparse import OptionParser, OptionGroup
725 parser = OptionParser("usage: %prog [options]")
727 group = OptionGroup(parser, "Input Options")
728 group.add_option("", "--source-root", dest="source_root", metavar="PATH",
729 help="Path to the LLVM source (inferred if not given)",
730 action="store", default=None)
731 group.add_option("", "--llvmbuild-source-root",
732 dest="llvmbuild_source_root",
734 "If given, an alternate path to search for LLVMBuild.txt files"),
735 action="store", default=None, metavar="PATH")
736 group.add_option("", "--build-root", dest="build_root", metavar="PATH",
737 help="Path to the build directory (if needed) [%default]",
738 action="store", default=None)
739 parser.add_option_group(group)
741 group = OptionGroup(parser, "Output Options")
742 group.add_option("", "--print-tree", dest="print_tree",
743 help="Print out the project component tree [%default]",
744 action="store_true", default=False)
745 group.add_option("", "--write-llvmbuild", dest="write_llvmbuild",
746 help="Write out the LLVMBuild.txt files to PATH",
747 action="store", default=None, metavar="PATH")
748 group.add_option("", "--write-library-table",
749 dest="write_library_table", metavar="PATH",
750 help="Write the C++ library dependency table to PATH",
751 action="store", default=None)
752 group.add_option("", "--write-cmake-fragment",
753 dest="write_cmake_fragment", metavar="PATH",
754 help="Write the CMake project information to PATH",
755 action="store", default=None)
756 group.add_option("", "--write-make-fragment",
757 dest="write_make_fragment", metavar="PATH",
758 help="Write the Makefile project information to PATH",
759 action="store", default=None)
760 group.add_option("", "--configure-target-def-file",
761 dest="configure_target_def_files",
762 help="""Configure the given file at SUBPATH (relative to
763 the inferred or given source root, and with a '.in' suffix) by replacing certain
764 substitution variables with lists of targets that support certain features (for
765 example, targets with AsmPrinters) and write the result to the build root (as
766 given by --build-root) at the same SUBPATH""",
767 metavar="SUBPATH", action="append", default=None)
768 parser.add_option_group(group)
770 group = OptionGroup(parser, "Configuration Options")
771 group.add_option("", "--native-target",
772 dest="native_target", metavar="NAME",
773 help=("Treat the named target as the 'native' one, if "
775 action="store", default=None)
776 group.add_option("", "--enable-targets",
777 dest="enable_targets", metavar="NAMES",
778 help=("Enable the given space or semi-colon separated "
779 "list of targets, or all targets if not present"),
780 action="store", default=None)
781 parser.add_option_group(group)
783 (opts, args) = parser.parse_args()
785 # Determine the LLVM source path, if not given.
786 source_root = opts.source_root
788 if not os.path.exists(os.path.join(source_root, 'lib', 'VMCore',
790 parser.error('invalid LLVM source root: %r' % source_root)
792 llvmbuild_path = os.path.dirname(__file__)
793 llvm_build_path = os.path.dirname(llvmbuild_path)
794 utils_path = os.path.dirname(llvm_build_path)
795 source_root = os.path.dirname(utils_path)
796 if not os.path.exists(os.path.join(source_root, 'lib', 'VMCore',
798 parser.error('unable to infer LLVM source root, please specify')
800 # Construct the LLVM project information.
801 llvmbuild_source_root = opts.llvmbuild_source_root or source_root
802 project_info = LLVMProjectInfo.load_from_path(
803 source_root, llvmbuild_source_root)
805 # Add the magic target based components.
806 add_magic_target_components(parser, project_info, opts)
808 # Validate the project component info.
809 project_info.validate_components()
811 # Print the component tree, if requested.
813 project_info.print_tree()
815 # Write out the components, if requested. This is useful for auto-upgrading
817 if opts.write_llvmbuild:
818 project_info.write_components(opts.write_llvmbuild)
820 # Write out the required library table, if requested.
821 if opts.write_library_table:
822 project_info.write_library_table(opts.write_library_table)
824 # Write out the make fragment, if requested.
825 if opts.write_make_fragment:
826 project_info.write_make_fragment(opts.write_make_fragment)
828 # Write out the cmake fragment, if requested.
829 if opts.write_cmake_fragment:
830 project_info.write_cmake_fragment(opts.write_cmake_fragment)
832 # Configure target definition files, if requested.
833 if opts.configure_target_def_files:
834 # Verify we were given a build root.
835 if not opts.build_root:
836 parser.error("must specify --build-root when using "
837 "--configure-target-def-file")
839 # Create the substitution list.
840 available_targets = [ci for ci in project_info.component_infos
841 if ci.type_name == 'TargetGroup']
843 ("@LLVM_ENUM_TARGETS@",
844 ' '.join('LLVM_TARGET(%s)' % ci.name
845 for ci in available_targets)),
846 ("@LLVM_ENUM_ASM_PRINTERS@",
847 ' '.join('LLVM_ASM_PRINTER(%s)' % ci.name
848 for ci in available_targets
849 if ci.has_asmprinter)),
850 ("@LLVM_ENUM_ASM_PARSERS@",
851 ' '.join('LLVM_ASM_PARSER(%s)' % ci.name
852 for ci in available_targets
853 if ci.has_asmparser)),
854 ("@LLVM_ENUM_DISASSEMBLERS@",
855 ' '.join('LLVM_DISASSEMBLER(%s)' % ci.name
856 for ci in available_targets
857 if ci.has_disassembler))]
859 # Configure the given files.
860 for subpath in opts.configure_target_def_files:
861 inpath = os.path.join(source_root, subpath + '.in')
862 outpath = os.path.join(opts.build_root, subpath)
863 result = configutil.configure_file(inpath, outpath, substitutions)
865 note("configured file %r hasn't changed" % outpath)
867 if __name__=='__main__':