OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Notes: | 5 # Notes: |
6 # | 6 # |
7 # This is all roughly based on the Makefile system used by the Linux | 7 # This is all roughly based on the Makefile system used by the Linux |
8 # kernel, but is a non-recursive make -- we put the entire dependency | 8 # kernel, but is a non-recursive make -- we put the entire dependency |
9 # graph in front of make and let it figure it out. | 9 # graph in front of make and let it figure it out. |
10 # | 10 # |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 part_of_all: flag indicating this target is part of 'all' | 1386 part_of_all: flag indicating this target is part of 'all' |
1387 """ | 1387 """ |
1388 | 1388 |
1389 self.WriteLn('### Rules for final target.') | 1389 self.WriteLn('### Rules for final target.') |
1390 | 1390 |
1391 if extra_outputs: | 1391 if extra_outputs: |
1392 self.WriteDependencyOnExtraOutputs(self.output_binary, extra_outputs) | 1392 self.WriteDependencyOnExtraOutputs(self.output_binary, extra_outputs) |
1393 self.WriteMakeRule(extra_outputs, deps, | 1393 self.WriteMakeRule(extra_outputs, deps, |
1394 comment=('Preserve order dependency of ' | 1394 comment=('Preserve order dependency of ' |
1395 'special output on deps.'), | 1395 'special output on deps.'), |
1396 order_only = True, | 1396 order_only = True) |
1397 multiple_output_trick = False) | |
1398 | 1397 |
1399 target_postbuilds = {} | 1398 target_postbuilds = {} |
1400 if self.type != 'none': | 1399 if self.type != 'none': |
1401 for configname in sorted(configs.keys()): | 1400 for configname in sorted(configs.keys()): |
1402 config = configs[configname] | 1401 config = configs[configname] |
1403 if self.flavor == 'mac': | 1402 if self.flavor == 'mac': |
1404 ldflags = self.xcode_settings.GetLdflags(configname, | 1403 ldflags = self.xcode_settings.GetLdflags(configname, |
1405 generator_default_variables['PRODUCT_DIR'], | 1404 generator_default_variables['PRODUCT_DIR'], |
1406 lambda p: Sourceify(self.Absolutify(p))) | 1405 lambda p: Sourceify(self.Absolutify(p))) |
1407 | 1406 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 force = True) | 1626 force = True) |
1628 # Add our outputs to the list of targets we read depfiles from. | 1627 # Add our outputs to the list of targets we read depfiles from. |
1629 # all_deps is only used for deps file reading, and for deps files we replace | 1628 # all_deps is only used for deps file reading, and for deps files we replace |
1630 # spaces with ? because escaping doesn't work with make's $(sort) and | 1629 # spaces with ? because escaping doesn't work with make's $(sort) and |
1631 # other functions. | 1630 # other functions. |
1632 outputs = [QuoteSpaces(o, SPACE_REPLACEMENT) for o in outputs] | 1631 outputs = [QuoteSpaces(o, SPACE_REPLACEMENT) for o in outputs] |
1633 self.WriteLn('all_deps += %s' % ' '.join(outputs)) | 1632 self.WriteLn('all_deps += %s' % ' '.join(outputs)) |
1634 | 1633 |
1635 | 1634 |
1636 def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, | 1635 def WriteMakeRule(self, outputs, inputs, actions=None, comment=None, |
1637 order_only=False, force=False, phony=False, | 1636 order_only=False, force=False, phony=False): |
1638 multiple_output_trick=True): | |
1639 """Write a Makefile rule, with some extra tricks. | 1637 """Write a Makefile rule, with some extra tricks. |
1640 | 1638 |
1641 outputs: a list of outputs for the rule (note: this is not directly | 1639 outputs: a list of outputs for the rule (note: this is not directly |
1642 supported by make; see comments below) | 1640 supported by make; see comments below) |
1643 inputs: a list of inputs for the rule | 1641 inputs: a list of inputs for the rule |
1644 actions: a list of shell commands to run for the rule | 1642 actions: a list of shell commands to run for the rule |
1645 comment: a comment to put in the Makefile above the rule (also useful | 1643 comment: a comment to put in the Makefile above the rule (also useful |
1646 for making this Python script's code self-documenting) | 1644 for making this Python script's code self-documenting) |
1647 order_only: if true, makes the dependency order-only | 1645 order_only: if true, makes the dependency order-only |
1648 force: if true, include FORCE_DO_CMD as an order-only dep | 1646 force: if true, include FORCE_DO_CMD as an order-only dep |
1649 phony: if true, the rule does not actually generate the named output, the | 1647 phony: if true, the rule does not actually generate the named output, the |
1650 output is just a name to run the rule | 1648 output is just a name to run the rule |
1651 multiple_output_trick: if true (the default), perform tricks such as dummy | |
1652 rules to avoid problems with multiple outputs. | |
1653 """ | 1649 """ |
1654 outputs = map(QuoteSpaces, outputs) | 1650 outputs = map(QuoteSpaces, outputs) |
1655 inputs = map(QuoteSpaces, inputs) | 1651 inputs = map(QuoteSpaces, inputs) |
1656 | 1652 |
1657 if comment: | 1653 if comment: |
1658 self.WriteLn('# ' + comment) | 1654 self.WriteLn('# ' + comment) |
1659 if phony: | 1655 if phony: |
1660 self.WriteLn('.PHONY: ' + ' '.join(outputs)) | 1656 self.WriteLn('.PHONY: ' + ' '.join(outputs)) |
1661 # TODO(evanm): just make order_only a list of deps instead of these hacks. | 1657 # TODO(evanm): just make order_only a list of deps instead of these hacks. |
1662 if order_only: | 1658 if order_only: |
1663 order_insert = '| ' | 1659 order_insert = '| ' |
| 1660 pick_output = ' '.join(outputs) |
1664 else: | 1661 else: |
1665 order_insert = '' | 1662 order_insert = '' |
| 1663 pick_output = outputs[0] |
1666 if force: | 1664 if force: |
1667 force_append = ' FORCE_DO_CMD' | 1665 force_append = ' FORCE_DO_CMD' |
1668 else: | 1666 else: |
1669 force_append = '' | 1667 force_append = '' |
1670 if actions: | 1668 if actions: |
1671 self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0]) | 1669 self.WriteLn("%s: TOOLSET := $(TOOLSET)" % outputs[0]) |
1672 self.WriteLn('%s: %s%s%s' % (outputs[0], order_insert, ' '.join(inputs), | 1670 self.WriteLn('%s: %s%s%s' % (pick_output, order_insert, ' '.join(inputs), |
1673 force_append)) | 1671 force_append)) |
1674 if actions: | 1672 if actions: |
1675 for action in actions: | 1673 for action in actions: |
1676 self.WriteLn('\t%s' % action) | 1674 self.WriteLn('\t%s' % action) |
1677 if multiple_output_trick and len(outputs) > 1: | 1675 if not order_only and len(outputs) > 1: |
1678 # If we have more than one output, a rule like | 1676 # If we have more than one output, a rule like |
1679 # foo bar: baz | 1677 # foo bar: baz |
1680 # that for *each* output we must run the action, potentially | 1678 # that for *each* output we must run the action, potentially |
1681 # in parallel. That is not what we're trying to write -- what | 1679 # in parallel. That is not what we're trying to write -- what |
1682 # we want is that we run the action once and it generates all | 1680 # we want is that we run the action once and it generates all |
1683 # the files. | 1681 # the files. |
1684 # http://www.gnu.org/software/hello/manual/automake/Multiple-Outputs.html | 1682 # http://www.gnu.org/software/hello/manual/automake/Multiple-Outputs.html |
1685 # discusses this problem and has this solution: | 1683 # discusses this problem and has this solution: |
1686 # 1) Write the naive rule that would produce parallel runs of | 1684 # 1) Write the naive rule that would produce parallel runs of |
1687 # the action. | 1685 # the action. |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 root_makefile.write(" include " + include_file + "\n") | 2133 root_makefile.write(" include " + include_file + "\n") |
2136 root_makefile.write("endif\n") | 2134 root_makefile.write("endif\n") |
2137 root_makefile.write('\n') | 2135 root_makefile.write('\n') |
2138 | 2136 |
2139 if generator_flags.get('auto_regeneration', True): | 2137 if generator_flags.get('auto_regeneration', True): |
2140 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) | 2138 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) |
2141 | 2139 |
2142 root_makefile.write(SHARED_FOOTER) | 2140 root_makefile.write(SHARED_FOOTER) |
2143 | 2141 |
2144 root_makefile.close() | 2142 root_makefile.close() |
OLD | NEW |