Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / gyp / pylib / gyp / generator / android.py
index 5d8c74e..4129b8e 100644 (file)
@@ -50,6 +50,8 @@ generator_supports_multiple_toolsets = True
 generator_additional_non_configuration_keys = [
     # Boolean to declare that this target does not want its name mangled.
     'android_unmangled_name',
+    # Map of android build system variables to set.
+    'aosp_build_settings',
 ]
 generator_additional_path_sections = []
 generator_extra_sources_for_rules = []
@@ -66,33 +68,6 @@ header = """\
 
 """
 
-android_standard_include_paths = set([
-    # JNI_H_INCLUDE in build/core/binary.mk
-    'dalvik/libnativehelper/include/nativehelper',
-    # from SRC_HEADERS in build/core/config.mk
-    'system/core/include',
-    'hardware/libhardware/include',
-    'hardware/libhardware_legacy/include',
-    'hardware/ril/include',
-    'dalvik/libnativehelper/include',
-    'frameworks/native/include',
-    'frameworks/native/opengl/include',
-    'frameworks/base/include',
-    'frameworks/base/opengl/include',
-    'frameworks/base/native/include',
-    'external/skia/include',
-    # TARGET_C_INCLUDES in build/core/combo/TARGET_linux-arm.mk
-    'bionic/libc/arch-arm/include',
-    'bionic/libc/include',
-    'bionic/libstdc++/include',
-    'bionic/libc/kernel/common',
-    'bionic/libc/kernel/arch-arm',
-    'bionic/libm/include',
-    'bionic/libm/include/arm',
-    'bionic/libthread_db/include',
-    ])
-
-
 # Map gyp target types to Android module classes.
 MODULE_CLASSES = {
     'static_library': 'STATIC_LIBRARIES',
@@ -133,7 +108,7 @@ class AndroidMkWriter(object):
     self.android_top_dir = android_top_dir
 
   def Write(self, qualified_target, relative_target, base_path, output_filename,
-            spec, configs, part_of_all, write_alias_target):
+            spec, configs, part_of_all, write_alias_target, sdk_version):
     """The main entry point: writes a .mk file for a single target.
 
     Arguments:
@@ -146,6 +121,7 @@ class AndroidMkWriter(object):
       part_of_all: flag indicating this target is part of 'all'
       write_alias_target: flag indicating whether to create short aliases for
                           this target
+      sdk_version: what to emit for LOCAL_SDK_VERSION in output
     """
     gyp.common.EnsureDirExists(output_filename)
 
@@ -185,17 +161,18 @@ class AndroidMkWriter(object):
     if self.android_stem != self.android_module:
       self.WriteLn('LOCAL_MODULE_STEM := ' + self.android_stem)
     self.WriteLn('LOCAL_MODULE_SUFFIX := ' + self.android_suffix)
-    self.WriteLn('LOCAL_MODULE_TAGS := optional')
     if self.toolset == 'host':
       self.WriteLn('LOCAL_IS_HOST_MODULE := true')
+      self.WriteLn('LOCAL_MULTILIB := $(GYP_HOST_MULTILIB)')
     else:
       self.WriteLn('LOCAL_MODULE_TARGET_ARCH := '
                    '$(TARGET_$(GYP_VAR_PREFIX)ARCH)')
+      self.WriteLn('LOCAL_SDK_VERSION := %s' % sdk_version)
 
     # Grab output directories; needed for Actions and Rules.
     if self.toolset == 'host':
       self.WriteLn('gyp_intermediate_dir := '
-                   '$(call local-intermediates-dir)')
+                   '$(call local-intermediates-dir,,$(GYP_HOST_VAR_PREFIX))')
     else:
       self.WriteLn('gyp_intermediate_dir := '
                    '$(call local-intermediates-dir,,$(GYP_VAR_PREFIX))')
@@ -694,14 +671,15 @@ class AndroidMkWriter(object):
       path = '$(gyp_shared_intermediate_dir)'
     elif self.type == 'shared_library':
       if self.toolset == 'host':
-        path = '$(HOST_OUT_INTERMEDIATE_LIBRARIES)'
+        path = '$($(GYP_HOST_VAR_PREFIX)HOST_OUT_INTERMEDIATE_LIBRARIES)'
       else:
         path = '$($(GYP_VAR_PREFIX)TARGET_OUT_INTERMEDIATE_LIBRARIES)'
     else:
       # Other targets just get built into their intermediate dir.
       if self.toolset == 'host':
-        path = '$(call intermediates-dir-for,%s,%s,true)' % (self.android_class,
-                                                            self.android_module)
+        path = ('$(call intermediates-dir-for,%s,%s,true,,'
+                '$(GYP_HOST_VAR_PREFIX))' % (self.android_class,
+                                             self.android_module))
       else:
         path = ('$(call intermediates-dir-for,%s,%s,,,$(GYP_VAR_PREFIX))'
                 % (self.android_class, self.android_module))
@@ -711,9 +689,7 @@ class AndroidMkWriter(object):
 
   def NormalizeIncludePaths(self, include_paths):
     """ Normalize include_paths.
-    Convert absolute paths to relative to the Android top directory;
-    filter out include paths that are already brought in by the Android build
-    system.
+    Convert absolute paths to relative to the Android top directory.
 
     Args:
       include_paths: A list of unprocessed include paths.
@@ -724,10 +700,7 @@ class AndroidMkWriter(object):
     for path in include_paths:
       if path[0] == '/':
         path = gyp.common.RelativePath(path, self.android_top_dir)
-
-      # Filter out the Android standard search path.
-      if path not in android_standard_include_paths:
-        normalized.append(path)
+      normalized.append(path)
     return normalized
 
   def ExtractIncludesFromCFlags(self, cflags):
@@ -748,16 +721,20 @@ class AndroidMkWriter(object):
 
     return (clean_cflags, include_paths)
 
-  def ComputeAndroidLibraryModuleNames(self, libraries):
-    """Compute the Android module names from libraries, ie spec.get('libraries')
+  def FilterLibraries(self, libraries):
+    """Filter the 'libraries' key to separate things that shouldn't be ldflags.
+
+    Library entries that look like filenames should be converted to android
+    module names instead of being passed to the linker as flags.
 
     Args:
       libraries: the value of spec.get('libraries')
     Returns:
-      A tuple (static_lib_modules, dynamic_lib_modules)
+      A tuple (static_lib_modules, dynamic_lib_modules, ldflags)
     """
     static_lib_modules = []
     dynamic_lib_modules = []
+    ldflags = []
     for libs in libraries:
       # Libs can have multiple words.
       for lib in libs.split():
@@ -774,13 +751,9 @@ class AndroidMkWriter(object):
         if match:
           dynamic_lib_modules.append(match.group(1))
           continue
-        # "-lstlport" -> libstlport
         if lib.startswith('-l'):
-          if lib.endswith('_static'):
-            static_lib_modules.append('lib' + lib[2:])
-          else:
-            dynamic_lib_modules.append('lib' + lib[2:])
-    return (static_lib_modules, dynamic_lib_modules)
+          ldflags.append(lib)
+    return (static_lib_modules, dynamic_lib_modules, ldflags)
 
 
   def ComputeDeps(self, spec):
@@ -808,28 +781,42 @@ class AndroidMkWriter(object):
     spec, configs: input from gyp.
     link_deps: link dependency list; see ComputeDeps()
     """
-    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)
+    # These must be included even for static libraries as some of them provide
+    # implicit include paths through the build system.
     libraries = gyp.common.uniquer(spec.get('libraries', []))
-    static_libs, dynamic_libs = self.ComputeAndroidLibraryModuleNames(
-        libraries)
-
-    # Link dependencies (i.e. libfoo.a, libfoo.so)
-    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_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_libs + shared_link_deps,
-                   'LOCAL_SHARED_LIBRARIES')
+    static_libs, dynamic_libs, ldflags_libs = self.FilterLibraries(libraries)
+
+    if self.type != 'static_library':
+      for configname, config in sorted(configs.iteritems()):
+        ldflags = list(config.get('ldflags', []))
+        self.WriteLn('')
+        self.WriteList(ldflags, 'LOCAL_LDFLAGS_%s' % configname)
+      self.WriteList(ldflags_libs, 'LOCAL_GYP_LIBS')
+      self.WriteLn('LOCAL_LDFLAGS := $(LOCAL_LDFLAGS_$(GYP_CONFIGURATION)) '
+                   '$(LOCAL_GYP_LIBS)')
+
+    # Link dependencies (i.e. other gyp targets this target depends on)
+    # These need not be included for static libraries as within the gyp build
+    # we do not use the implicit include path mechanism.
+    if self.type != 'static_library':
+      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']
+    else:
+      static_link_deps = []
+      shared_link_deps = []
+
+    # Only write the lists if they are non-empty.
+    if static_libs or static_link_deps:
+      self.WriteLn('')
+      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')
+    if dynamic_libs or shared_link_deps:
+      self.WriteLn('')
+      self.WriteList(dynamic_libs + shared_link_deps,
+                     'LOCAL_SHARED_LIBRARIES')
 
 
   def WriteTarget(self, spec, configs, deps, link_deps, part_of_all,
@@ -847,6 +834,16 @@ class AndroidMkWriter(object):
     if self.type != 'none':
       self.WriteTargetFlags(spec, configs, link_deps)
 
+    settings = spec.get('aosp_build_settings', {})
+    if settings:
+      self.WriteLn('### Set directly by aosp_build_settings.')
+      for k, v in settings.iteritems():
+        if isinstance(v, list):
+          self.WriteList(v, k)
+        else:
+          self.WriteLn('%s := %s' % (k, make.QuoteIfNecessary(v)))
+      self.WriteLn('')
+
     # Add to the set of targets which represent the gyp 'all' target. We use the
     # name 'gyp_all_modules' as the Android build system doesn't allow the use
     # of the Make target 'all' and because 'all_modules' is the equivalent of
@@ -887,6 +884,8 @@ class AndroidMkWriter(object):
       self.WriteLn('LOCAL_UNINSTALLABLE_MODULE := true')
       if self.toolset == 'target':
         self.WriteLn('LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_VAR_PREFIX)')
+      else:
+        self.WriteLn('LOCAL_2ND_ARCH_VAR_PREFIX := $(GYP_HOST_VAR_PREFIX)')
       self.WriteLn()
       self.WriteLn('include $(BUILD_SYSTEM)/base_rules.mk')
       self.WriteLn()
@@ -894,9 +893,8 @@ class AndroidMkWriter(object):
       self.WriteLn('\t$(hide) echo "Gyp timestamp: $@"')
       self.WriteLn('\t$(hide) mkdir -p $(dir $@)')
       self.WriteLn('\t$(hide) touch $@')
-      if self.toolset == 'target':
-        self.WriteLn()
-        self.WriteLn('LOCAL_2ND_ARCH_VAR_PREFIX :=')
+      self.WriteLn()
+      self.WriteLn('LOCAL_2ND_ARCH_VAR_PREFIX :=')
 
 
   def WriteList(self, value_list, variable=None, prefix='',
@@ -967,6 +965,7 @@ def GenerateOutput(target_list, target_dicts, data, params):
   builddir_name = generator_flags.get('output_dir', 'out')
   limit_to_target_all = generator_flags.get('limit_to_target_all', False)
   write_alias_targets = generator_flags.get('write_alias_targets', True)
+  sdk_version = generator_flags.get('aosp_sdk_version', 19)
   android_top_dir = os.environ.get('ANDROID_BUILD_TOP')
   assert android_top_dir, '$ANDROID_BUILD_TOP not set; you need to run lunch.'
 
@@ -1063,7 +1062,8 @@ def GenerateOutput(target_list, target_dicts, data, params):
     android_module = writer.Write(qualified_target, relative_target, base_path,
                                   output_file, spec, configs,
                                   part_of_all=part_of_all,
-                                  write_alias_target=write_alias_targets)
+                                  write_alias_target=write_alias_targets,
+                                  sdk_version=sdk_version)
     if android_module in android_modules:
       print ('ERROR: Android module names must be unique. The following '
              'targets both generate Android module name %s.\n  %s\n  %s' %
@@ -1080,6 +1080,8 @@ def GenerateOutput(target_list, target_dicts, data, params):
 
   root_makefile.write('GYP_CONFIGURATION ?= %s\n' % default_configuration)
   root_makefile.write('GYP_VAR_PREFIX ?=\n')
+  root_makefile.write('GYP_HOST_VAR_PREFIX ?=\n')
+  root_makefile.write('GYP_HOST_MULTILIB ?=\n')
 
   # Write out the sorted list of includes.
   root_makefile.write('\n')