Build Skia for a bare-bones embedded Linux system.

Motivation:

    I have downloaded a barebones Linux system built for 64-bit ARM
    from linaro.org and a ARMv8 Foundation Model from arm.com to run
    it on.  This will let us build and test Skia on ARM64 before we
    aquire hardware to allow that.  This CL introduces the changes to
    the build files necessary to build Skia on a barebones embedded
    Linux system.  I tested it with the aarch64 GCC compiler provided
    by linaro.org.

Changes:

    Add a "barelinux" target_os for the DEPS file.  Add an optional
    git download of zlib.

    Changes to gyp files: these changes abstract out libpng, libz, and
    giflib so that images.gyp doesn't know whether they are static or
    dynamically linked.  I also add the variables skia_giflib_static,
    skia_libpng_static, skia_zlib_static, and skia_freetype_static,
    all of which default to false but when set to true will override
    the behavior of the giflib, libpng, zlib, and freetype build
    targets to require them to build statically.  Also, the
    skia_no_fontconfig variable turns off use of the fontconfig service.

	Scripts in platform_tools/barelinux/bin:

    arm64_download - this script downloads the Linaro's ARMv8 Aarch64
	toolchain and minimal embedded Linux system as well as ARM's
	foundation model.  The required files are mirrored on Google
	Cloud.  The script then starts a emulated Arm64 Linux system in
	the background.  After the boot is complete, you can SSH into the
	system at port 8022 via user@localhost.  The SSH key will be
	downloaded into the working directery as well.

	download_deps - Uses gclient to download Skia's dependencies for a
    bare Linux system (the normal dependecies plus giflib, libpng, and
    zlib.)

	barelinux_make - this script builds a version of skia that does
    not depend on external libraries, perfect for putting in an
    embedded system running Linux.  Assumes you have run download_deps
    first.

To test:
    To build a barelinux target, use the barelinux_make script.

    To build for a armv8 system: skia_arch_type=arm arm_neon=0 armv7=1
    armv8=1 arm_thumb=0 skia_arch_width=64 and set the CC and CXX
    variables to point at the cross-compiler downloaded by
    arm64_download.

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

Author: halcanary@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13570 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/DEPS b/DEPS
index 8c280f4..1fa3662 100644
--- a/DEPS
+++ b/DEPS
@@ -36,6 +36,17 @@
     "platform_tools/chromeos/toolchain/src/third_party/chromite": "https://chromium.googlesource.com/chromiumos/chromite.git@d6a4c7e0ee4d53ddc5238dbddfc0417796a70e54",
     "platform_tools/chromeos/toolchain/src/third_party/pyelftools": "https://chromium.googlesource.com/chromiumos/third_party/pyelftools.git@bdc1d380acd88d4bfaf47265008091483b0d614e",
   },
+
+  # barelinux is a DEPS target that has no shared libraries to link
+  # to, similar to android or chromeos.
+  "barelinux": {
+    "third_party/externals/giflib" :
+      "https://android.googlesource.com/platform/external/giflib.git@android-4.2.2_r1.2",
+    "third_party/externals/libpng" :
+       "https://android.googlesource.com/platform/external/libpng.git@android-4.2.2_r1.2",
+    "third_party/externals/zlib" :
+       "https://android.googlesource.com/platform/external/zlib.git@android-4.2.2_r1.2",
+  }
 }
 
 #hooks = [
diff --git a/gyp/common_variables.gypi b/gyp/common_variables.gypi
index c3ec7d8..6d101ed 100644
--- a/gyp/common_variables.gypi
+++ b/gyp/common_variables.gypi
@@ -91,8 +91,42 @@
           'arm_version%': 0,
           'arm_neon%': 0,
         }],
+        [ 'skia_os in ["android", "nacl"] and not skia_android_framework',
+          # skia_freetype_static - on OS variants that normally would
+          #     dynamically link the system FreeType library, don't do
+          #     that; instead statically link to the version in
+          #     third_party/freetype and third_party/externals/freetype.
+          {
+            'skia_freetype_static%': '1',
+          }, {
+            'skia_freetype_static%': '0',
+          }
+        ],
       ],
 
+      # skia_giflib_static - on OS variants that normally would link giflib
+      #     with '-lgif' and include the headers from '/usr/include/gif_lib.h',
+      #     don't do that; instead compile and staticlly link the version of
+      #     giflib in third_party/externals/giflib.
+      'skia_giflib_static%': '0',
+
+      # skia_libpng_static - on OS variants that normally would link libpng
+      #     with '-lpng' and include the headers from '/usr/include/png.h',
+      #     don't do that; instead compile and staticlly link the version of
+      #     libpng in third_party/externals/libpng.
+      'skia_libpng_static%': '0',
+
+      # skia_zlib_static - on OS variants that normally would link zlib with
+      #     '-lz' or libz.dylib and include the headers from '<zlib.h>',
+      #     don't do that; instead compile and staticlly link the version of
+      #     zlib in third_party/externals/zlib.
+      'skia_zlib_static%': '0',
+
+      # skia_no_fontconfig - On POSIX systems that would normally use the
+      #     SkFontHost_fontconfig interface; use the SkFontHost_linux
+      #     version instead.
+      'skia_no_fontconfig%': '0',
+
       'skia_sanitizer%': '',
       'skia_scalar%': 'float',
       'skia_mesa%': 0,
@@ -151,6 +185,12 @@
     'arm_neon_optional%': 0,
     'skia_os%': '<(skia_os)',
     'os_posix%': '<(os_posix)',
+
+    'skia_freetype_static%': '<(skia_freetype_static)',
+    'skia_giflib_static%': '<(skia_giflib_static)',
+    'skia_libpng_static%': '<(skia_libpng_static)',
+    'skia_zlib_static%': '<(skia_zlib_static)',
+    'skia_no_fontconfig%': '<(skia_no_fontconfig)',
     'skia_sanitizer%': '<(skia_sanitizer)',
     'skia_scalar%': '<(skia_scalar)',
     'skia_mesa%': '<(skia_mesa)',
diff --git a/gyp/freetype.gyp b/gyp/freetype.gyp
index 6717c78..cd71e78 100644
--- a/gyp/freetype.gyp
+++ b/gyp/freetype.gyp
@@ -5,54 +5,71 @@
       'target_name': 'freetype',
       'type': 'none',
       'conditions': [
-        [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]', {
-          'direct_dependent_settings': {
-            'include_dirs' : [
-              '/usr/include/freetype2',
+        [ 'skia_freetype_static',
+          {
+            'dependencies': [
+              'freetype_static'
             ],
-            'link_settings': {
-              'libraries': [
-                '-lfreetype',
+            'export_dependent_settings': [
+              'freetype_static'
+            ],
+            'conditions': [
+              [ 'skia_os in ["android", "nacl"]',
+                {
+                  'direct_dependent_settings': {
+                    'defines': [
+                      # Both Android and NaCl provide at least FreeType 2.4.0
+                      'SK_FONTHOST_FREETYPE_RUNTIME_VERSION=0x020400',
+                      'SK_CAN_USE_DLOPEN=0',
+                    ],
+                  }
+                }
+              ]
+            ],
+          }, { # (not skia_freetype_static)
+            # dynamic linking depends on the OS:
+            'conditions': [
+              [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]',
+                {
+                  'direct_dependent_settings': {
+                    'include_dirs' : [
+                      '/usr/include/freetype2',
+                    ],
+                    'link_settings': {
+                      'libraries': [
+                        '-lfreetype',
+                      ],
+                    },
+                    'defines': [
+                      # The font host requires at least FreeType 2.3.0
+                      # at runtime.
+                      'SK_FONTHOST_FREETYPE_RUNTIME_VERSION=0x020300',
+                      'SK_CAN_USE_DLOPEN=1',
+                    ],
+                  }
+                },
               ],
-              'defines': [
-                #The font host requires at least FreeType 2.3.0 at runtime.
-                'SK_FONTHOST_FREETYPE_RUNTIME_VERSION=0x020300',\
-                'SK_CAN_USE_DLOPEN=1',
+              [ 'skia_android_framework',
+                {
+                  'direct_dependent_settings': {
+                    'defines': [
+                      # Android provides at least FreeType 2.4.0
+                      'SK_FONTHOST_FREETYPE_RUNTIME_VERSION=0x020400',
+                      'SK_CAN_USE_DLOPEN=0',
+                    ],
+                  },
+                  'include_dirs': [
+                    'external/expat/lib',
+                    'external/freetype/include',
+                  ],
+                  'libraries': [
+                    '-lft2',
+                  ],
+                }
               ],
-            }
-          },
-        }],
-        [ 'skia_os in ["android", "nacl"]', {
-          'dependencies': [
-            'freetype_static'
-          ],
-          'export_dependent_settings': [
-            'freetype_static'
-          ],
-          'direct_dependent_settings': {
-            'defines': [
-              # Both Android and NaCl provide at least FreeType 2.4.0
-              'SK_FONTHOST_FREETYPE_RUNTIME_VERSION=0x020400',
-              'SK_CAN_USE_DLOPEN=0',
             ],
-          },
-        }],
-        [ 'skia_android_framework', {
-            'include_dirs': [
-              'external/expat/lib',
-              'external/freetype/include',
-            ],
-            'libraries': [
-              '-lft2',
-            ],
-            # Remove these, and use the system's freetype instead.
-            'dependencies!': [
-              'freetype_static',
-            ],
-            'export_dependent_settings!': [
-              'freetype_static',
-            ]
-        }],
+          }
+        ],
       ],
     },
     {
@@ -61,7 +78,7 @@
       'standalone_static_library': 1,
       'dependencies': [
         # we are dependent upon PNG for color emoji glyphs
-        'images.gyp:images'
+        'libpng.gyp:libpng',
       ],
       'includes': [
         # common freetype sources needed for both the base Skia build and the
diff --git a/gyp/giflib.gyp b/gyp/giflib.gyp
new file mode 100644
index 0000000..56e5003
--- /dev/null
+++ b/gyp/giflib.gyp
@@ -0,0 +1,53 @@
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+  'variables': {
+    'skia_warnings_as_errors': 0,
+  },
+  'targets': [
+    {
+      'target_name': 'giflib',
+      'conditions': [
+        [ 'skia_giflib_static',
+          {
+            'type': 'static_library',
+            'defines': [
+              'HAVE_CONFIG_H',
+            ],
+            'include_dirs': [
+              '../third_party/externals/giflib',
+            ],
+            'dependencies': [
+            ],
+            'direct_dependent_settings': {
+              'include_dirs': [
+                '../third_party/externals/giflib',
+              ],
+            },
+            'cflags': [
+              '-w',
+            ],
+            'sources': [
+              '../third_party/externals/giflib/dgif_lib.c',
+              '../third_party/externals/giflib/gifalloc.c',
+              '../third_party/externals/giflib/gif_err.c',
+            ],
+          }, {  # not skia_giflib_static
+            'type': 'none',
+            'direct_dependent_settings': {
+              'link_settings': {
+                'libraries': [
+                  '-lgif',
+                ],
+              },
+            },
+          }
+        ],
+      ]
+    }
+  ]
+}
+
diff --git a/gyp/images.gyp b/gyp/images.gyp
index fdbf2a0..13e7687 100644
--- a/gyp/images.gyp
+++ b/gyp/images.gyp
@@ -119,16 +119,14 @@
           ],
         }],
         [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris"]', {
-          # Any targets that depend on this target should link in libpng, libgif, and
-          # our code that calls it.
-          # See http://code.google.com/p/gyp/wiki/InputFormatReference#Dependent_Settings
-          'link_settings': {
-            'libraries': [
-              '-lgif',
-              '-lpng',
-              '-lz',
-            ],
-          },
+          'export_dependent_settings': [
+            'libpng.gyp:libpng',
+            'giflib.gyp:giflib'
+          ],
+          'dependencies': [
+            'libpng.gyp:libpng',
+            'giflib.gyp:giflib'
+          ],
           # end libpng/libgif stuff
         }],
         # FIXME: NaCl should be just like linux, etc, above, but it currently is separated out
@@ -139,12 +137,6 @@
             '../src/images/SkImageDecoder_libgif.cpp',
             '../src/images/SkMovie_gif.cpp',
           ],
-          'link_settings': {
-            'libraries': [
-              '-lpng',
-              '-lz',
-            ],
-          },
         }],
         [ 'skia_os == "android"', {
           'include_dirs': [
@@ -171,11 +163,6 @@
           'dependencies': [
              'chromeos_deps.gyp:gif',
           ],
-          'link_settings': {
-            'libraries': [
-              '-lpng',
-            ],
-          },
         }],
         [ 'skia_os == "ios"', {
            'include_dirs': [
diff --git a/gyp/libjpeg.gyp b/gyp/libjpeg.gyp
index b10ee8c..7307294 100644
--- a/gyp/libjpeg.gyp
+++ b/gyp/libjpeg.gyp
@@ -104,10 +104,9 @@
               'cflags': [
                 '-w', # supresses warnings
               ],
-
             },
           ],
-        }, {
+        }, {  ## use_system_libjpeg != 0
           'targets': [
             {
               'target_name': 'libjpeg',
diff --git a/gyp/libpng.gyp b/gyp/libpng.gyp
new file mode 100644
index 0000000..92ff8d5
--- /dev/null
+++ b/gyp/libpng.gyp
@@ -0,0 +1,88 @@
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+  'variables': {
+    'skia_warnings_as_errors': 0,
+  },
+  'targets': [
+    {
+      'target_name': 'libpng',
+      'conditions': [
+        [ 'skia_libpng_static',
+          {
+            'type': 'static_library',
+            'include_dirs': [
+              '../third_party/externals/libpng',
+            ],
+            'dependencies': [
+              'zlib.gyp:zlib',
+            ],
+            'export_dependent_settings': [
+              'zlib.gyp:zlib',
+            ],
+            'direct_dependent_settings': {
+              'include_dirs': [
+                '../third_party/externals/libpng',
+              ],
+            },
+            'cflags': [
+              '-w',
+              '-fvisibility=hidden',
+            ],
+            'sources': [
+              '../third_party/externals/libpng/png.c',
+              '../third_party/externals/libpng/pngerror.c',
+              '../third_party/externals/libpng/pnggccrd.c',
+              '../third_party/externals/libpng/pngget.c',
+              '../third_party/externals/libpng/pngmem.c',
+              '../third_party/externals/libpng/pngpread.c',
+              '../third_party/externals/libpng/pngread.c',
+              '../third_party/externals/libpng/pngrio.c',
+              '../third_party/externals/libpng/pngrtran.c',
+              '../third_party/externals/libpng/pngrutil.c',
+              '../third_party/externals/libpng/pngset.c',
+              '../third_party/externals/libpng/pngtrans.c',
+              '../third_party/externals/libpng/pngvcrd.c',
+              '../third_party/externals/libpng/pngwio.c',
+              '../third_party/externals/libpng/pngwrite.c',
+              '../third_party/externals/libpng/pngwtran.c',
+              '../third_party/externals/libpng/pngwutil.c',
+            ],
+          }, {  # not skia_libpng_static
+            'type': 'none',
+            'conditions': [
+              [ 'skia_os == "android"',
+                {
+                  # TODO(halcanary): merge all png targets into this file.
+                  'dependencies': [
+                    'android_deps.gyp:png',
+                  ],
+                  'export_dependent_settings': [
+                    'android_deps.gyp:png',
+                  ],
+                }, {  # skia_os != "android"
+                  'dependencies': [
+                    'zlib.gyp:zlib',
+                    ],
+                  'export_dependent_settings': [
+                    'zlib.gyp:zlib',
+                    ],
+                  'direct_dependent_settings': {
+                    'link_settings': {
+                      'libraries': [
+                        '-lpng',
+                      ],
+                    },
+                  },
+                }
+              ]
+            ]
+          }
+        ]
+      ],
+    },
+  ]
+}
diff --git a/gyp/lua.gyp b/gyp/lua.gyp
index 704b8e4..e030ffe 100644
--- a/gyp/lua.gyp
+++ b/gyp/lua.gyp
@@ -57,7 +57,16 @@
         ],
       },
       'defines': [
-        "getlocaledecpoint()='.'"
+        "getlocaledecpoint()='.'",
+      ],
+      'conditions': [
+        ['skia_os != "win"',
+         {
+            'defines': [
+              'LUA_USE_POSIX',  # Fix warning re dangerous tmpnam.
+            ],
+          }
+        ],
       ],
     },
   ],
diff --git a/gyp/most.gyp b/gyp/most.gyp
index b914bc5..7c32941 100644
--- a/gyp/most.gyp
+++ b/gyp/most.gyp
@@ -4,6 +4,9 @@
 # - debugger: this requires QT to build
 #
 {
+  'variables': {
+    'skia_skip_gui%': 0,
+  },
   'targets': [
     {
       'target_name': 'most',
@@ -29,6 +32,14 @@
         ['skia_gpu == 1', {
           'dependencies': [ 'dm.gyp:dm' ],
         }],
+        [ 'skia_skip_gui',
+          {
+            'dependencies!': [
+              'SampleApp.gyp:SampleApp',
+              'skpskgr_test.gyp:*',
+            ]
+          }
+        ]
       ],
     },
   ],
diff --git a/gyp/pdf.gyp b/gyp/pdf.gyp
index 145dc5b..e5923e7 100644
--- a/gyp/pdf.gyp
+++ b/gyp/pdf.gyp
@@ -8,7 +8,7 @@
       'standalone_static_library': 1,
       'dependencies': [
         'skia_lib.gyp:skia_lib',
-        'zlib.gyp:zlib',
+        'skflate.gyp:skflate',
       ],
       'includes': [
         'pdf.gypi',
diff --git a/gyp/pdfviewer_lib.gyp b/gyp/pdfviewer_lib.gyp
index a0a142c..b33c6c5 100644
--- a/gyp/pdfviewer_lib.gyp
+++ b/gyp/pdfviewer_lib.gyp
@@ -44,7 +44,7 @@
       ],
       'dependencies': [
         'skia_lib.gyp:skia_lib',
-        'zlib.gyp:zlib',
+        'skflate.gyp:skflate',
       ],
     },
   ],
diff --git a/gyp/ports.gyp b/gyp/ports.gyp
index a627910..7ecda5f 100644
--- a/gyp/ports.gyp
+++ b/gyp/ports.gyp
@@ -64,16 +64,29 @@
           ],
         }],
         [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]', {
-          'link_settings': {
-            'libraries': [
-              '-lfontconfig',
-              '-ldl',
-            ],
-          },
-          'sources': [
-            '../src/fonts/SkFontMgr_fontconfig.cpp',
-            '../src/ports/SkFontHost_fontconfig.cpp',
-            '../src/ports/SkFontConfigInterface_direct.cpp',
+          'conditions': [
+            [ 'skia_no_fontconfig', {
+              'link_settings': {
+                'libraries': [
+                  '-ldl',
+                ],
+              },
+              'sources': [
+                '../src/ports/SkFontHost_linux.cpp',
+              ],
+            }, {
+              'link_settings': {
+                'libraries': [
+                  '-lfontconfig',
+                  '-ldl',
+                ],
+              },
+              'sources': [
+                '../src/fonts/SkFontMgr_fontconfig.cpp',
+                '../src/ports/SkFontHost_fontconfig.cpp',
+                '../src/ports/SkFontConfigInterface_direct.cpp',
+              ],
+            }]
           ],
         }],
         [ 'skia_os == "nacl"', {
diff --git a/gyp/skflate.gyp b/gyp/skflate.gyp
new file mode 100644
index 0000000..9e11cd9
--- /dev/null
+++ b/gyp/skflate.gyp
@@ -0,0 +1,26 @@
+# Target for including SkFlate.
+{
+  'targets': [
+    {
+      'target_name': 'skflate',
+      'type': 'static_library',
+      'dependencies': [
+        'skia_lib.gyp:skia_lib',
+      ],
+      'conditions': [
+        # When zlib is not availible on a system,
+        # SkFlate::HaveFlate will just return false.
+        [ 'skia_os != "win"',
+          {
+            'dependencies': [
+              'zlib.gyp:zlib',
+            ],
+          }
+        ],
+      ],
+      'sources': [
+        '../src/core/SkFlate.cpp',
+      ],
+    },
+  ],
+}
diff --git a/gyp/zlib.gyp b/gyp/zlib.gyp
index b26053e..6539471 100644
--- a/gyp/zlib.gyp
+++ b/gyp/zlib.gyp
@@ -1,48 +1,78 @@
-# Target for including zlib.
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
 {
+  'variables': {
+    'skia_warnings_as_errors': 0,
+  },
   'targets': [
     {
       'target_name': 'zlib',
-      'type': 'static_library',
-      'dependencies': [
-        'skia_lib.gyp:skia_lib',
-      ],
-      'sources': [
-        '../include/core/SkFlate.h',
-
-        '../src/core/SkFlate.cpp',
-      ],
       'conditions': [
-        [ 'skia_os == "mac"', {
-          'link_settings': {
-            'libraries': [
-              '$(SDKROOT)/usr/lib/libz.dylib',
+        [ 'skia_zlib_static',
+          {
+            'type': 'static_library',
+            'include_dirs': [
+              '../third_party/externals/zlib',
             ],
-          },
-          'defines': [ 'SK_ZLIB_INCLUDE=<zlib.h>', ],
-        }],
-        [ 'skia_os == "ios"', {
-          'link_settings': {
-            'libraries': [
-              '$(SDKROOT)/usr/lib/libz.dylib',
+            'direct_dependent_settings': {
+              'defines': [
+                'SK_ZLIB_INCLUDE=<zlib.h>',
+              ],
+              'include_dirs': [
+                '../third_party/externals/zlib',
+              ],
+            },
+            'sources': [
+              '../third_party/externals/zlib/src/adler32.c',
+              '../third_party/externals/zlib/src/compress.c',
+              '../third_party/externals/zlib/src/crc32.c',
+              '../third_party/externals/zlib/src/deflate.c',
+              '../third_party/externals/zlib/src/gzclose.c',
+              '../third_party/externals/zlib/src/gzlib.c',
+              '../third_party/externals/zlib/src/gzread.c',
+              '../third_party/externals/zlib/src/gzwrite.c',
+              '../third_party/externals/zlib/src/infback.c',
+              '../third_party/externals/zlib/src/inffast.c',
+              '../third_party/externals/zlib/src/inflate.c',
+              '../third_party/externals/zlib/src/inftrees.c',
+              '../third_party/externals/zlib/src/trees.c',
+              '../third_party/externals/zlib/src/uncompr.c',
+              '../third_party/externals/zlib/src/zutil.c',
             ],
-          },
-          'defines': [ 'SK_ZLIB_INCLUDE=<zlib.h>', ],
-        }],
-        [ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "android", "nacl"]', {
-          'link_settings': { 'libraries': [ '-lz', ], },
-          'conditions': [
-            [ 'skia_android_framework==0', {
-              'defines': [ 'SK_ZLIB_INCLUDE=<zlib.h>', ],
-            }],
-          ],
-        }],
-        [ 'skia_android_framework', {
-          'include_dirs': [
-            'external/zlib',
-          ],
-        }],
-      ],
-    },
-  ],
+          }, {  # not skia_zlib_static
+            'type': 'none',
+            'direct_dependent_settings': {
+              'conditions': [
+                [ 'skia_android_framework', {
+                  'include_dirs': [
+                    'external/zlib',
+                  ],
+                }, {
+                  'defines': [
+                    'SK_ZLIB_INCLUDE=<zlib.h>',
+                  ],
+                }]
+              ],
+              'link_settings': {
+                'conditions': [
+                  [ 'skia_os == "mac" or skia_os == "ios"', {
+                    'libraries': [
+                      '$(SDKROOT)/usr/lib/libz.dylib',
+                    ]
+                  }, {  # skia_os != "mac" and skia_os != "ios"
+                    'libraries': [
+                      '-lz',
+                    ]
+                  }],
+                ],
+              }
+            },
+          }
+        ]
+      ]
+    }
+  ]
 }
diff --git a/platform_tools/barelinux/bin/arm64_download b/platform_tools/barelinux/bin/arm64_download
new file mode 100755
index 0000000..598ee89
--- /dev/null
+++ b/platform_tools/barelinux/bin/arm64_download
@@ -0,0 +1,167 @@
+#!/bin/sh
+
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+usage() {
+    cat >&2 <<EOF
+arm64_download - this script downloads the Linaro's ARMv8 Aarch64
+toolchain and minimal embedded Linux system as well as ARM's
+foundation model.  The required files are mirrored on Google Cloud.
+
+If the files are already located in the working directory, the
+download can be skipped if the checksums match.
+
+The script then starts a emulated Arm64 Linux system in the
+background.  After the boot is complete, you can SSH into the system
+at port 8022 via user@localhost.  The SSH key will be downloaded into
+the working directery as well.
+
+Requires gsutil, xz, tar, and gunzip.
+
+Usage:
+  $0 WORKING_DIRECTORY
+  ssh-add WORKING_DIRECTORY/key
+  ...wait...
+  ssh -p 8022 user@localhost
+EOF
+    return 1
+}
+
+try() {
+    # print an error on nonzero return code
+    "$@"
+    local ret=$?
+    if [ $ret != 0 ] ; then
+        echo "'$@' failed and returned ${ret}." >&2
+        return $ret
+    fi
+}
+
+gsutil_check_get() {
+    local gurl="$1"
+    local file="$2"
+    if ! [ -f "$file" ] || \
+        [ "$(gsutil stat "$gurl" | sed -n 's/\W*Hash (md5):\W*//p')" \
+        != "$(md5sum < "$file" | sed 's/\W*-//')" ] ; then
+        try gsutil cp "$gurl" "$file" || return
+    fi
+}
+
+download_compiler() {
+    local working_dir="$1"
+    local location="$2"
+    local toolchain="$3"
+
+    try cd "$working_dir" || return
+
+    try gsutil_check_get "gs://${location}/${toolchain}.tar.xz" \
+        "${working_dir}/${toolchain}.tar.xz" || return
+    (
+        cd "$working_dir"
+        xz --decompress --stdout < "${toolchain}.tar.xz" | tar xf -
+    )
+    local dir="${working_dir}/${toolchain}"
+    try test -d "$dir" || return
+    try test -x "${dir}/bin/aarch64-linux-gnu-gcc" || return
+    try test -x "${dir}/bin/aarch64-linux-gnu-g++" || return
+}
+
+download_runtime() {
+    local working_dir="$1"
+    local location="$2"
+    local firmware="$3"
+    local compressed_rootfs="$4"
+    local compressed_foundation_model="$5"
+    local keyfile="$6"
+
+    try gsutil_check_get "gs://${location}/${firmware}" \
+        "${working_dir}/firmware" || return
+
+    try gsutil_check_get "gs://${location}/${compressed_rootfs}" \
+        "${working_dir}/${compressed_rootfs}" || return
+
+    try xz --decompress --stdout \
+            < "${working_dir}/${compressed_rootfs}" \
+            > "${working_dir}/rootfs" || return
+    try test -f "${working_dir}/rootfs" || return
+
+    try gsutil_check_get "gs://${location}/${compressed_foundation_model}" \
+        "${working_dir}/${compressed_foundation_model}" || return
+    (
+        try cd "$working_dir" || return
+        try gunzip -c "$compressed_foundation_model" | try tar xf - || return
+        try test -d "Foundation_v8pkg" || return  #  Assert.
+    )
+
+    try gsutil_check_get "gs://${location}/${keyfile}" \
+        "${working_dir}/key" || return
+    chmod go= "${working_dir}/key"
+}
+
+start_arm64_image() {
+    local working_dir="$1"
+    local foundation_dir="${working_dir}/Foundation_v8pkg"
+    local foundation="${foundation_dir}/models/Linux64_GCC-4.1/Foundation_v8"
+    local firmware="${working_dir}/firmware"
+    local rootfs="${working_dir}/rootfs"
+
+    try test -d "$foundation_dir" || return
+    try test -x "$foundation" || return
+    try test -f "$firmware" || return
+    try test -f "$rootfs" || return
+
+    for PID in $(ps -o 'pid=' -C 'Foundation_v8') ; do
+        kill $PID
+    done
+
+    DISPLAY='' nohup \
+    "$foundation" \
+        --image="${firmware}" \
+        --cores=4 \
+        --block-device="${rootfs}" \
+        --network="nat" \
+        --network-nat-subnet="192.168.31.0/24" \
+        --network-nat-ports="8022=22" \
+        > /dev/null 2>&1 &
+    echo 'Listening to SSH on port 8022.'
+}
+
+arm64_download() {
+    local working_directory="$1"
+    local location="chromium-skia-gm/arm64env"
+    try mkdir -p "$working_directory" || return
+
+    try download_compiler \
+        "$working_directory" \
+        "$location" \
+        'gcc-linaro-aarch64-linux-gnu-4.8-2013.12_linux' \
+         || return
+
+    local rootfs='vexpress64-openembedded_lamp-armv8-gcc-4.8_20131215-557'
+    try download_runtime \
+        "$working_directory" \
+        "$location" \
+        'img-foundation.axf' \
+        "${rootfs}.img.CLEAN_AND_CONFIGURED.xz" \
+        'FM000-KT-00035-r0p8-52rel06.tgz' \
+        'CLEAN_AND_CONFIGURED_key' \
+        || return
+
+    try start_arm64_image \
+        "$working_directory" \
+        || return
+
+}
+
+for command in gsutil xz tar gunzip; do
+    try command -v "$command" > /dev/null || usage || exit
+done
+
+if [ -z "$1" ] ; then
+    usage || exit
+fi
+try arm64_download "$1" || exit
diff --git a/platform_tools/barelinux/bin/barelinux_make b/platform_tools/barelinux/bin/barelinux_make
new file mode 100755
index 0000000..03e1a4c
--- /dev/null
+++ b/platform_tools/barelinux/bin/barelinux_make
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+usage() {
+    cat >&2 <<EOF
+barelinux_make - this script builds a version of skia that does not
+depend on external libraries, perfect for putting in an embedded
+system running Linux.
+
+Assumes that you have already run the download_deps script.
+
+Usage:
+  $0 \\
+    [-o SKIA_OUT_DIR] [-c CC_EXE] [-x CXX_EXE] \\
+    [-t Debug | Release | Coverage | Release_Developer]\\
+    [GYP_DEFINES...]
+
+Example use:
+  $0 \\
+    -o ~/build/skia/arg64gcc \\
+    -c ~/local/arm64/bin/aarch64-linux-gnu-gcc \\
+    -x ~/local/arm64/bin/aarch64-linux-gnu-g++ \\
+    skia_gpu=0 skia_arch_type=arm skia_arch_width=64 \\
+    armv7=1 armv8=1 arm_neon=0 arm_thumb=0
+EOF
+    return 1
+}
+
+# BUILD_TYPE should be one of:
+#  Coverage, Debug, Release, or Release_Developer
+BUILD_TYPE='Debug'
+
+unset OPTIND
+while getopts ":c:x:o:h" opt ; do
+    case $opt in
+        c)  export CC="$OPTARG" ;;
+        x)  export CXX="$OPTARG" ;;
+        o)  export SKIA_OUT="$OPTARG";;
+        t)  BUILD_TYPE="$OPTARG";;
+        h)  usage || exit;;
+        ?)  echo "unknown option '$OPTARG'" >&2;
+            usage || exit;;
+    esac
+done
+# Append exra arguments to GYP_DEFINES variable.
+shift $(( $OPTIND - 1 ))
+GYP_DEFINES="${GYP_DEFINES} $*"
+
+# If you move this script, this must be changed.
+SKIA_SRC_DIR="$(cd "$(dirname "$0")/../../.."; pwd)"
+
+try() {
+    # exit shell script on nonzero return code
+    "$@"
+    local ret=$?
+    if [ $ret != 0 ] ; then
+        echo "'$@' failed and returned ${ret}." >&2
+        return $ret
+    fi
+}
+is_set() {
+    test "$1" && test "$(eval echo \${$1})";
+}
+
+# Set a reasonable default.
+is_set SKIA_OUT || export SKIA_OUT="${SKIA_SRC_DIR}/out/barelinux"
+
+# Assume ninja is in your path
+try command -v ninja > /dev/null || exit
+
+try test -x "${SKIA_SRC_DIR}/gyp_skia" || exit
+try mkdir -p "$SKIA_OUT" || exit
+
+export GYP_GENERATORS="ninja"
+export GYP_GENERATOR_FLAGS=""
+export GYP_DEFINES="${GYP_DEFINES} \
+    skia_warnings_as_errors=0 \
+    skia_giflib_static=1 \
+    skia_libpng_static=1 \
+    skia_zlib_static=1 \
+    skia_freetype_static=1 \
+    skia_no_fontconfig=1 \
+    skia_poppler_enabled=0 \
+    skia_skip_gui=1 \
+    "
+
+try "${SKIA_SRC_DIR}/gyp_skia" || exit
+
+try test -d "${SKIA_OUT}/${BUILD_TYPE}" || exit
+
+try ninja -C "${SKIA_OUT}/${BUILD_TYPE}" || exit
+
diff --git a/platform_tools/barelinux/bin/download_deps b/platform_tools/barelinux/bin/download_deps
new file mode 100755
index 0000000..0676961
--- /dev/null
+++ b/platform_tools/barelinux/bin/download_deps
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Copyright 2014 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# download_deps - download Skia's dependencies for a bare Linux system
+# (the normal dependecies plus giflib, libpng, and zlib.)
+
+try() {
+    # print an error on nonzero return code
+    "$@"
+    local ret=$?
+    if [ $ret != 0 ] ; then
+        echo "'$@' failed and returned ${ret}." >&2
+        return $ret
+    fi
+}
+
+try command -v gclient > /dev/null || exit
+cd "$(dirname "$0")/../../.."
+
+try gclient config --unmanaged --name . \
+    'https://skia.googlesource.com/skia.git' || exit
+
+echo 'target_os = ["barelinux"]' >> ./.gclient
+
+try gclient sync --jobs=1 || exit