GN: build skiaserve

I trimmed the libmicrohttpd sources and defines down to the minimum needed to build and run.  This builds and runs on Linux and Android for me.

Request.h was missing an include for SkTypes.h, which supplies the default for SK_GPU_SUPPORTED if not otherwise defined.

To build on Android, exit() -> _exit().

build.py was unused.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2367513002

NOTREECHECKS=true

Review-Url: https://codereview.chromium.org/2367513002
diff --git a/BUILD.gn b/BUILD.gn
index 4501af1..26a23be 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -920,4 +920,36 @@
     ]
     testonly = true
   }
+
+  executable("skiaserve") {
+    sources = [
+      "tools/skiaserve/Request.cpp",
+      "tools/skiaserve/Response.cpp",
+      "tools/skiaserve/skiaserve.cpp",
+      "tools/skiaserve/urlhandlers/BatchBoundsHandler.cpp",
+      "tools/skiaserve/urlhandlers/BatchesHandler.cpp",
+      "tools/skiaserve/urlhandlers/BreakHandler.cpp",
+      "tools/skiaserve/urlhandlers/ClipAlphaHandler.cpp",
+      "tools/skiaserve/urlhandlers/CmdHandler.cpp",
+      "tools/skiaserve/urlhandlers/ColorModeHandler.cpp",
+      "tools/skiaserve/urlhandlers/DataHandler.cpp",
+      "tools/skiaserve/urlhandlers/DownloadHandler.cpp",
+      "tools/skiaserve/urlhandlers/EnableGPUHandler.cpp",
+      "tools/skiaserve/urlhandlers/ImgHandler.cpp",
+      "tools/skiaserve/urlhandlers/InfoHandler.cpp",
+      "tools/skiaserve/urlhandlers/PostHandler.cpp",
+      "tools/skiaserve/urlhandlers/QuitHandler.cpp",
+      "tools/skiaserve/urlhandlers/RootHandler.cpp",
+    ]
+    deps = [
+      ":flags",
+      ":gpu_tool_utils",
+      ":skia",
+      ":tool_utils",
+      "//third_party/jsoncpp",
+      "//third_party/libmicrohttpd",
+      "//third_party/libpng",
+    ]
+    testonly = true
+  }
 }
diff --git a/third_party/libmicrohttpd/BUILD.gn b/third_party/libmicrohttpd/BUILD.gn
new file mode 100644
index 0000000..7238077
--- /dev/null
+++ b/third_party/libmicrohttpd/BUILD.gn
@@ -0,0 +1,36 @@
+# Copyright 2016 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+declare_args() {
+}
+
+import("../third_party.gni")
+
+third_party("libmicrohttpd") {
+  public_include_dirs = [ "../externals/microhttpd/src/include" ]
+
+  include_dirs = [ "." ]
+  sources = [
+    "../externals/microhttpd/src/microhttpd/base64.c",
+    "../externals/microhttpd/src/microhttpd/connection.c",
+    "../externals/microhttpd/src/microhttpd/daemon.c",
+    "../externals/microhttpd/src/microhttpd/internal.c",
+    "../externals/microhttpd/src/microhttpd/memorypool.c",
+    "../externals/microhttpd/src/microhttpd/postprocessor.c",
+    "../externals/microhttpd/src/microhttpd/reason_phrase.c",
+    "../externals/microhttpd/src/microhttpd/response.c",
+  ]
+
+  defines = [ "DAUTH_SUPPORT=1" ]
+
+  if (!is_win) {
+    defines += [
+      "HAVE_NETINET_IN_H=1",
+      "HAVE_PTHREAD_H=1",
+      "HAVE_SYS_SOCKET_H=1",
+      "MHD_USE_POSIX_THREADS=1",
+    ]
+  }
+}
diff --git a/third_party/libmicrohttpd/build.py b/third_party/libmicrohttpd/build.py
deleted file mode 100644
index f09a360..0000000
--- a/third_party/libmicrohttpd/build.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright 2016 Google Inc.
-#
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# this script will configure and build microhttpd in a temp directory and then
-# copy the static library generated to a destination folder
-import argparse
-import os
-from subprocess import call
-import shutil
-import tempfile
-
-parser = argparse.ArgumentParser()
-parser.add_argument("--src", help="microhttpd src directory")
-parser.add_argument("--out", help="build directory")
-parser.add_argument("--dst", help="output for final build products")
-args = parser.parse_args()
-
-out_dir = args.out
-cwd = os.getcwd()
-try:
-  os.makedirs(out_dir)
-except OSError as e:
-  pass
-
-os.chdir(out_dir)
-call([os.path.join(cwd, args.src, "configure"),
-      "--disable-doc",
-      "--disable-examples",
-      "--enable-https=no",
-      "--disable-curl",
-      "--enable-spdy=no",
-      "--enable-shared=no"])
-call(["make", "--silent"])
-call(["cp",
-      "src/microhttpd/.libs/libmicrohttpd.a",
-      os.path.join(cwd, args.dst)])
diff --git a/tools/skiaserve/Request.h b/tools/skiaserve/Request.h
index 7a5daf5..0b6ed3b 100644
--- a/tools/skiaserve/Request.h
+++ b/tools/skiaserve/Request.h
@@ -8,6 +8,8 @@
 #ifndef Request_DEFINED
 #define Request_DEFINED
 
+#include "SkTypes.h"
+
 #if SK_SUPPORT_GPU
 #include "GrContextFactory.h"
 #endif
diff --git a/tools/skiaserve/urlhandlers/QuitHandler.cpp b/tools/skiaserve/urlhandlers/QuitHandler.cpp
index a9196a0..fa8045c 100644
--- a/tools/skiaserve/urlhandlers/QuitHandler.cpp
+++ b/tools/skiaserve/urlhandlers/QuitHandler.cpp
@@ -22,5 +22,5 @@
 int QuitHandler::handle(Request* request, MHD_Connection* connection,
                         const char* url, const char* method,
                         const char* upload_data, size_t* upload_data_size) {
-    exit(0);
+    _exit(0);
 }