OLD | NEW |
1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 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 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 if len(dirs) > 0: | 860 if len(dirs) > 0: |
861 command = 'mkdir -p %s' % ' '.join(dirs) + '; ' + command | 861 command = 'mkdir -p %s' % ' '.join(dirs) + '; ' + command |
862 | 862 |
863 cd_action = 'cd %s; ' % Sourceify(self.path or '.') | 863 cd_action = 'cd %s; ' % Sourceify(self.path or '.') |
864 | 864 |
865 # command and cd_action get written to a toplevel variable called | 865 # command and cd_action get written to a toplevel variable called |
866 # cmd_foo. Toplevel variables can't handle things that change per | 866 # cmd_foo. Toplevel variables can't handle things that change per |
867 # makefile like $(TARGET), so hardcode the target. | 867 # makefile like $(TARGET), so hardcode the target. |
868 command = command.replace('$(TARGET)', self.target) | 868 command = command.replace('$(TARGET)', self.target) |
869 cd_action = cd_action.replace('$(TARGET)', self.target) | 869 cd_action = cd_action.replace('$(TARGET)', self.target) |
| 870 target_libraries_path = self._TargetLibrariesPath() |
| 871 ld_library_path = self._LibraryPathVarName() |
870 | 872 |
871 # Set LD_LIBRARY_PATH in case the action runs an executable from this | 873 # Set LD_LIBRARY_PATH in case the action runs an executable from this |
872 # build which links to shared libs from this build. | 874 # build which links to shared libs from this build. |
873 # actions run on the host, so they should in theory only use host | 875 # actions run on the host, so they should in theory only use host |
874 # libraries, but until everything is made cross-compile safe, also use | 876 # libraries, but until everything is made cross-compile safe, also use |
875 # target libraries. | 877 # target libraries. |
876 # TODO(piman): when everything is cross-compile safe, remove lib.target | 878 # TODO(piman): when everything is cross-compile safe, remove lib.target |
877 self.WriteLn('cmd_%s = LD_LIBRARY_PATH=$(builddir)/lib.host:' | 879 self.WriteLn( |
878 '$(builddir)/lib.target:$$LD_LIBRARY_PATH; ' | 880 'cmd_%(name)s = %(ld_library_path)s=$(builddir)/lib.host:' |
879 'export LD_LIBRARY_PATH; ' | 881 '%(target_libraries_path)s:$$%(ld_library_path)s; ' |
880 '%s%s' | 882 'export %(ld_library_path)s; ' |
881 % (name, cd_action, command)) | 883 '%(cd_action)s%(command)s' % { |
| 884 'name': name, |
| 885 'cd_action': cd_action, |
| 886 'command': command, |
| 887 'target_libraries_path': target_libraries_path, |
| 888 'ld_library_path': ld_library_path}) |
882 self.WriteLn() | 889 self.WriteLn() |
883 outputs = map(self.Absolutify, outputs) | 890 outputs = map(self.Absolutify, outputs) |
884 # 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 |
885 # are defined relative to their containing dir. This replaces the obj | 892 # are defined relative to their containing dir. This replaces the obj |
886 # 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 |
887 # goes in the right place. | 894 # goes in the right place. |
888 # 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); |
889 # it's superfluous for the "extra outputs", and this avoids accidentally | 896 # it's superfluous for the "extra outputs", and this avoids accidentally |
890 # writing duplicate dummy rules for those outputs. | 897 # writing duplicate dummy rules for those outputs. |
891 # Same for environment. | 898 # Same for environment. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 # action, cd_action, and mkdirs get written to a toplevel variable | 1007 # action, cd_action, and mkdirs get written to a toplevel variable |
1001 # called cmd_foo. Toplevel variables can't handle things that change | 1008 # called cmd_foo. Toplevel variables can't handle things that change |
1002 # per makefile like $(TARGET), so hardcode the target. | 1009 # per makefile like $(TARGET), so hardcode the target. |
1003 if self.flavor == 'mac': | 1010 if self.flavor == 'mac': |
1004 action = [gyp.xcode_emulation.ExpandEnvVars(command, env) | 1011 action = [gyp.xcode_emulation.ExpandEnvVars(command, env) |
1005 for command in action] | 1012 for command in action] |
1006 action = gyp.common.EncodePOSIXShellList(action) | 1013 action = gyp.common.EncodePOSIXShellList(action) |
1007 action = action.replace('$(TARGET)', self.target) | 1014 action = action.replace('$(TARGET)', self.target) |
1008 cd_action = cd_action.replace('$(TARGET)', self.target) | 1015 cd_action = cd_action.replace('$(TARGET)', self.target) |
1009 mkdirs = mkdirs.replace('$(TARGET)', self.target) | 1016 mkdirs = mkdirs.replace('$(TARGET)', self.target) |
| 1017 target_libraries_path = self._TargetLibrariesPath() |
| 1018 ld_library_path = self._LibraryPathVarName() |
1010 | 1019 |
1011 # Set LD_LIBRARY_PATH in case the rule runs an executable from this | 1020 # Set LD_LIBRARY_PATH in case the rule runs an executable from this |
1012 # build which links to shared libs from this build. | 1021 # build which links to shared libs from this build. |
1013 # rules run on the host, so they should in theory only use host | 1022 # rules run on the host, so they should in theory only use host |
1014 # libraries, but until everything is made cross-compile safe, also use | 1023 # libraries, but until everything is made cross-compile safe, also use |
1015 # target libraries. | 1024 # target libraries. |
1016 # TODO(piman): when everything is cross-compile safe, remove lib.target | 1025 # TODO(piman): when everything is cross-compile safe, remove lib.target |
1017 self.WriteLn( | 1026 self.WriteLn( |
1018 "cmd_%(name)s_%(count)d = LD_LIBRARY_PATH=" | 1027 "cmd_%(name)s_%(count)d = %(ld_library_path)s=" |
1019 "$(builddir)/lib.host:$(builddir)/lib.target:$$LD_LIBRARY_PATH; " | 1028 "$(builddir)/lib.host:%(target_libraries_path)s:" |
1020 "export LD_LIBRARY_PATH; " | 1029 "$$%(ld_library_path)s; " |
| 1030 "export %(ld_library_path)s; " |
1021 "%(cd_action)s%(mkdirs)s%(action)s" % { | 1031 "%(cd_action)s%(mkdirs)s%(action)s" % { |
1022 'action': action, | 1032 'action': action, |
1023 'cd_action': cd_action, | 1033 'cd_action': cd_action, |
1024 'count': count, | 1034 'count': count, |
1025 'mkdirs': mkdirs, | 1035 'mkdirs': mkdirs, |
1026 'name': name, | 1036 'name': name, |
| 1037 'target_libraries_path': target_libraries_path, |
| 1038 'ld_library_path': ld_library_path, |
1027 }) | 1039 }) |
1028 self.WriteLn( | 1040 self.WriteLn( |
1029 'quiet_cmd_%(name)s_%(count)d = RULE %(name)s_%(count)d $@' % { | 1041 'quiet_cmd_%(name)s_%(count)d = RULE %(name)s_%(count)d $@' % { |
1030 'count': count, | 1042 'count': count, |
1031 'name': name, | 1043 'name': name, |
1032 }) | 1044 }) |
1033 self.WriteLn() | 1045 self.WriteLn() |
1034 count += 1 | 1046 count += 1 |
1035 | 1047 |
1036 outputs_variable = 'rule_%s_outputs' % name | 1048 outputs_variable = 'rule_%s_outputs' % name |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 # Xcode puts shared_library results into PRODUCT_DIR, and some gyp files | 1888 # Xcode puts shared_library results into PRODUCT_DIR, and some gyp files |
1877 # rely on this. Emulate this behavior for mac. | 1889 # rely on this. Emulate this behavior for mac. |
1878 if (self.type == 'shared_library' and | 1890 if (self.type == 'shared_library' and |
1879 (self.flavor != 'mac' or self.toolset != 'target')): | 1891 (self.flavor != 'mac' or self.toolset != 'target')): |
1880 # Install all shared libs into a common directory (per toolset) for | 1892 # Install all shared libs into a common directory (per toolset) for |
1881 # convenient access with LD_LIBRARY_PATH. | 1893 # convenient access with LD_LIBRARY_PATH. |
1882 return '$(builddir)/lib.%s/%s' % (self.toolset, self.alias) | 1894 return '$(builddir)/lib.%s/%s' % (self.toolset, self.alias) |
1883 return '$(builddir)/' + self.alias | 1895 return '$(builddir)/' + self.alias |
1884 | 1896 |
1885 | 1897 |
| 1898 def _TargetLibrariesPath(self): |
| 1899 """Returns the path to shared libraries in the "target" toolset.""" |
| 1900 if self.flavor == 'mac': |
| 1901 return '$(builddir)' |
| 1902 else: |
| 1903 return '$(builddir)/lib.target' |
| 1904 |
| 1905 def _LibraryPathVarName(self): |
| 1906 """Returns the name of the environment variables for shared libraries.""" |
| 1907 if self.flavor == 'mac': |
| 1908 return 'DYLD_LIBRARY_PATH' |
| 1909 else: |
| 1910 return 'LD_LIBRARY_PATH' |
| 1911 |
| 1912 |
1886 def WriteAutoRegenerationRule(params, root_makefile, makefile_name, | 1913 def WriteAutoRegenerationRule(params, root_makefile, makefile_name, |
1887 build_files): | 1914 build_files): |
1888 """Write the target to regenerate the Makefile.""" | 1915 """Write the target to regenerate the Makefile.""" |
1889 options = params['options'] | 1916 options = params['options'] |
1890 build_files_args = [gyp.common.RelativePath(filename, options.toplevel_dir) | 1917 build_files_args = [gyp.common.RelativePath(filename, options.toplevel_dir) |
1891 for filename in params['build_files_arg']] | 1918 for filename in params['build_files_arg']] |
1892 | 1919 |
1893 gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'], | 1920 gyp_binary = gyp.common.FixIfRelativePath(params['gyp_binary'], |
1894 options.toplevel_dir) | 1921 options.toplevel_dir) |
1895 if not gyp_binary.startswith(os.sep): | 1922 if not gyp_binary.startswith(os.sep): |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 root_makefile.write("endif\n") | 2177 root_makefile.write("endif\n") |
2151 root_makefile.write('\n') | 2178 root_makefile.write('\n') |
2152 | 2179 |
2153 if (not generator_flags.get('standalone') | 2180 if (not generator_flags.get('standalone') |
2154 and generator_flags.get('auto_regeneration', True)): | 2181 and generator_flags.get('auto_regeneration', True)): |
2155 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) | 2182 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) |
2156 | 2183 |
2157 root_makefile.write(SHARED_FOOTER) | 2184 root_makefile.write(SHARED_FOOTER) |
2158 | 2185 |
2159 root_makefile.close() | 2186 root_makefile.close() |
OLD | NEW |