Prepare skia for shared library build on android

This reapplies revision 9378 after the buildbot has been updated.

R=borenet@google.com, djsollen@google.com

Review URL: https://codereview.chromium.org/15855006

git-svn-id: http://skia.googlecode.com/svn/trunk/gyp@9395 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/FileReaderApp.gyp b/FileReaderApp.gyp
index bcd0f0d..f590ffe 100644
--- a/FileReaderApp.gyp
+++ b/FileReaderApp.gyp
@@ -18,8 +18,7 @@
         '../src/utils/mac/SkOSWindow_Mac.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'views.gyp:views',
         'xml.gyp:xml',
       ],
diff --git a/SampleApp.gyp b/SampleApp.gyp
index 5531605..59d2f84 100644
--- a/SampleApp.gyp
+++ b/SampleApp.gyp
@@ -142,9 +142,7 @@
         '../samplecode/SampleFontCache.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'views.gyp:views',
         'animator.gyp:animator',
         'xml.gyp:xml',
diff --git a/SimpleCocoaApp.gyp b/SimpleCocoaApp.gyp
index 3e17ad5..6d7b925 100644
--- a/SimpleCocoaApp.gyp
+++ b/SimpleCocoaApp.gyp
@@ -25,7 +25,7 @@
 
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
         'views.gyp:views',
         'xml.gyp:xml',
       ],
diff --git a/SimpleiOSApp.gyp b/SimpleiOSApp.gyp
index 3678e7c..cb00f81 100644
--- a/SimpleiOSApp.gyp
+++ b/SimpleiOSApp.gyp
@@ -28,9 +28,7 @@
         '../experimental/SimpleiOSApp/SimpleiOSApp-Info.plist',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'views.gyp:views',
         'xml.gyp:xml',
       ],
diff --git a/bench.gyp b/bench.gyp
index be768f0..49e6c2c 100644
--- a/bench.gyp
+++ b/bench.gyp
@@ -17,9 +17,7 @@
         'bench.gypi'
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'bench_timer',
       ],
       'conditions': [
@@ -50,7 +48,7 @@
         '../src/gpu',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
       ],
       'conditions': [
         [ 'skia_os not in ["mac", "ios"]', {
diff --git a/common.gypi b/common.gypi
index d3e1498..2be8bb8 100644
--- a/common.gypi
+++ b/common.gypi
@@ -39,6 +39,15 @@
         }],
       ],
     },
+    # Validate the 'skia_os' setting against 'skia_shared_lib', because shared
+    # library build is only supported on Android.
+    'variables': {
+      'conditions': [
+        [ 'skia_os != "android" and skia_shared_lib', {
+          'error': '<!(Skia shared lib build only currently supported on Android.)',
+        }],
+      ],
+    },
     'includes': [
       'common_conditions.gypi',
     ],
diff --git a/common_conditions.gypi b/common_conditions.gypi
index fda1222..64e7c13 100644
--- a/common_conditions.gypi
+++ b/common_conditions.gypi
@@ -326,6 +326,17 @@
           [ 'skia_profile_enabled == 1', {
             'cflags': ['-g', '-fno-omit-frame-pointer', '-marm', '-mapcs'],
           }],
+          [ 'skia_shared_lib', {
+            'cflags': [
+              '-fPIC',
+            ],
+            'defines': [
+              'GR_DLL=1',
+              'GR_IMPLEMENTATION=1',
+              'SKIA_DLL',
+              'SKIA_IMPLEMENTATION=1',
+            ],
+          }],
           [ 'skia_arch_type == "arm" and arm_thumb == 1', {
             'cflags': [
               '-mthumb',
diff --git a/common_variables.gypi b/common_variables.gypi
index 4f9f542..ac937bd 100644
--- a/common_variables.gypi
+++ b/common_variables.gypi
@@ -90,6 +90,7 @@
       'skia_osx_sdkroot%': '',
       'skia_profile_enabled%': 0,
       'skia_win_debuggers_path%': '',
+      'skia_shared_lib%': 0,
     },
 
     'conditions': [
@@ -121,6 +122,7 @@
     'skia_gpu%': '<(skia_gpu)',
     'skia_osx_sdkroot%': '<(skia_osx_sdkroot)',
     'skia_profile_enabled%': '<(skia_profile_enabled)',
+    'skia_shared_lib%': '<(skia_shared_lib)',
     'skia_static_initializers%': '<(skia_static_initializers)',
     'ios_sdk_version%': '6.0',
     'skia_win_debuggers_path%': '<(skia_win_debuggers_path)',
diff --git a/core.gyp b/core.gyp
index 9e0792b..d018cbe 100644
--- a/core.gyp
+++ b/core.gyp
@@ -76,6 +76,11 @@
             'config/win',
           ],
         }],
+        [ 'skia_os == "android"', {
+          'sources': [
+            '../src/core/SkPaintOptionsAndroid.cpp',
+          ],
+        }],
         [ 'skia_os == "android" and skia_arch_type == "arm" and armv7 == 1', {
           # The code in SkUtilsArm.cpp can be used on an ARM-based Linux system, not only Android.
           'sources': [
@@ -120,9 +125,6 @@
           }],
         ],
       },
-      'dependencies': [
-        'opts.gyp:opts'
-      ],
     },
   ],
 }
diff --git a/debugger.gyp b/debugger.gyp
index b935fb0..9ea300d 100644
--- a/debugger.gyp
+++ b/debugger.gyp
@@ -94,17 +94,12 @@
         '../debugger/SkObjectParser.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'images.gyp:images',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'bench.gyp:bench_timer',
         'tools.gyp:picture_renderer',
       ],
       'conditions': [
         [ 'skia_os == "nacl"', {
-          'dependencies': [
-            'utils.gyp:utils', # For SkBase64.h
-          ],
           'include_dirs': [
             '../src/utils',
           ],
diff --git a/effects.gyp b/effects.gyp
index e110c9f..91458eb 100644
--- a/effects.gyp
+++ b/effects.gyp
@@ -9,7 +9,10 @@
         'effects.gypi',
       ],
       'include_dirs': [
+        '../include/config',
+        '../include/core',
         '../include/effects',
+        '../include/utils',
         '../src/core',
       ],
       'direct_dependent_settings': {
@@ -17,15 +20,13 @@
           '../include/effects',
         ],
       },
-      'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-      ],
       'sources': [
         'effects.gypi', # Makes the gypi appear in IDEs (but does not modify the build).
       ],
       'conditions': [
         ['skia_gpu == 1', {
           'include_dirs': [
+            '../include/gpu',
             '../src/gpu',
           ],
         }],
diff --git a/flags.gyp b/flags.gyp
index aa83ea9..e80b0a3 100644
--- a/flags.gyp
+++ b/flags.gyp
@@ -10,8 +10,7 @@
         '../tools/flags/SkCommandLineFlags.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'core.gyp:core',
+        'skia_lib.gyp:skia_lib',
       ],
       'direct_dependent_settings': {
         'include_dirs': [
diff --git a/gm.gyp b/gm.gyp
index fa413c3..a8b1533 100644
--- a/gm.gyp
+++ b/gm.gyp
@@ -16,7 +16,7 @@
         '../gm/gm_expectations.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
         'core.gyp:core',
         'images.gyp:images',
         'jsoncpp.gyp:jsoncpp',
@@ -57,14 +57,11 @@
         '../src/pipe/utils/SamplePipeControllers.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'flags.gyp:flags',
         'gm.gyp:gm_expectations',
-        'images.gyp:images',
         'jsoncpp.gyp:jsoncpp',
         'pdf.gyp:pdf',
-        'utils.gyp:utils',
       ],
       'conditions': [
         ['skia_os == "mac"', {
diff --git a/most.gyp b/most.gyp
index d32987f..1ad25ef 100644
--- a/most.gyp
+++ b/most.gyp
@@ -10,7 +10,7 @@
       'type': 'none',
       'dependencies': [
         # The minimal set of static libraries for basic Skia functionality.
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
 
         'bench.gyp:bench',
         'gm.gyp:gm',
diff --git a/nacl.gyp b/nacl.gyp
index 484570b..3dd4c8e 100644
--- a/nacl.gyp
+++ b/nacl.gyp
@@ -5,7 +5,7 @@
       'target_name': 'nacl_interface',
       'type': 'static_library',
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
       ],
       'include_dirs': [
         # For SkThreadUtils.h
diff --git a/pathops_unittest.gyp b/pathops_unittest.gyp
index a3ae936..c7c32ef 100644
--- a/pathops_unittest.gyp
+++ b/pathops_unittest.gyp
@@ -27,11 +27,8 @@
         '../tests/Test.h',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'flags.gyp:flags',
-        'images.gyp:images',
-        'utils.gyp:utils',
       ],
       'conditions': [
         [ 'skia_gpu == 1', {
diff --git a/pdf.gyp b/pdf.gyp
index 0e75914..31b48db 100644
--- a/pdf.gyp
+++ b/pdf.gyp
@@ -6,7 +6,7 @@
       'type': 'static_library',
       'standalone_static_library': 1,
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
         'zlib.gyp:zlib',
       ],
       'include_dirs': [
diff --git a/pixman_test.gyp b/pixman_test.gyp
index 64c5a9c..a571dd7 100644
--- a/pixman_test.gyp
+++ b/pixman_test.gyp
@@ -118,10 +118,8 @@
         '../../../pixman/pixman/pixman.h',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'experimental.gyp:experimental',
-        'images.gyp:images',
         'pdf.gyp:pdf',
         'views.gyp:views',
         'xml.gyp:xml',
diff --git a/ports.gyp b/ports.gyp
index fc9bb9b..3422b8e 100644
--- a/ports.gyp
+++ b/ports.gyp
@@ -6,18 +6,17 @@
       'product_name': 'skia_ports',
       'type': 'static_library',
       'standalone_static_library': 1,
-      'dependencies': [
-        'core.gyp:core',
-        'sfnt.gyp:sfnt',
-        'utils.gyp:utils',
-      ],
       'include_dirs': [
+        '../include/config',
+        '../include/core',
         '../include/effects',
         '../include/images',
         '../include/ports',
+        '../include/utils',
         '../include/xml',
         '../src/core',
         '../src/lazy',
+        '../src/sfnt',
         '../src/utils',
       ],
       'sources': [
diff --git a/sfnt.gyp b/sfnt.gyp
index 438f33e..cc21b22 100644
--- a/sfnt.gyp
+++ b/sfnt.gyp
@@ -5,10 +5,9 @@
       'product_name': 'skia_sfnt',
       'type': 'static_library',
       'standalone_static_library': 1,
-      'dependencies': [
-        'core.gyp:core',
-      ],
       'include_dirs': [
+        '../include/config',
+        '../include/core',
         '../src/sfnt',
       ],
       'sources': [
diff --git a/shapeops_demo.gyp b/shapeops_demo.gyp
index 4537c01..83836ee 100644
--- a/shapeops_demo.gyp
+++ b/shapeops_demo.gyp
@@ -69,9 +69,7 @@
         '../experimental/Intersection/TriangleUtilities.h',
      ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'views.gyp:views',
         'xml.gyp:xml',
       ],
diff --git a/shapeops_edge.gyp b/shapeops_edge.gyp
index 8c67cf7..e4e7d72 100644
--- a/shapeops_edge.gyp
+++ b/shapeops_edge.gyp
@@ -115,9 +115,7 @@
         '../experimental/Intersection/thingsToDo.txt',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
       ],
       'conditions': [
         [ 'skia_gpu == 1', {
diff --git a/shapeops_tool.gyp b/shapeops_tool.gyp
index 3b1408a..35caccb 100644
--- a/shapeops_tool.gyp
+++ b/shapeops_tool.gyp
@@ -15,23 +15,15 @@
         '../experimental/Intersection/AddTestOutput/main.cpp',
       ],
       'dependencies': [
-        'core.gyp:core',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'experimental.gyp:experimental',
-        'images.gyp:images',
-        'ports.gyp:ports',
         'pdf.gyp:pdf',
-        'utils.gyp:utils',
       ],
       'conditions': [
         [ 'skia_gpu == 1', {
           'include_dirs': [
             '../src/gpu',
           ],
-          'dependencies': [
-            'gpu.gyp:gr',
-            'gpu.gyp:skgr',
-          ],
         }],
       ],
     },
diff --git a/skia_base_libs.gyp b/skia_base_libs.gyp
deleted file mode 100644
index 83cc7c7..0000000
--- a/skia_base_libs.gyp
+++ /dev/null
@@ -1,52 +0,0 @@
-# The minimal set of static libraries for basic Skia functionality.
-{
-  'variables': {
-    'component_libs': [
-      'core.gyp:core',
-      'opts.gyp:opts',
-      'ports.gyp:ports',
-      'utils.gyp:utils',
-    ],
-    'conditions': [
-      [ 'skia_arch_type == "x86" and skia_os != "android"', {
-        'component_libs': [
-          'opts.gyp:opts_ssse3',
-        ],
-      }],
-      [ 'arm_neon == 1', {
-        'component_libs': [
-          'opts.gyp:opts_neon',
-        ],
-      }],
-      [ 'skia_gpu', {
-        'component_libs': [
-          'gpu.gyp:gr',
-          'gpu.gyp:skgr',
-        ],
-      }],
-      [ 'skia_os == "nacl"', {
-        'component_libs': [
-          'freetype.gyp:freetype',
-        ],
-      }],
-    ],
-  },
-  'targets': [
-    {
-      'target_name': 'skia_base_libs',
-      'type': 'none',
-      'dependencies': [
-        '<@(component_libs)',
-      ],
-      'export_dependent_settings': [
-        '<@(component_libs)',
-      ],
-    },
-  ],
-}
-
-# Local Variables:
-# tab-width:2
-# indent-tabs-mode:nil
-# End:
-# vim: set expandtab tabstop=2 shiftwidth=2:
diff --git a/skia_lib.gyp b/skia_lib.gyp
new file mode 100644
index 0000000..f85c5ad
--- /dev/null
+++ b/skia_lib.gyp
@@ -0,0 +1,72 @@
+# The minimal set of static libraries for basic Skia functionality.
+
+{
+  'variables': {
+    'component_libs': [
+      'core.gyp:core',
+      'effects.gyp:effects',
+      'images.gyp:images',
+      'opts.gyp:opts',
+      'ports.gyp:ports',
+      'sfnt.gyp:sfnt',
+      'utils.gyp:utils',
+    ],
+    'conditions': [
+      [ 'skia_arch_type == "x86" and skia_os != "android"', {
+        'component_libs': [
+          'opts.gyp:opts_ssse3',
+        ],
+      }],
+      [ 'arm_neon == 1', {
+        'component_libs': [
+          'opts.gyp:opts_neon',
+        ],
+      }],
+      [ 'skia_gpu', {
+        'component_libs': [
+          'gpu.gyp:gr',
+          'gpu.gyp:skgr',
+        ],
+      }],
+      [ 'skia_os == "nacl"', {
+        'component_libs': [
+          'freetype.gyp:freetype',
+        ],
+      }],
+    ],
+  },
+  'targets': [
+    {
+      'target_name': 'skia_lib',
+      'conditions': [
+        [ 'skia_shared_lib', {
+          'conditions': [
+            [ 'skia_os == "android"', {
+              # The name skia will confuse the linker on android into using the system's libskia.so
+              # instead of the one packaged with the apk. We simply choose a different name to fix
+              # this.
+              'product_name': 'skia_android',
+            }, {
+              'product_name': 'skia',
+            }],
+          ],
+          'type': 'shared_library',
+        }, {
+          'type': 'none',
+        }],
+      ],
+      'dependencies': [
+        '<@(component_libs)',
+      ],
+      'export_dependent_settings': [
+        '<@(component_libs)',
+      ],
+    },
+  ],
+}
+
+# Local Variables:
+# tab-width:2
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=2 shiftwidth=2:
diff --git a/tests.gyp b/tests.gyp
index 10a4ba4..557fea5 100644
--- a/tests.gyp
+++ b/tests.gyp
@@ -128,15 +128,11 @@
         '../src/pipe/utils/SamplePipeControllers.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'flags.gyp:flags',
         'experimental.gyp:experimental',
-        'images.gyp:images',
         'pdf.gyp:pdf',
         'tools.gyp:picture_utils',
-        'utils.gyp:utils',
-        'sfnt.gyp:sfnt',
       ],
       'conditions': [
         [ 'skia_gpu == 1', {
diff --git a/tools.gyp b/tools.gyp
index ede028a..25aa1db 100644
--- a/tools.gyp
+++ b/tools.gyp
@@ -37,9 +37,7 @@
         '../tools/skdiff_utils.h',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
       ],
     },
     {
@@ -55,9 +53,7 @@
         '../tools/skdiff_utils.h',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
       ],
     },
     {
@@ -67,10 +63,8 @@
         '../tools/skhello.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'flags.gyp:flags',
-        'images.gyp:images',
       ],
     },
     {
@@ -84,11 +78,9 @@
         '../src/utils/',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'flags.gyp:flags',
         'gm.gyp:gm_expectations',
-        'images.gyp:images',
         'jsoncpp.gyp:jsoncpp',
         'utils.gyp:utils',
       ],
@@ -102,7 +94,7 @@
         '../src/utils/SkLua.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
         'effects.gyp:effects',
         'utils.gyp:utils',
         'images.gyp:images',
@@ -123,10 +115,9 @@
         '../src/pipe/utils/',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
         'tools.gyp:picture_renderer',
         'tools.gyp:picture_utils',
-        'ports.gyp:ports',
         'flags.gyp:flags',
       ],
     },
@@ -146,12 +137,10 @@
         '../src/lazy/',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
+        'skia_lib.gyp:skia_lib',
         'tools.gyp:picture_utils',
         'tools.gyp:picture_renderer',
         'bench.gyp:bench_timer',
-        'ports.gyp:ports',
         'flags.gyp:flags',
       ],
     },
@@ -174,9 +163,7 @@
         '../src/utils/',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'tools.gyp:picture_utils',
         'flags.gyp:flags',
       ],
@@ -189,9 +176,6 @@
           },
         ],
       ],
-      'export_dependent_settings': [
-        'images.gyp:images',
-      ],
     },
     {
       'target_name': 'render_pdfs',
@@ -206,11 +190,8 @@
         '../src/utils/',
       ],
       'dependencies': [
-        'core.gyp:core',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'pdf.gyp:pdf',
-        'ports.gyp:ports',
         'tools.gyp:picture_utils',
       ],
       'conditions': [
@@ -257,7 +238,7 @@
         '../tools/picture_utils.h',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
+        'skia_lib.gyp:skia_lib',
       ],
       'direct_dependent_settings': {
         'include_dirs': [
@@ -272,9 +253,7 @@
         '../tools/pinspect.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
       ],
     },
     {
@@ -296,9 +275,7 @@
         '../debugger/SkObjectParser.cpp',
       ],
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'effects.gyp:effects',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'tools.gyp:picture_utils',
       ],
     },
diff --git a/xps.gyp b/xps.gyp
index 3768742..29d5e07 100644
--- a/xps.gyp
+++ b/xps.gyp
@@ -6,8 +6,7 @@
       'type': 'static_library',
       'standalone_static_library': 1,
       'dependencies': [
-        'skia_base_libs.gyp:skia_base_libs',
-        'images.gyp:images',
+        'skia_lib.gyp:skia_lib',
         'sfnt.gyp:sfnt',
       ],
       'include_dirs': [