diff options
Diffstat (limited to 'tools/gyp/pylib/gyp/generator/android.py')
-rw-r--r-- | tools/gyp/pylib/gyp/generator/android.py | 128 |
1 files changed, 49 insertions, 79 deletions
diff --git a/tools/gyp/pylib/gyp/generator/android.py b/tools/gyp/pylib/gyp/generator/android.py index a01ead020d..9476a1df69 100644 --- a/tools/gyp/pylib/gyp/generator/android.py +++ b/tools/gyp/pylib/gyp/generator/android.py @@ -39,7 +39,7 @@ generator_default_variables = { 'RULE_INPUT_PATH': '$(RULE_SOURCES)', 'RULE_INPUT_EXT': '$(suffix $<)', 'RULE_INPUT_NAME': '$(notdir $<)', - 'CONFIGURATION_NAME': '$(GYP_DEFAULT_CONFIGURATION)', + 'CONFIGURATION_NAME': '$(GYP_CONFIGURATION)', } # Make supports multiple toolsets @@ -292,11 +292,9 @@ class AndroidMkWriter(object): main_output = make.QuoteSpaces(self.LocalPathify(outputs[0])) self.WriteLn('%s: gyp_local_path := $(LOCAL_PATH)' % main_output) self.WriteLn('%s: gyp_intermediate_dir := ' - '$(GYP_ABS_ANDROID_TOP_DIR)/$(gyp_intermediate_dir)' % - main_output) + '$(abspath $(gyp_intermediate_dir))' % main_output) self.WriteLn('%s: gyp_shared_intermediate_dir := ' - '$(GYP_ABS_ANDROID_TOP_DIR)/$(gyp_shared_intermediate_dir)' % - main_output) + '$(abspath $(gyp_shared_intermediate_dir))' % main_output) # Android's envsetup.sh adds a number of directories to the path including # the built host binary directory. This causes actions/rules invoked by @@ -394,11 +392,9 @@ class AndroidMkWriter(object): main_output = outputs[0] self.WriteLn('%s: gyp_local_path := $(LOCAL_PATH)' % main_output) self.WriteLn('%s: gyp_intermediate_dir := ' - '$(GYP_ABS_ANDROID_TOP_DIR)/$(gyp_intermediate_dir)' - % main_output) + '$(abspath $(gyp_intermediate_dir))' % main_output) self.WriteLn('%s: gyp_shared_intermediate_dir := ' - '$(GYP_ABS_ANDROID_TOP_DIR)/$(gyp_shared_intermediate_dir)' - % main_output) + '$(abspath $(gyp_shared_intermediate_dir))' % main_output) # See explanation in WriteActions. self.WriteLn('%s: export PATH := ' @@ -413,7 +409,9 @@ class AndroidMkWriter(object): (main_output, main_output_deps)) self.WriteLn('\t%s\n' % command) for output in outputs[1:]: - self.WriteLn('%s: %s' % (output, main_output)) + # Make each output depend on the main output, with an empty command + # to force make to notice that the mtime has changed. + self.WriteLn('%s: %s ;' % (output, main_output)) self.WriteLn('.PHONY: %s' % (rule_trigger)) self.WriteLn('%s: %s' % (rule_trigger, main_output)) self.WriteLn('') @@ -470,42 +468,39 @@ class AndroidMkWriter(object): Args: spec, configs: input from gyp. """ - config = configs[spec['default_configuration']] - extracted_includes = [] - - self.WriteLn('\n# Flags passed to both C and C++ files.') - cflags, includes_from_cflags = self.ExtractIncludesFromCFlags( - config.get('cflags')) - extracted_includes.extend(includes_from_cflags) - self.WriteList(cflags, 'MY_CFLAGS') - - cflags_c, includes_from_cflags_c = self.ExtractIncludesFromCFlags( - config.get('cflags_c')) - extracted_includes.extend(includes_from_cflags_c) - self.WriteList(cflags_c, 'MY_CFLAGS_C') - - self.WriteList(config.get('defines'), 'MY_DEFS', prefix='-D', - quoter=make.EscapeCppDefine) - self.WriteLn('LOCAL_CFLAGS := $(MY_CFLAGS_C) $(MY_CFLAGS) $(MY_DEFS)') - + for configname, config in sorted(configs.iteritems()): + extracted_includes = [] + + self.WriteLn('\n# Flags passed to both C and C++ files.') + cflags, includes_from_cflags = self.ExtractIncludesFromCFlags( + config.get('cflags', []) + config.get('cflags_c', [])) + extracted_includes.extend(includes_from_cflags) + self.WriteList(cflags, 'MY_CFLAGS_%s' % configname) + + self.WriteList(config.get('defines'), 'MY_DEFS_%s' % configname, + prefix='-D', quoter=make.EscapeCppDefine) + + self.WriteLn('\n# Include paths placed before CFLAGS/CPPFLAGS') + includes = list(config.get('include_dirs', [])) + includes.extend(extracted_includes) + includes = map(Sourceify, map(self.LocalPathify, includes)) + includes = self.NormalizeIncludePaths(includes) + self.WriteList(includes, 'LOCAL_C_INCLUDES_%s' % configname) + + self.WriteLn('\n# Flags passed to only C++ (and not C) files.') + self.WriteList(config.get('cflags_cc'), 'LOCAL_CPPFLAGS_%s' % configname) + + self.WriteLn('\nLOCAL_CFLAGS := $(MY_CFLAGS_$(GYP_CONFIGURATION)) ' + '$(MY_DEFS_$(GYP_CONFIGURATION))') # Undefine ANDROID for host modules - # TODO: the source code should not use macro ANDROID to tell if it's host or - # target module. + # TODO: the source code should not use macro ANDROID to tell if it's host + # or target module. if self.toolset == 'host': self.WriteLn('# Undefine ANDROID for host modules') self.WriteLn('LOCAL_CFLAGS += -UANDROID') - - self.WriteLn('\n# Include paths placed before CFLAGS/CPPFLAGS') - includes = list(config.get('include_dirs', [])) - includes.extend(extracted_includes) - includes = map(Sourceify, map(self.LocalPathify, includes)) - includes = self.NormalizeIncludePaths(includes) - self.WriteList(includes, 'LOCAL_C_INCLUDES') self.WriteLn('LOCAL_C_INCLUDES := $(GYP_COPIED_SOURCE_ORIGIN_DIRS) ' - '$(LOCAL_C_INCLUDES)') - - self.WriteLn('\n# Flags passed to only C++ (and not C) files.') - self.WriteList(config.get('cflags_cc'), 'LOCAL_CPPFLAGS') + '$(LOCAL_C_INCLUDES_$(GYP_CONFIGURATION))') + self.WriteLn('LOCAL_CPPFLAGS := $(LOCAL_CPPFLAGS_$(GYP_CONFIGURATION))') def WriteSources(self, spec, configs, extra_sources): @@ -698,24 +693,6 @@ class AndroidMkWriter(object): assert spec.get('product_dir') is None # TODO: not supported? return os.path.join(path, self.ComputeOutputBasename(spec)) - - def NormalizeLdFlags(self, ld_flags): - """ Clean up ldflags from gyp file. - Remove any ldflags that contain android_top_dir. - - Args: - ld_flags: ldflags from gyp files. - - Returns: - clean ldflags - """ - clean_ldflags = [] - for flag in ld_flags: - if self.android_top_dir in flag: - continue - clean_ldflags.append(flag) - return clean_ldflags - def NormalizeIncludePaths(self, include_paths): """ Normalize include_paths. Convert absolute paths to relative to the Android top directory; @@ -747,12 +724,11 @@ class AndroidMkWriter(object): """ clean_cflags = [] include_paths = [] - if cflags: - for flag in cflags: - if flag.startswith('-I'): - include_paths.append(flag[2:]) - else: - clean_cflags.append(flag) + for flag in cflags: + if flag.startswith('-I'): + include_paths.append(flag[2:]) + else: + clean_cflags.append(flag) return (clean_cflags, include_paths) @@ -816,14 +792,11 @@ class AndroidMkWriter(object): spec, configs: input from gyp. link_deps: link dependency list; see ComputeDeps() """ - config = configs[spec['default_configuration']] - - # LDFLAGS - ldflags = list(config.get('ldflags', [])) - static_flags, dynamic_flags = self.ComputeAndroidLibraryModuleNames( - ldflags) - self.WriteLn('') - self.WriteList(self.NormalizeLdFlags(ldflags), 'LOCAL_LDFLAGS') + for configname, config in sorted(configs.iteritems()): + ldflags = list(config.get('ldflags', [])) + self.WriteLn('') + self.WriteList(ldflags, 'LOCAL_LDFLAGS_%s' % configname) + self.WriteLn('\nLOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION))') # Libraries (i.e. -lfoo) libraries = gyp.common.uniquer(spec.get('libraries', [])) @@ -834,12 +807,12 @@ class AndroidMkWriter(object): static_link_deps = [x[1] for x in link_deps if x[0] == 'static'] shared_link_deps = [x[1] for x in link_deps if x[0] == 'shared'] self.WriteLn('') - self.WriteList(static_flags + static_libs + static_link_deps, + self.WriteList(static_libs + static_link_deps, 'LOCAL_STATIC_LIBRARIES') self.WriteLn('# Enable grouping to fix circular references') self.WriteLn('LOCAL_GROUP_STATIC_LIBRARIES := true') self.WriteLn('') - self.WriteList(dynamic_flags + dynamic_libs + shared_link_deps, + self.WriteList(dynamic_libs + shared_link_deps, 'LOCAL_SHARED_LIBRARIES') @@ -1083,10 +1056,7 @@ def GenerateOutput(target_list, target_dicts, data, params): os.path.dirname(makefile_path)) include_list.add(mkfile_rel_path) - # Some tools need to know the absolute path of the top directory. - root_makefile.write('GYP_ABS_ANDROID_TOP_DIR := $(shell pwd)\n') - root_makefile.write('GYP_DEFAULT_CONFIGURATION := %s\n' % - default_configuration) + root_makefile.write('GYP_CONFIGURATION ?= %s\n' % default_configuration) # Write out the sorted list of includes. root_makefile.write('\n') |