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