Get all of the code to build under Android.bp

Test: compiles and all host-side tests pass
BUG: 65287350
Change-Id: I2dfdc5692308c8510ada64557b6cad6498ad1010
diff --git a/Android.bp b/Android.bp
index d911e9a..561c9cd 100644
--- a/Android.bp
+++ b/Android.bp
@@ -15,24 +15,127 @@
 
 subdirs = [
     "common",
+    "host",
 ]
 
 cc_library_headers {
-  name: "cuttlefish_common_headers",
-  export_include_dirs: ["."],
-  host_supported: true,
+    name: "cuttlefish_common_headers",
+    export_include_dirs: ["."],
+    host_supported: true,
+}
+
+// TODO(b/67435044) Update the include paths and remove this
+cc_library_headers {
+    name: "cuttlefish_glog",
+    export_include_dirs: ["common/libs"],
+    host_supported: true,
 }
 
 cc_defaults {
-  name: "cuttlefish_host",
-  gnu_extensions: false,
-  header_libs: ["cuttlefish_common_headers"],
-  // Build only 64 bit Intel Linux host executables
-  device_supported: false,
-  compile_multilib: "64",
-  target: {
-    darwin: {
-      enabled: false,
+    name: "cuttlefish_host",
+    gnu_extensions: false,
+    header_libs: [
+        "cuttlefish_common_headers",
+        "cuttlefish_kernel_headers",
+    ],
+    // Build only 64 bit Intel Linux host executables
+    device_supported: false,
+    compile_multilib: "64",
+    target: {
+        linux: {
+            host_ldlibs: ["-lrt"],
+            cflags: ["-DCUTTLEFISH_HOST"],
+        },
+        darwin: {
+            enabled: false,
+        },
     },
-  },
+}
+
+cc_library_host_static {
+    name: "vsoc_lib",
+    srcs: [
+        "common/vsoc/lib/compat.cpp",
+        "common/vsoc/lib/e2e_test_region_layout.cpp",
+        "common/vsoc/lib/fb_bcast_layout.cpp",
+        "common/vsoc/lib/gralloc_layout.cpp",
+        "common/vsoc/lib/lock_common.cpp",
+        "common/vsoc/lib/region_view.cpp",
+        "host/vsoc/lib/host_lock.cpp",
+        "host/vsoc/lib/region_control.cpp",
+        "host/vsoc/lib/region_view.cpp",
+    ],
+    header_libs: ["cuttlefish_glog"],
+    static_libs: [
+        "libcuttlefish_fs",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_library_host_static {
+    name: "libvsoc_gralloc",
+    srcs: [
+        "host/vsoc/gralloc/gralloc_buffer_region.cpp",
+    ],
+    header_libs: ["cuttlefish_glog"],
+    static_libs: [
+        "vsoc_lib",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_test_host {
+    name: "circqueue_test",
+    srcs: [
+        "common/vsoc/lib/circqueue_test.cpp",
+    ],
+    static_libs: [
+        "vsoc_lib",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_test_host {
+    name: "lock_test",
+    srcs: [
+        "common/vsoc/lib/lock_test.cpp",
+    ],
+    static_libs: [
+        "vsoc_lib",
+        "libgtest_host",
+        "libbase",
+        "cuttlefish_auto_resources",
+        "libcuttlefish_fs",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_test_host {
+    name: "vsoc_graphics_test",
+    srcs: [
+        "common/vsoc/lib/graphics_test.cpp",
+    ],
+    static_libs: [
+        "vsoc_lib",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_binary_host {
+    name: "host_region_e2e_test",
+    srcs: [
+        "host/vsoc/lib/host_region_e2e_test.cpp",
+    ],
+    static_libs: [
+        "vsoc_lib",
+        "libgtest_host",
+        "libbase",
+        "cuttlefish_auto_resources",
+        "libcuttlefish_fs",
+    ],
+    defaults: ["cuttlefish_host"],
 }
diff --git a/common/Android.bp b/common/Android.bp
index 73c4f07..2d1c3d9 100644
--- a/common/Android.bp
+++ b/common/Android.bp
@@ -15,4 +15,5 @@
 
 subdirs = [
     "libs",
+    "vsoc",
 ]
diff --git a/common/libs/Android.bp b/common/libs/Android.bp
index 9ea8fea..d3e8982 100644
--- a/common/libs/Android.bp
+++ b/common/libs/Android.bp
@@ -15,4 +15,7 @@
 
 subdirs = [
     "auto_resources",
+    "fs",
+    "threads",
+    "time",
 ]
diff --git a/common/libs/auto_resources/Android.bp b/common/libs/auto_resources/Android.bp
index 6d460b1..14ccf5f 100644
--- a/common/libs/auto_resources/Android.bp
+++ b/common/libs/auto_resources/Android.bp
@@ -1,3 +1,18 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 cc_library_host_static {
     name: "cuttlefish_auto_resources",
     srcs: [
@@ -13,8 +28,7 @@
     ],
     static_libs: [
         "cuttlefish_auto_resources",
-	"libgmock",
+        "libgmock",
     ],
     defaults: ["cuttlefish_host"],
 }
-
diff --git a/common/libs/fs/Android.bp b/common/libs/fs/Android.bp
new file mode 100644
index 0000000..a3f9176
--- /dev/null
+++ b/common/libs/fs/Android.bp
@@ -0,0 +1,27 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_host_static {
+    name: "libcuttlefish_fs",
+    srcs: [
+        "gce_fs.cpp",
+        "shared_fd.cpp",
+    ],
+    static_libs: [
+        "cuttlefish_auto_resources",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
diff --git a/common/libs/glog/logging.h b/common/libs/glog/logging.h
index a8dabf1..1660ca6 100644
--- a/common/libs/glog/logging.h
+++ b/common/libs/glog/logging.h
@@ -17,6 +17,20 @@
 
 #ifdef ANDROID
 #include <android-base/logging.h>
-#else
+
+#if defined(CUTTLEFISH_HOST)
+
+// Host code came to rely on extensions that were not present in Android
+// logging.
+
+extern bool FLAGS_debug;
+
+#define DLOG(LEVEL)                                 \
+  if (FLAGS_debug) LOG(LEVEL)
+
+using ::android::base::INFO;
+
+#endif  // CUTTLEFISH_HOST
+#else  // DEBIAN_HOST (by elimination)
 #include <glog/logging.h>
 #endif
diff --git a/common/libs/threads/Android.bp b/common/libs/threads/Android.bp
new file mode 100644
index 0000000..9ddb2c9
--- /dev/null
+++ b/common/libs/threads/Android.bp
@@ -0,0 +1,26 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_test_host {
+    name: "cuttlefish_thread_test",
+    srcs: [
+        "cuttlefish_thread_test.cpp",
+    ],
+    static_libs: [
+        "cuttlefish_time",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
diff --git a/common/libs/threads/pthread.h b/common/libs/threads/cuttlefish_thread.h
similarity index 95%
rename from common/libs/threads/pthread.h
rename to common/libs/threads/cuttlefish_thread.h
index ba774b5..8748955 100644
--- a/common/libs/threads/pthread.h
+++ b/common/libs/threads/cuttlefish_thread.h
@@ -1,3 +1,4 @@
+#pragma once
 /*
  * Copyright (C) 2016 The Android Open Source Project
  *
@@ -13,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef CUTTLEFISH_COMMON_COMMON_LIBS_THREADS_PTHREAD_H_
-#define CUTTLEFISH_COMMON_COMMON_LIBS_THREADS_PTHREAD_H_
 
 // Concurreny classess for Cloud Android projects.
 //
@@ -168,5 +167,3 @@
 };
 
 }  // namespace avd
-
-#endif  // CUTTLEFISH_COMMON_COMMON_LIBS_THREADS_PTHREAD_H_
diff --git a/common/libs/threads/pthread_test.cpp b/common/libs/threads/cuttlefish_thread_test.cpp
similarity index 89%
rename from common/libs/threads/pthread_test.cpp
rename to common/libs/threads/cuttlefish_thread_test.cpp
index b5f93c8..9ea1a5d 100644
--- a/common/libs/threads/pthread_test.cpp
+++ b/common/libs/threads/cuttlefish_thread_test.cpp
@@ -13,9 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 
-#include "common/libs/glog/logging.h"
+#include <android-base/logging.h>
 #include "common/libs/threads/thunkers.h"
 #include "common/libs/time/monotonic_time.h"
 
@@ -69,7 +69,7 @@
 
   void* FastThread() {
     mutex_.Lock();
-    LOG_IF(FATAL, busy_ != NULL);
+    CHECK(busy_ == NULL);
     busy_ = "FastThread";
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
     stage_ = 1;
@@ -77,9 +77,9 @@
     mutex_.Unlock();
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(10));
     mutex_.Lock();
-    LOG_IF(FATAL, busy_ != NULL);
+    CHECK(busy_ == NULL);
     busy_ = "FastThread";
-    LOG_IF(FATAL, stage_ != 2);
+    CHECK(stage_ == 2);
     stage_ = FINISHED;
     busy_ = NULL;
     mutex_.Unlock();
@@ -89,9 +89,9 @@
   void* SlowThread() {
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(50));
     mutex_.Lock();
-    LOG_IF(FATAL, busy_ != NULL);
+    CHECK(busy_== NULL);
     busy_ = "SlowThread";
-    LOG_IF(FATAL, stage_ != 1);
+    CHECK(stage_ == 1);
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
     stage_ = 2;
     busy_ = NULL;
@@ -134,12 +134,12 @@
     mutex_.Unlock();
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
     mutex_.Lock();
-    LOG_IF(FATAL, signalled_ != 1);
+    CHECK(signalled_== 1);
     cond_.NotifyOne();
     mutex_.Unlock();
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
     mutex_.Lock();
-    LOG_IF(FATAL, signalled_ != 2);
+    CHECK(signalled_ == 2);
     mutex_.Unlock();
     return NULL;
   }
@@ -185,7 +185,7 @@
     mutex_.Unlock();
     SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
     mutex_.Lock();
-    LOG_IF(FATAL, signalled_ != 2);
+    CHECK(signalled_ == 2);
     mutex_.Unlock();
     return NULL;
   }
@@ -226,7 +226,7 @@
   void* SignalThread() {
     SleepUntil(start_ + Milliseconds(200));
     mutex_.Lock();
-    LOG_IF(FATAL, stage_ != 2);
+    CHECK(stage_ == 2);
     cond_.NotifyOne();
     stage_ = 3;
     mutex_.Unlock();
@@ -235,17 +235,17 @@
 
   void* WaitThread() {
     mutex_.Lock();
-    LOG_IF(FATAL, stage_ != 0);
+    CHECK(stage_ == 0);
     stage_ = 1;
     cond_.WaitUntil(start_ + Milliseconds(50));
     MonotonicTimePoint current(MonotonicTimePoint::Now());
-    LOG_IF(FATAL, Milliseconds(current - start_).count() < 50);
-    LOG_IF(FATAL, Milliseconds(current - start_).count() > 100);
+    CHECK(Milliseconds(current - start_).count() >= 50);
+    CHECK(Milliseconds(current - start_).count() <= 100);
     stage_ = 2;
     cond_.WaitUntil(start_ + Milliseconds(1000));
     current = MonotonicTimePoint::Now();
-    LOG_IF(FATAL, Milliseconds(current - start_).count() > 500);
-    LOG_IF(FATAL, stage_ != 3);
+    CHECK(Milliseconds(current - start_).count() <= 500);
+    CHECK(stage_ == 3);
     stage_ = FINISHED;
     mutex_.Unlock();
     return NULL;
@@ -257,9 +257,8 @@
   MonotonicTimePoint start_;
 };
 
-int main(int argc, char** argv) {
-  ::google::InitGoogleLogging(argv[0]);
-  ::google::LogToStderr();
+int main(int, char**argv) {
+  ::android::base::InitLogging(argv, android::base::StderrLogger);
   MutexTest mt;
   mt.Run();
   NotifyOneTest nt1;
diff --git a/common/libs/time/Android.bp b/common/libs/time/Android.bp
new file mode 100644
index 0000000..fd5e097
--- /dev/null
+++ b/common/libs/time/Android.bp
@@ -0,0 +1,33 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_host_static {
+    name: "cuttlefish_time",
+    srcs: [
+        "monotonic_time.cpp",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_test_host {
+    name: "monotonic_time_test",
+    srcs: [
+        "monotonic_time_test.cpp",
+    ],
+    static_libs: [
+        "cuttlefish_time",
+    ],
+    defaults: ["cuttlefish_host"],
+}
diff --git a/common/vsoc/Android.bp b/common/vsoc/Android.bp
new file mode 100644
index 0000000..b3eaa7a
--- /dev/null
+++ b/common/vsoc/Android.bp
@@ -0,0 +1,18 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+subdirs = [
+    "framebuffer",
+]
diff --git a/common/vsoc/framebuffer/Android.bp b/common/vsoc/framebuffer/Android.bp
new file mode 100644
index 0000000..f30b18b
--- /dev/null
+++ b/common/vsoc/framebuffer/Android.bp
@@ -0,0 +1,40 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_library_host_static {
+    name: "libvsoc_framebuffer",
+    srcs: [
+        "fb_bcast_region.cpp",
+    ],
+    static_libs: [
+        "vsoc_lib",
+        "libbase",
+        "cuttlefish_auto_resources",
+    ],
+    defaults: ["cuttlefish_host"],
+}
+
+cc_binary_host {
+    name: "test_framebuffer",
+    srcs: ["test_fb.cpp"],
+    static_libs: [
+        "libvsoc_framebuffer",
+        "vsoc_lib",
+        "libbase",
+        "cuttlefish_auto_resources",
+        "libcuttlefish_fs",
+    ],
+    defaults: ["cuttlefish_host"],
+}
diff --git a/common/vsoc/lib/compat.cpp b/common/vsoc/lib/compat.cpp
index 0453456..3b8deb2 100644
--- a/common/vsoc/lib/compat.cpp
+++ b/common/vsoc/lib/compat.cpp
@@ -21,7 +21,7 @@
 
 namespace vsoc {
 
-#ifndef ANDROID
+#ifdef CUTTLEFISH_HOST
 uint32_t gettid() {
   thread_local uint32_t tid = syscall(SYS_gettid);
   return tid;
diff --git a/common/vsoc/lib/compat.h b/common/vsoc/lib/compat.h
index d7c73d9..8f3355c 100644
--- a/common/vsoc/lib/compat.h
+++ b/common/vsoc/lib/compat.h
@@ -21,7 +21,7 @@
 #include <stdint.h>
 
 namespace vsoc {
-#ifndef ANDROID
+#ifdef CUTTLEFISH_HOST
 // Things that are missing on the host
 uint32_t gettid();
 #endif
diff --git a/common/vsoc/lib/lock_test.cpp b/common/vsoc/lib/lock_test.cpp
index ba32493..d09b5a4 100644
--- a/common/vsoc/lib/lock_test.cpp
+++ b/common/vsoc/lib/lock_test.cpp
@@ -22,10 +22,10 @@
 
 #include "common/vsoc/lib/region_view.h"
 
-#ifdef ANDROID
-using MyLock = vsoc::layout::GuestLock;
-#else
+#ifdef CUTTLEFISH_HOST
 using MyLock = vsoc::layout::HostLock;
+#else
+using MyLock = vsoc::layout::GuestLock;
 #endif
 
 class SimpleLocker {
diff --git a/common/vsoc/shm/base.h b/common/vsoc/shm/base.h
index 7bdbc9c..2f65415 100644
--- a/common/vsoc/shm/base.h
+++ b/common/vsoc/shm/base.h
@@ -51,12 +51,12 @@
   static const uint32_t Guest = 1;
   static const uint32_t Host = 2;
   static const uint32_t Both = 3;
-#ifdef ANDROID
-  static const uint32_t OurSide = Guest;
-  static const uint32_t Peer = Host;
-#else
+#ifdef CUTTLEFISH_HOST
   static const uint32_t OurSide = Host;
   static const uint32_t Peer = Guest;
+#else
+  static const uint32_t OurSide = Guest;
+  static const uint32_t Peer = Host;
 #endif
 
   uint32_t value_;
diff --git a/common/vsoc/shm/lock.h b/common/vsoc/shm/lock.h
index 843401c..433714f 100644
--- a/common/vsoc/shm/lock.h
+++ b/common/vsoc/shm/lock.h
@@ -136,7 +136,7 @@
  */
 class GuestLock : public WaitingLockBase {
  public:
-#ifdef ANDROID
+#ifndef CUTTLEFISH_HOST
   void Lock();
   void Unlock();
 #endif
@@ -153,7 +153,7 @@
  */
 class HostLock : public WaitingLockBase {
  public:
-#ifndef ANDROID
+#ifdef CUTTLEFISH_HOST
   void Lock();
   void Unlock();
 #endif
diff --git a/guest/commands/audio/vsoc_audio.cpp b/guest/commands/audio/vsoc_audio.cpp
index 0b531a3..d0e958a 100644
--- a/guest/commands/audio/vsoc_audio.cpp
+++ b/guest/commands/audio/vsoc_audio.cpp
@@ -26,7 +26,7 @@
 
 #include "common/libs/auto_resources/auto_resources.h"
 #include "common/libs/fs/shared_select.h"
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 #include "common/libs/threads/thunkers.h"
 #include "guest/commands/audio/vsoc_audio.h"
 #include "guest/commands/audio/vsoc_audio_input_stream.h"
diff --git a/guest/commands/audio/vsoc_audio.h b/guest/commands/audio/vsoc_audio.h
index 4f92e31..d487d50 100644
--- a/guest/commands/audio/vsoc_audio.h
+++ b/guest/commands/audio/vsoc_audio.h
@@ -19,7 +19,7 @@
 #include <map>
 
 #include "common/libs/fs/shared_fd.h"
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 #include "guest/commands/audio/audio_hal.h"
 #include "guest/commands/audio/vsoc_audio_input_stream.h"
 #include "guest/commands/audio/vsoc_audio_message.h"
diff --git a/guest/commands/usbforward/usb_server.h b/guest/commands/usbforward/usb_server.h
index 821026a..942e16e 100644
--- a/guest/commands/usbforward/usb_server.h
+++ b/guest/commands/usbforward/usb_server.h
@@ -21,7 +21,7 @@
 #include <libusb/libusb.h>
 
 #include "common/libs/fs/shared_fd.h"
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 #include "guest/commands/usbforward/transport_request.h"
 
 namespace usb_forward {
diff --git a/guest/hals/camera/EmulatedCameraFactory.h b/guest/hals/camera/EmulatedCameraFactory.h
index 96c51f8..cbf41b2 100755
--- a/guest/hals/camera/EmulatedCameraFactory.h
+++ b/guest/hals/camera/EmulatedCameraFactory.h
@@ -20,7 +20,7 @@
 #include <utils/RefBase.h>
 
 #include <utils/Vector.h>
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 #include "guest/libs/platform_support/api_level_fixes.h"
 #include "CameraConfiguration.h"
 #include "EmulatedBaseCamera.h"
diff --git a/guest/hals/sensors/vsoc_sensors.h b/guest/hals/sensors/vsoc_sensors.h
index a8e2dab..dbbeddd 100644
--- a/guest/hals/sensors/vsoc_sensors.h
+++ b/guest/hals/sensors/vsoc_sensors.h
@@ -17,7 +17,7 @@
 
 #include <vector>
 
-#include "common/libs/threads/pthread.h"
+#include "common/libs/threads/cuttlefish_thread.h"
 #include "common/libs/fs/shared_fd.h"
 #include "guest/hals/sensors/sensors.h"
 #include "guest/hals/sensors/sensors_hal.h"
diff --git a/host/Android.bp b/host/Android.bp
new file mode 100644
index 0000000..68a03c9
--- /dev/null
+++ b/host/Android.bp
@@ -0,0 +1,18 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+subdirs = [
+    "frontend",
+]
diff --git a/host/frontend/Android.bp b/host/frontend/Android.bp
new file mode 100644
index 0000000..bf82b3c
--- /dev/null
+++ b/host/frontend/Android.bp
@@ -0,0 +1,18 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+subdirs = [
+    "vnc_server",
+]
diff --git a/host/frontend/vnc_server/Android.bp b/host/frontend/vnc_server/Android.bp
new file mode 100644
index 0000000..be12249
--- /dev/null
+++ b/host/frontend/vnc_server/Android.bp
@@ -0,0 +1,43 @@
+//
+// Copyright (C) 2017 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_binary_host {
+    name: "vnc_server",
+    srcs: [
+        "blackboard.cpp",
+        "frame_buffer_watcher.cpp",
+        "jpeg_compressor.cpp",
+        "main.cpp",
+        "simulated_hw_composer.cpp",
+        "tcp_socket.cpp",
+        "virtual_inputs.cpp",
+        "virtual_input_device.cpp",
+        "vnc_client_connection.cpp",
+        "vnc_server.cpp",
+    ],
+    header_libs: [
+        "cuttlefish_glog",
+    ],
+    static_libs: [
+        "libjpeg",
+        "libvsoc_framebuffer",
+        "libvsoc_gralloc",
+        "libcuttlefish_fs",
+        "vsoc_lib",
+        "cuttlefish_auto_resources",
+        "libbase",
+    ],
+    defaults: ["cuttlefish_host"],
+}
diff --git a/host/frontend/vnc_server/main.cpp b/host/frontend/vnc_server/main.cpp
index 3692aac..7070848 100644
--- a/host/frontend/vnc_server/main.cpp
+++ b/host/frontend/vnc_server/main.cpp
@@ -14,18 +14,57 @@
  * limitations under the License.
  */
 
+#include <getopt.h>
 #include <algorithm>
 #include <string>
 
 #include "host/frontend/vnc_server/vnc_server.h"
 
-DEFINE_bool(agressive, false, "Whether to use agressive server");
-DEFINE_int32(port, 6444, "Port where to listen for connections");
+bool FLAGS_agressive = false;
+bool FLAGS_debug = false;
+std::string FLAGS_input_socket("/tmp/android-cuttlefish-1-input");
+
+bool FLAGS_port = 6444;
+
+static struct option opts[] = {
+  {"agressive", no_argument, NULL, 'a'},
+  {"debug", no_argument, NULL, 'd'},
+  {"input_socket", required_argument, NULL, 'i'},
+  {"port", required_argument, NULL, 'p'},
+  {0, 0, 0, 0}
+};
 
 int main(int argc, char* argv[]) {
-  google::InitGoogleLogging(argv[0]);
-  google::InstallFailureSignalHandler();
-  google::ParseCommandLineFlags(&argc, &argv, true);
+  using ::android::base::ERROR;
+  ::android::base::InitLogging(argv, android::base::StderrLogger);
+  long port = -1;
+  char *endp = NULL;
+  bool error = false;
+  char c;
+  while ((c = getopt_long(argc, argv, "", opts, nullptr)) != -1) {
+    switch(c) {
+      case 'a':
+        FLAGS_agressive = true;
+        break;
+      case 'd':
+        FLAGS_debug = true;
+        break;
+      case 'i':
+        FLAGS_input_socket = optarg;
+        break;
+      case 'p':
+        port = strtol(optarg, &endp, 10);
+        if (*endp || (port <= 0) || (port > 65536)) {
+          LOG(ERROR) << "Port must be an integer > 0 and < 65536";
+          error = true;
+        }
+        FLAGS_port = port;
+        break;
+    }
+  }
+  if (error) {
+    exit(2);
+  }
   avd::vnc::VncServer vnc_server(FLAGS_port, FLAGS_agressive);
   vnc_server.MainLoop();
 }
diff --git a/host/frontend/vnc_server/virtual_inputs.cpp b/host/frontend/vnc_server/virtual_inputs.cpp
index 92b27e3..e04d3a2 100644
--- a/host/frontend/vnc_server/virtual_inputs.cpp
+++ b/host/frontend/vnc_server/virtual_inputs.cpp
@@ -19,11 +19,7 @@
 #include <mutex>
 #include <thread>
 
-#include <gflags/gflags.h>
-
-DEFINE_string(input_socket, "/tmp/android-cuttlefish-1-input",
-              "The name of unix socket where the monkey server is listening "
-              "for input commands");
+extern std::string FLAGS_input_socket;
 
 using avd::vnc::VirtualInputs;