libweave: Build weave example for ubuntu

BUG=brillo:1275
TEST=libweave/examples/ubuntu/build.sh

Change-Id: I6b0d97cc27077c8d64d095419cce34da3d79b0cd
Reviewed-on: https://chromium-review.googlesource.com/297005
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Trybot-Ready: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/libweave/examples/ubuntu/build.sh b/libweave/examples/ubuntu/build.sh
new file mode 100755
index 0000000..96d0ab6
--- /dev/null
+++ b/libweave/examples/ubuntu/build.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+# Copyright 2015 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
+ROOT_DIR=$(cd -P -- "$(dirname -- "$0")/../.." && pwd -P)
+
+cd $ROOT_DIR
+
+gyp -Ilibweave_common.gypi --toplevel-dir=. -f ninja $DIR/weave.gyp
+
+if [ -z "$BUILD_CONFIG" ]; then
+   export BUILD_CONFIG=Debug
+fi
+
+export BUILD_TARGET=$*
+if [ -z "$BUILD_TARGET" ]; then
+   export BUILD_TARGET="weave libweave_testrunner"
+fi
+
+export CORES=`cat /proc/cpuinfo | grep processor | wc -l`
+ninja -j $CORES -C out/${BUILD_CONFIG} $BUILD_TARGET || exit 1
+
+if [[ $BUILD_TARGET == *"libweave_testrunner"* ]]; then
+  out/${BUILD_CONFIG}/libweave_testrunner
+fi
diff --git a/libweave/examples/ubuntu/weave.gyp b/libweave/examples/ubuntu/weave.gyp
new file mode 100644
index 0000000..0aa4e3a
--- /dev/null
+++ b/libweave/examples/ubuntu/weave.gyp
@@ -0,0 +1,32 @@
+{
+  'targets': [
+    {
+      'target_name': 'weave',
+      'type': 'executable',
+      'cflags': ['-pthread'],
+      'sources': [
+        'main.cc',
+        'file_config_store.cc',
+        'event_task_runner.cc',
+        'curl_http_client.cc',
+        'network_manager.cc',
+        'avahi_client.cc',
+        'event_http_server.cc',
+      ],
+      'dependencies': [
+        '../../libweave_standalone.gyp:libweave',
+      ],
+      'libraries': [
+        '-levent',
+        '-lcrypto',
+        '-lexpat',
+        '-lcurl',
+        '-lpthread',
+        '-lssl',
+        '-lavahi-common',
+        '-lavahi-client',
+        '-levent_openssl',
+      ]
+    }
+  ]
+}
diff --git a/libweave/libweave_common.gypi b/libweave/libweave_common.gypi
new file mode 100644
index 0000000..c6bdd78
--- /dev/null
+++ b/libweave/libweave_common.gypi
@@ -0,0 +1,43 @@
+{
+  'target_defaults': {
+    'configurations': {
+      'Release': {
+        'defines': [
+          'NDEBUG',
+        ],
+        'cflags': [
+          '-Os',
+        ],
+      },
+      'Debug': {
+        'defines': [
+          '_DEBUG',
+        ],
+        'cflags': [
+          '-Og',
+        ],
+      },
+    },
+    'include_dirs': [
+      '.',
+      '..',
+      'include',
+      'external',
+      'third_party/include',
+      'third_party/modp_b64/modp_b64',
+    ],
+    'cflags!': ['-fPIE'],
+    'cflags': [
+      '-fPIC',
+      '-fvisibility=hidden',
+      '-Wl,--exclude-libs,ALL',
+      '--std=c++11',
+      '-Wno-format-nonliteral',
+      '-Wno-char-subscripts',
+      #'-Wno-deprecated-register',
+    ],
+    'libraries': [
+      '-L../../third_party/lib',
+    ],
+  },
+}
diff --git a/libweave/libweave_standalone.gyp b/libweave/libweave_standalone.gyp
new file mode 100644
index 0000000..6c825ac
--- /dev/null
+++ b/libweave/libweave_standalone.gyp
@@ -0,0 +1,80 @@
+{
+  'includes': [
+    'libweave.gypi',
+  ],
+  'target_defaults': {
+    'libraries': [
+      '-lcrypto',
+      '-lexpat',
+      '-lpthread',
+      '-lgtest',
+      '-lgmock',
+    ],
+  },
+  'targets': [
+    {
+      'target_name': 'libweave_common',
+      'type': 'static_library',
+      'include_dirs': [
+        '../libweave/external',
+      ],
+      'sources': [
+        '<@(weave_sources)',
+        '<@(base_sources)',
+      ],
+    },
+    {
+      'target_name': 'libweave',
+      'type': 'shared_library',
+      'include_dirs': [
+        '../libweave/external',
+      ],
+      'dependencies': [
+        'libweave_common',
+      ],
+      'sources': [
+        'src/empty.cc'
+      ],
+    },
+    {
+      'target_name': 'libweave-test',
+      'type': 'static_library',
+      'standalone_static_library': 1,
+      'include_dirs': [
+        '../libweave/external',
+      ],
+      'sources': [
+        '<@(weave_test_sources)',
+      ],
+    },
+    {
+      'target_name': 'libweave_testrunner',
+      'type': 'executable',
+      'include_dirs': [
+        '../libweave/external',
+      ],
+      'dependencies': [
+        'libweave_common',
+        'libweave-test',
+      ],
+      'sources': [
+        '<@(weave_unittest_sources)',
+        '<@(base_unittests)',
+      ],
+    },
+    {
+      'target_name': 'libweave_exports_testrunner',
+      'type': 'executable',
+      'include_dirs': [
+        '../libweave/external',
+      ],
+      'dependencies': [
+        'libweave',
+        'libweave-test',
+      ],
+      'sources': [
+        '<@(weave_exports_unittest_sources)',
+      ],
+    },
+  ],
+}