Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Side by Side Diff: pylib/gyp/generator/make.py

Issue 10833021: Honor $CC/$CC_host and friends in make generator. (Closed) Base URL: http://git.chromium.org/external/gyp.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pylib/gyp/generator/ninja.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 generator_wants_sorted_dependencies = False 53 generator_wants_sorted_dependencies = False
54 54
55 # Placates pylint. 55 # Placates pylint.
56 generator_additional_non_configuration_keys = [] 56 generator_additional_non_configuration_keys = []
57 generator_additional_path_sections = [] 57 generator_additional_path_sections = []
58 generator_extra_sources_for_rules = [] 58 generator_extra_sources_for_rules = []
59 59
60 60
61 def CalculateVariables(default_variables, params): 61 def CalculateVariables(default_variables, params):
62 """Calculate additional variables for use in the build (called by gyp).""" 62 """Calculate additional variables for use in the build (called by gyp)."""
63 cc_target = os.environ.get('CC.target', os.environ.get('CC', 'cc'))
64 flavor = gyp.common.GetFlavor(params) 63 flavor = gyp.common.GetFlavor(params)
65 if flavor == 'mac': 64 if flavor == 'mac':
66 default_variables.setdefault('OS', 'mac') 65 default_variables.setdefault('OS', 'mac')
67 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib') 66 default_variables.setdefault('SHARED_LIB_SUFFIX', '.dylib')
68 default_variables.setdefault('SHARED_LIB_DIR', 67 default_variables.setdefault('SHARED_LIB_DIR',
69 generator_default_variables['PRODUCT_DIR']) 68 generator_default_variables['PRODUCT_DIR'])
70 default_variables.setdefault('LIB_DIR', 69 default_variables.setdefault('LIB_DIR',
71 generator_default_variables['PRODUCT_DIR']) 70 generator_default_variables['PRODUCT_DIR'])
72 71
73 # Copy additional generator configuration data from Xcode, which is shared 72 # Copy additional generator configuration data from Xcode, which is shared
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 # 247 #
249 # Note: flock is used to seralize linking. Linking is a memory-intensive 248 # Note: flock is used to seralize linking. Linking is a memory-intensive
250 # process so running parallel links can often lead to thrashing. To disable 249 # process so running parallel links can often lead to thrashing. To disable
251 # the serialization, override LINK via an envrionment variable as follows: 250 # the serialization, override LINK via an envrionment variable as follows:
252 # 251 #
253 # export LINK=g++ 252 # export LINK=g++
254 # 253 #
255 # This will allow make to invoke N linker processes as specified in -jN. 254 # This will allow make to invoke N linker processes as specified in -jN.
256 LINK ?= %(flock)s $(builddir)/linker.lock $(CXX) 255 LINK ?= %(flock)s $(builddir)/linker.lock $(CXX)
257 256
258 CC.target ?= $(CC) 257 CC.target ?= %(CC.target)s
259 CFLAGS.target ?= $(CFLAGS) 258 CFLAGS.target ?= $(CFLAGS)
260 CXX.target ?= $(CXX) 259 CXX.target ?= %(CXX.target)s
261 CXXFLAGS.target ?= $(CXXFLAGS) 260 CXXFLAGS.target ?= $(CXXFLAGS)
262 LINK.target ?= $(LINK) 261 LINK.target ?= %(LINK.target)s
263 LDFLAGS.target ?= $(LDFLAGS) 262 LDFLAGS.target ?= $(LDFLAGS)
264 AR.target ?= $(AR) 263 AR.target ?= $(AR)
265 ARFLAGS.target ?= %(ARFLAGS.target)s 264 ARFLAGS.target ?= %(ARFLAGS.target)s
266 265
267 # N.B.: the logic of which commands to run should match the computation done 266 # N.B.: the logic of which commands to run should match the computation done
268 # in gyp's make.py where ARFLAGS.host etc. is computed. 267 # in gyp's make.py where ARFLAGS.host etc. is computed.
269 # TODO(evan): move all cross-compilation logic to gyp-time so we don't need 268 # TODO(evan): move all cross-compilation logic to gyp-time so we don't need
270 # to replicate this environment fallback in make as well. 269 # to replicate this environment fallback in make as well.
271 CC.host ?= gcc 270 CC.host ?= %(CC.host)s
272 CFLAGS.host ?= 271 CFLAGS.host ?=
273 CXX.host ?= g++ 272 CXX.host ?= %(CXX.host)s
274 CXXFLAGS.host ?= 273 CXXFLAGS.host ?=
275 LINK.host ?= g++ 274 LINK.host ?= %(LINK.host)s
276 LDFLAGS.host ?= 275 LDFLAGS.host ?=
277 AR.host ?= ar 276 AR.host ?= %(AR.host)s
278 ARFLAGS.host := %(ARFLAGS.host)s 277 ARFLAGS.host := %(ARFLAGS.host)s
279 278
280 # Define a dir function that can handle spaces. 279 # Define a dir function that can handle spaces.
281 # http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions 280 # http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
282 # "leading spaces cannot appear in the text of the first argument as written. 281 # "leading spaces cannot appear in the text of the first argument as written.
283 # These characters can be put into the argument value by variable substitution." 282 # These characters can be put into the argument value by variable substitution."
284 empty := 283 empty :=
285 space := $(empty) $(empty) 284 space := $(empty) $(empty)
286 285
287 # http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path- with-spaces 286 # http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path- with-spaces
(...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 """Run tests against the system to compute default settings for commands. 1884 """Run tests against the system to compute default settings for commands.
1886 1885
1887 Returns: 1886 Returns:
1888 dictionary of settings matching the block of command-lines used in 1887 dictionary of settings matching the block of command-lines used in
1889 SHARED_HEADER. E.g. the dictionary will contain a ARFLAGS.target 1888 SHARED_HEADER. E.g. the dictionary will contain a ARFLAGS.target
1890 key for the default ARFLAGS for the target ar command. 1889 key for the default ARFLAGS for the target ar command.
1891 """ 1890 """
1892 # Compute flags used for building static archives. 1891 # Compute flags used for building static archives.
1893 # N.B.: this fallback logic should match the logic in SHARED_HEADER. 1892 # N.B.: this fallback logic should match the logic in SHARED_HEADER.
1894 # See comment there for more details. 1893 # See comment there for more details.
1895 ar_target = os.environ.get('AR.target', os.environ.get('AR', 'ar')) 1894 ar_target = GetEnv(('AR_target', 'AR'), 'ar')
1896 cc_target = os.environ.get('CC.target', os.environ.get('CC', 'cc')) 1895 cc_target = GetEnv(('CC_target', 'CC'), 'cc')
1897 arflags_target = 'crs' 1896 arflags_target = 'crs'
1898 # ar -T enables thin archives on Linux. OS X's ar supports a -T flag, but it 1897 # ar -T enables thin archives on Linux. OS X's ar supports a -T flag, but it
1899 # does something useless (it limits filenames in the archive to 15 chars). 1898 # does something useless (it limits filenames in the archive to 15 chars).
1900 if flavor != 'mac' and gyp.system_test.TestArSupportsT(ar_command=ar_target, 1899 if flavor != 'mac' and gyp.system_test.TestArSupportsT(ar_command=ar_target,
1901 cc_command=cc_target): 1900 cc_command=cc_target):
1902 arflags_target = 'crsT' 1901 arflags_target = 'crsT'
1903 1902
1904 ar_host = os.environ.get('AR.host', 'ar') 1903 ar_host = os.environ.get('AR_host', 'ar')
1905 cc_host = os.environ.get('CC.host', 'gcc') 1904 cc_host = os.environ.get('CC_host', 'gcc')
1906 arflags_host = 'crs' 1905 arflags_host = 'crs'
1907 # It feels redundant to compute this again given that most builds aren't 1906 # It feels redundant to compute this again given that most builds aren't
1908 # cross-compiles, but due to quirks of history CC.host defaults to 'gcc' 1907 # cross-compiles, but due to quirks of history CC_host defaults to 'gcc'
1909 # while CC.target defaults to 'cc', so the commands really are different 1908 # while CC_target defaults to 'cc', so the commands really are different
1910 # even though they're nearly guaranteed to run the same code underneath. 1909 # even though they're nearly guaranteed to run the same code underneath.
1911 if flavor != 'mac' and gyp.system_test.TestArSupportsT(ar_command=ar_host, 1910 if flavor != 'mac' and gyp.system_test.TestArSupportsT(ar_command=ar_host,
1912 cc_command=cc_host): 1911 cc_command=cc_host):
1913 arflags_host = 'crsT' 1912 arflags_host = 'crsT'
1914 1913
1915 return { 'ARFLAGS.target': arflags_target, 1914 return { 'ARFLAGS.target': arflags_target,
1916 'ARFLAGS.host': arflags_host } 1915 'ARFLAGS.host': arflags_host }
1917 1916
1918 1917
1918 def GetEnv(possible_keys, default):
1919 """Look up a key in the environment, falling back to a secondary key
1920 and finally falling back to a default value."""
1921 for key in possible_keys:
1922 if key in os.environ:
1923 return os.environ[key]
1924
1925 return default
1926
1919 def GenerateOutput(target_list, target_dicts, data, params): 1927 def GenerateOutput(target_list, target_dicts, data, params):
1920 options = params['options'] 1928 options = params['options']
1921 flavor = gyp.common.GetFlavor(params) 1929 flavor = gyp.common.GetFlavor(params)
1922 generator_flags = params.get('generator_flags', {}) 1930 generator_flags = params.get('generator_flags', {})
1923 builddir_name = generator_flags.get('output_dir', 'out') 1931 builddir_name = generator_flags.get('output_dir', 'out')
1924 android_ndk_version = generator_flags.get('android_ndk_version', None) 1932 android_ndk_version = generator_flags.get('android_ndk_version', None)
1925 default_target = generator_flags.get('default_target', 'all') 1933 default_target = generator_flags.get('default_target', 'all')
1926 1934
1927 def CalculateMakefilePath(build_file, base_name): 1935 def CalculateMakefilePath(build_file, base_name):
1928 """Determine where to write a Makefile for a given gyp file.""" 1936 """Determine where to write a Makefile for a given gyp file."""
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 elif flavor == 'solaris': 1996 elif flavor == 'solaris':
1989 header_params.update({ 1997 header_params.update({
1990 'flock': './gyp-sun-tool flock', 1998 'flock': './gyp-sun-tool flock',
1991 'flock_index': 2, 1999 'flock_index': 2,
1992 'extra_commands': SHARED_HEADER_SUN_COMMANDS, 2000 'extra_commands': SHARED_HEADER_SUN_COMMANDS,
1993 }) 2001 })
1994 elif flavor == 'freebsd': 2002 elif flavor == 'freebsd':
1995 header_params.update({ 2003 header_params.update({
1996 'flock': 'lockf', 2004 'flock': 'lockf',
1997 }) 2005 })
2006
1998 header_params.update(RunSystemTests(flavor)) 2007 header_params.update(RunSystemTests(flavor))
2008 header_params.update({
2009 'CC.target': GetEnv(('CC_target', 'CC'), '$(CC)'),
2010 'AR.target': GetEnv(('AR_target', 'AR'), '$(AR)'),
2011 'CXX.target': GetEnv(('CXX_target', 'CXX'), '$(CXX)'),
2012 'LINK.target': GetEnv(('LD_target', 'LD'), '$(LINK)'),
Nico 2012/08/08 21:26:08 If I understood michaelbai right, the _target stuf
Sam Clegg 2012/08/10 00:43:58 I will remove this.
2013 'CC.host': GetEnv(('CC_host',), 'gcc'),
2014 'AR.host': GetEnv(('AR_host',), 'ar'),
2015 'CXX.host': GetEnv(('CXX_host',), 'g++'),
2016 'LINK.host': GetEnv(('LD_host',), 'g++'),
Nico 2012/08/08 21:26:08 This part is fine, but it's overridden by make_glo
2017 })
1999 2018
2000 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) 2019 build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0])
2001 make_global_settings_dict = data[build_file].get('make_global_settings', {}) 2020 make_global_settings_dict = data[build_file].get('make_global_settings', {})
2002 make_global_settings = '' 2021 make_global_settings = ''
2003 for key, value in make_global_settings_dict: 2022 for key, value in make_global_settings_dict:
2004 if value[0] != '$': 2023 if value[0] != '$':
2005 value = '$(abspath %s)' % value 2024 value = '$(abspath %s)' % value
2006 if key == 'LINK': 2025 if key == 'LINK':
2007 make_global_settings += ('%s ?= %s $(builddir)/linker.lock %s\n' % 2026 make_global_settings += ('%s ?= %s $(builddir)/linker.lock %s\n' %
2008 (key, flock_command, value)) 2027 (key, flock_command, value))
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 root_makefile.write(" include " + include_file + "\n") 2143 root_makefile.write(" include " + include_file + "\n")
2125 root_makefile.write("endif\n") 2144 root_makefile.write("endif\n")
2126 root_makefile.write('\n') 2145 root_makefile.write('\n')
2127 2146
2128 if generator_flags.get('auto_regeneration', True): 2147 if generator_flags.get('auto_regeneration', True):
2129 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files) 2148 WriteAutoRegenerationRule(params, root_makefile, makefile_name, build_files)
2130 2149
2131 root_makefile.write(SHARED_FOOTER) 2150 root_makefile.write(SHARED_FOOTER)
2132 2151
2133 root_makefile.close() 2152 root_makefile.close()
OLDNEW
« no previous file with comments | « no previous file | pylib/gyp/generator/ninja.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698