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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 # The makefile rules are all relative to the top dir, but the gyp actions | 891 # The makefile rules are all relative to the top dir, but the gyp actions |
892 # are defined relative to their containing dir. This replaces the obj | 892 # are defined relative to their containing dir. This replaces the obj |
893 # variable for the action rule with an absolute version so that the output | 893 # variable for the action rule with an absolute version so that the output |
894 # goes in the right place. | 894 # goes in the right place. |
895 # Only write the 'obj' and 'builddir' rules for the "primary" output (:1); | 895 # Only write the 'obj' and 'builddir' rules for the "primary" output (:1); |
896 # it's superfluous for the "extra outputs", and this avoids accidentally | 896 # it's superfluous for the "extra outputs", and this avoids accidentally |
897 # writing duplicate dummy rules for those outputs. | 897 # writing duplicate dummy rules for those outputs. |
898 # Same for environment. | 898 # Same for environment. |
899 self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0])) | 899 self.WriteLn("%s: obj := $(abs_obj)" % QuoteSpaces(outputs[0])) |
900 self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0])) | 900 self.WriteLn("%s: builddir := $(abs_builddir)" % QuoteSpaces(outputs[0])) |
901 self.WriteXcodeEnv(outputs[0], self.GetXcodeEnv()) | 901 self.WriteSortedXcodeEnv(outputs[0], self.GetSortedXcodeEnv()) |
902 | 902 |
903 for input in inputs: | 903 for input in inputs: |
904 assert ' ' not in input, ( | 904 assert ' ' not in input, ( |
905 "Spaces in action input filenames not supported (%s)" % input) | 905 "Spaces in action input filenames not supported (%s)" % input) |
906 for output in outputs: | 906 for output in outputs: |
907 assert ' ' not in output, ( | 907 assert ' ' not in output, ( |
908 "Spaces in action output filenames not supported (%s)" % output) | 908 "Spaces in action output filenames not supported (%s)" % output) |
909 | 909 |
910 # See the comment in WriteCopies about expanding env vars. | 910 # See the comment in WriteCopies about expanding env vars. |
911 env = self.GetXcodeEnv() | 911 env = self.GetSortedXcodeEnv() |
912 outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs] | 912 outputs = [gyp.xcode_emulation.ExpandEnvVars(o, env) for o in outputs] |
913 inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs] | 913 inputs = [gyp.xcode_emulation.ExpandEnvVars(i, env) for i in inputs] |
914 | 914 |
915 self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)), | 915 self.WriteDoCmd(outputs, map(Sourceify, map(self.Absolutify, inputs)), |
916 part_of_all=part_of_all, command=name) | 916 part_of_all=part_of_all, command=name) |
917 | 917 |
918 # Stuff the outputs in a variable so we can refer to them later. | 918 # Stuff the outputs in a variable so we can refer to them later. |
919 outputs_variable = 'action_%s_outputs' % name | 919 outputs_variable = 'action_%s_outputs' % name |
920 self.WriteLn('%s := %s' % (outputs_variable, ' '.join(outputs))) | 920 self.WriteLn('%s := %s' % (outputs_variable, ' '.join(outputs))) |
921 extra_outputs.append('$(%s)' % outputs_variable) | 921 extra_outputs.append('$(%s)' % outputs_variable) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1062 |
1063 # If the output path has variables in it, which happens in practice for | 1063 # If the output path has variables in it, which happens in practice for |
1064 # 'copies', writing the environment as target-local doesn't work, | 1064 # 'copies', writing the environment as target-local doesn't work, |
1065 # because the variables are already needed for the target name. | 1065 # because the variables are already needed for the target name. |
1066 # Copying the environment variables into global make variables doesn't | 1066 # Copying the environment variables into global make variables doesn't |
1067 # work either, because then the .d files will potentially contain spaces | 1067 # work either, because then the .d files will potentially contain spaces |
1068 # after variable expansion, and .d file handling cannot handle spaces. | 1068 # after variable expansion, and .d file handling cannot handle spaces. |
1069 # As a workaround, manually expand variables at gyp time. Since 'copies' | 1069 # As a workaround, manually expand variables at gyp time. Since 'copies' |
1070 # can't run scripts, there's no need to write the env then. | 1070 # can't run scripts, there's no need to write the env then. |
1071 # WriteDoCmd() will escape spaces for .d files. | 1071 # WriteDoCmd() will escape spaces for .d files. |
1072 env = self.GetXcodeEnv() | 1072 env = self.GetSortedXcodeEnv() |
1073 output = gyp.xcode_emulation.ExpandEnvVars(output, env) | 1073 output = gyp.xcode_emulation.ExpandEnvVars(output, env) |
1074 path = gyp.xcode_emulation.ExpandEnvVars(path, env) | 1074 path = gyp.xcode_emulation.ExpandEnvVars(path, env) |
1075 self.WriteDoCmd([output], [path], 'copy', part_of_all) | 1075 self.WriteDoCmd([output], [path], 'copy', part_of_all) |
1076 outputs.append(output) | 1076 outputs.append(output) |
1077 self.WriteLn('%s = %s' % (variable, ' '.join(map(QuoteSpaces, outputs)))) | 1077 self.WriteLn('%s = %s' % (variable, ' '.join(map(QuoteSpaces, outputs)))) |
1078 extra_outputs.append('$(%s)' % variable) | 1078 extra_outputs.append('$(%s)' % variable) |
1079 self.WriteLn() | 1079 self.WriteLn() |
1080 | 1080 |
1081 | 1081 |
1082 def WriteMacBundleResources(self, resources, bundle_deps): | 1082 def WriteMacBundleResources(self, resources, bundle_deps): |
(...skipping 21 matching lines...) Expand all Loading... |
1104 os.path.basename(info_plist)) | 1104 os.path.basename(info_plist)) |
1105 self.WriteList(defines, intermediate_plist + ': INFOPLIST_DEFINES', '-D', | 1105 self.WriteList(defines, intermediate_plist + ': INFOPLIST_DEFINES', '-D', |
1106 quoter=EscapeCppDefine) | 1106 quoter=EscapeCppDefine) |
1107 self.WriteMakeRule([intermediate_plist], [info_plist], | 1107 self.WriteMakeRule([intermediate_plist], [info_plist], |
1108 ['$(call do_cmd,infoplist)', | 1108 ['$(call do_cmd,infoplist)', |
1109 # "Convert" the plist so that any weird whitespace changes from the | 1109 # "Convert" the plist so that any weird whitespace changes from the |
1110 # preprocessor do not affect the XML parser in mac_tool. | 1110 # preprocessor do not affect the XML parser in mac_tool. |
1111 '@plutil -convert xml1 $@ $@']) | 1111 '@plutil -convert xml1 $@ $@']) |
1112 info_plist = intermediate_plist | 1112 info_plist = intermediate_plist |
1113 # plists can contain envvars and substitute them into the file. | 1113 # plists can contain envvars and substitute them into the file. |
1114 self.WriteXcodeEnv(out, self.GetXcodeEnv(additional_settings=extra_env)) | 1114 self.WriteSortedXcodeEnv( |
| 1115 out, self.GetSortedXcodeEnv(additional_settings=extra_env)) |
1115 self.WriteDoCmd([out], [info_plist], 'mac_tool,,,copy-info-plist', | 1116 self.WriteDoCmd([out], [info_plist], 'mac_tool,,,copy-info-plist', |
1116 part_of_all=True) | 1117 part_of_all=True) |
1117 bundle_deps.append(out) | 1118 bundle_deps.append(out) |
1118 | 1119 |
1119 | 1120 |
1120 def WriteSources(self, configs, deps, sources, | 1121 def WriteSources(self, configs, deps, sources, |
1121 extra_outputs, extra_link_deps, | 1122 extra_outputs, extra_link_deps, |
1122 part_of_all, precompiled_header): | 1123 part_of_all, precompiled_header): |
1123 """Write Makefile code for any 'sources' from the gyp input. | 1124 """Write Makefile code for any 'sources' from the gyp input. |
1124 These are source files necessary to build the current target. | 1125 These are source files necessary to build the current target. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 if self.flavor == 'mac': | 1442 if self.flavor == 'mac': |
1442 if target_postbuilds: | 1443 if target_postbuilds: |
1443 postbuilds.append('$(TARGET_POSTBUILDS_$(BUILDTYPE))') | 1444 postbuilds.append('$(TARGET_POSTBUILDS_$(BUILDTYPE))') |
1444 postbuilds.extend( | 1445 postbuilds.extend( |
1445 gyp.xcode_emulation.GetSpecPostbuildCommands(spec)) | 1446 gyp.xcode_emulation.GetSpecPostbuildCommands(spec)) |
1446 | 1447 |
1447 if postbuilds: | 1448 if postbuilds: |
1448 # Envvars may be referenced by TARGET_POSTBUILDS_$(BUILDTYPE), | 1449 # Envvars may be referenced by TARGET_POSTBUILDS_$(BUILDTYPE), |
1449 # so we must output its definition first, since we declare variables | 1450 # so we must output its definition first, since we declare variables |
1450 # using ":=". | 1451 # using ":=". |
1451 self.WriteXcodeEnv(self.output, self.GetXcodePostbuildEnv()) | 1452 self.WriteSortedXcodeEnv(self.output, self.GetSortedXcodePostbuildEnv()) |
1452 | 1453 |
1453 for configname in target_postbuilds: | 1454 for configname in target_postbuilds: |
1454 self.WriteLn('%s: TARGET_POSTBUILDS_%s := %s' % | 1455 self.WriteLn('%s: TARGET_POSTBUILDS_%s := %s' % |
1455 (QuoteSpaces(self.output), | 1456 (QuoteSpaces(self.output), |
1456 configname, | 1457 configname, |
1457 gyp.common.EncodePOSIXShellList(target_postbuilds[configname]))) | 1458 gyp.common.EncodePOSIXShellList(target_postbuilds[configname]))) |
1458 | 1459 |
1459 # Postbuilds expect to be run in the gyp file's directory, so insert an | 1460 # Postbuilds expect to be run in the gyp file's directory, so insert an |
1460 # implicit postbuild to cd to there. | 1461 # implicit postbuild to cd to there. |
1461 postbuilds.insert(0, gyp.common.EncodePOSIXShellList(['cd', self.path])) | 1462 postbuilds.insert(0, gyp.common.EncodePOSIXShellList(['cd', self.path])) |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 self.WriteLn('include $(BUILD_SHARED_LIBRARY)') | 1777 self.WriteLn('include $(BUILD_SHARED_LIBRARY)') |
1777 elif self.type == 'static_library': | 1778 elif self.type == 'static_library': |
1778 self.WriteLn('include $(BUILD_STATIC_LIBRARY)') | 1779 self.WriteLn('include $(BUILD_STATIC_LIBRARY)') |
1779 self.WriteLn() | 1780 self.WriteLn() |
1780 | 1781 |
1781 | 1782 |
1782 def WriteLn(self, text=''): | 1783 def WriteLn(self, text=''): |
1783 self.fp.write(text + '\n') | 1784 self.fp.write(text + '\n') |
1784 | 1785 |
1785 | 1786 |
1786 def GetXcodeEnv(self, additional_settings=None): | 1787 def GetSortedXcodeEnv(self, additional_settings=None): |
1787 return gyp.xcode_emulation.GetXcodeEnv( | 1788 return gyp.xcode_emulation.GetSortedXcodeEnv( |
1788 self.xcode_settings, "$(abs_builddir)", | 1789 self.xcode_settings, "$(abs_builddir)", |
1789 os.path.join("$(abs_srcdir)", self.path), "$(BUILDTYPE)", | 1790 os.path.join("$(abs_srcdir)", self.path), "$(BUILDTYPE)", |
1790 additional_settings) | 1791 additional_settings) |
1791 | 1792 |
1792 | 1793 |
1793 def GetXcodePostbuildEnv(self): | 1794 def GetSortedXcodePostbuildEnv(self): |
1794 # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack. | 1795 # CHROMIUM_STRIP_SAVE_FILE is a chromium-specific hack. |
1795 # TODO(thakis): It would be nice to have some general mechanism instead. | 1796 # TODO(thakis): It would be nice to have some general mechanism instead. |
1796 strip_save_file = self.xcode_settings.GetPerTargetSetting( | 1797 strip_save_file = self.xcode_settings.GetPerTargetSetting( |
1797 'CHROMIUM_STRIP_SAVE_FILE', '') | 1798 'CHROMIUM_STRIP_SAVE_FILE', '') |
1798 # Even if strip_save_file is empty, explicitly write it. Else a postbuild | 1799 # Even if strip_save_file is empty, explicitly write it. Else a postbuild |
1799 # might pick up an export from an earlier target. | 1800 # might pick up an export from an earlier target. |
1800 return self.GetXcodeEnv( | 1801 return self.GetSortedXcodeEnv( |
1801 additional_settings={'CHROMIUM_STRIP_SAVE_FILE': strip_save_file}) | 1802 additional_settings={'CHROMIUM_STRIP_SAVE_FILE': strip_save_file}) |
1802 | 1803 |
1803 | 1804 |
1804 def WriteXcodeEnv(self, target, env): | 1805 def WriteSortedXcodeEnv(self, target, env): |
1805 for k in gyp.xcode_emulation.TopologicallySortedEnvVarKeys(env): | 1806 for k, v in env: |
1806 # For | 1807 # For |
1807 # foo := a\ b | 1808 # foo := a\ b |
1808 # the escaped space does the right thing. For | 1809 # the escaped space does the right thing. For |
1809 # export foo := a\ b | 1810 # export foo := a\ b |
1810 # it does not -- the backslash is written to the env as literal character. | 1811 # it does not -- the backslash is written to the env as literal character. |
1811 # So don't escape spaces in |env[k]|. | 1812 # So don't escape spaces in |env[k]|. |
1812 self.WriteLn('%s: export %s := %s' % (QuoteSpaces(target), k, env[k])) | 1813 self.WriteLn('%s: export %s := %s' % (QuoteSpaces(target), k, v)) |
1813 | 1814 |
1814 | 1815 |
1815 def Objectify(self, path): | 1816 def Objectify(self, path): |
1816 """Convert a path to its output directory form.""" | 1817 """Convert a path to its output directory form.""" |
1817 if '$(' in path: | 1818 if '$(' in path: |
1818 path = path.replace('$(obj)/', '$(obj).%s/$(TARGET)/' % self.toolset) | 1819 path = path.replace('$(obj)/', '$(obj).%s/$(TARGET)/' % self.toolset) |
1819 return path | 1820 return path |
1820 return '$(obj).%s/$(TARGET)/%s' % (self.toolset, path) | 1821 return '$(obj).%s/$(TARGET)/%s' % (self.toolset, path) |
1821 | 1822 |
1822 | 1823 |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 root_makefile.write(" include " + include_file + "\n") | 2135 root_makefile.write(" include " + include_file + "\n") |
2135 root_makefile.write("endif\n") | 2136 root_makefile.write("endif\n") |
2136 root_makefile.write('\n') | 2137 root_makefile.write('\n') |
2137 | 2138 |
2138 if generator_flags.get('auto_regeneration', True): | 2139 if generator_flags.get('auto_regeneration', True): |
2139 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) | 2140 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) |
2140 | 2141 |
2141 root_makefile.write(SHARED_FOOTER) | 2142 root_makefile.write(SHARED_FOOTER) |
2142 | 2143 |
2143 root_makefile.close() | 2144 root_makefile.close() |
OLD | NEW |