Bazel: migrate to self-contained workspace.

Change-Id: I19b14578da8bc7f207aadd9940499e4c147c97e4
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Reviewed-on: https://nginx-review.googlesource.com/2402
Reviewed-by: Gurgen Hrachyan <gugo@google.com>
diff --git a/BUILD b/BUILD
index b55f224..0b0e6a9 100644
--- a/BUILD
+++ b/BUILD
@@ -26,18 +26,7 @@
 
 exports_files(["LICENSE"])
 
-load("//:build.bzl", "nginx_copts")
-
-genrule(
-    name = "ngx_modules_c",
-    srcs = [
-        "//nginx:modules",
-    ],
-    outs = [
-        "ngx_modules.c",
-    ],
-    cmd = "cp -p $(<) $(@)",
-)
+load("@nginx//:build.bzl", "nginx_copts")
 
 cc_library(
     name = "http_brotli_filter",
@@ -53,8 +42,8 @@
     ],
     deps = [
         "//external:brotli_enc",
-        "//nginx:core",
-        "//nginx:http",
+        "@nginx//:core",
+        "@nginx//:http",
     ],
 )
 
@@ -71,20 +60,20 @@
         "//visibility:public",
     ],
     deps = [
-        "//nginx:core",
-        "//nginx:http",
+        "@nginx//:core",
+        "@nginx//:http",
     ],
 )
 
 cc_binary(
     name = "nginx",
     srcs = [
-        "ngx_modules.c",
+        "@nginx//:modules",
     ],
     copts = nginx_copts,
     deps = [
         ":http_brotli_filter",
         ":http_brotli_static",
-        "//nginx:core",
+        "@nginx//:core",
     ],
 )
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..902b2dd
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,46 @@
+# Copyright (C) 2015-2016 Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+workspace(name = "ngx_brotli")
+
+git_repository(
+    name = "io_brotli",
+    commit = "e7f47b94709ee4991b49103e6ada78a24d950893",  # 2016-08-24
+    remote = "https://github.com/google/brotli.git",
+)
+
+bind(
+    name = "brotli_enc",
+    actual = "@io_brotli//:brotli_enc",
+)
+
+git_repository(
+    name = "nginx",
+    commit = "2a881edaa3e60c9392e90efe9f6bfc25024e6e3c",  # 2016-08-23
+    remote = "https://nginx.googlesource.com/nginx",
+)
+
+load("@nginx//:build.bzl", "nginx_repositories")
+
+nginx_repositories(bind = True)
diff --git a/src/ngx_http_brotli_filter_module.c b/src/ngx_http_brotli_filter_module.c
index 0f55015..af7f322 100644
--- a/src/ngx_http_brotli_filter_module.c
+++ b/src/ngx_http_brotli_filter_module.c
@@ -10,7 +10,11 @@
 #include <ngx_core.h>
 #include <ngx_http.h>
 
+#if (NGX_BAZEL)
+#include <brotli/encode.h>
+#else
 #include <brotli/enc/encode.h>
+#endif
 
 
 typedef struct {