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/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',
+                    ]
+                  }],
+                ],
+              }
+            },
+          }
+        ]
+      ]
+    }
+  ]
 }