TS-2885 Change LuaJIT to build statically, and add --disable-luajit
Conflicts:
	CHANGES
diff --git a/CHANGES b/CHANGES
index 41d1671..07fd5ff 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.0.0
 
+  *) [TS-2885] Change LuaJIT to build statically, and add --disable-luajit. This
+   is an option that will eventually be removed as we make LuaJIT mandatory.
+
   *) [TS-2886] Fix regression where body factory is not used.
 
   *) [TS-2881] Redirection handling broken
diff --git a/configure.ac b/configure.ac
index 8bf3d85..bd20b70 100644
--- a/configure.ac
+++ b/configure.ac
@@ -486,6 +486,21 @@
 AM_CONDITIONAL([ENABLE_CPPAPI], [ test "x${enable_cppapi}" = "xyes" ])
 
 #
+# Disable LuaJIT? This is a interrim option, when Lua becomes part of the core
+# requirements, we will remove this option.
+#
+AC_MSG_CHECKING([whether to disable LuaJIT])
+AC_ARG_ENABLE([luajit],
+  [AS_HELP_STRING([--disable-luajit],[turn off LuaJIT])],
+  [],
+  [enable_luajit="yes"]
+)
+AC_MSG_RESULT([$enable_luajit])
+TS_ARG_ENABLE_VAR([use], [luajit])
+AC_SUBST(use_luajit)
+AM_CONDITIONAL([ENABLE_LUAJIT], [ test "x${enable_luajit}" = "xyes" ])
+
+#
 # Installation directories
 # For each var the following is evaluated
 # foo      Standard variable  eg. ${prefix}/foo
@@ -1862,29 +1877,6 @@
   iocore/net/Makefile
   iocore/utils/Makefile
   lib/Makefile
-  lib/atscppapi/Makefile
-  lib/atscppapi/examples/Makefile
-  lib/atscppapi/examples/async_http_fetch/Makefile
-  lib/atscppapi/examples/async_timer/Makefile
-  lib/atscppapi/examples/clientredirect/Makefile
-  lib/atscppapi/examples/clientrequest/Makefile
-  lib/atscppapi/examples/customresponse/Makefile
-  lib/atscppapi/examples/boom/Makefile
-  lib/atscppapi/examples/globalhook/Makefile
-  lib/atscppapi/examples/gzip_transformation/Makefile
-  lib/atscppapi/examples/helloworld/Makefile
-  lib/atscppapi/examples/intercept/Makefile
-  lib/atscppapi/examples/internal_transaction_handling/Makefile
-  lib/atscppapi/examples/logger_example/Makefile
-  lib/atscppapi/examples/multiple_transaction_hooks/Makefile
-  lib/atscppapi/examples/null_transformation_plugin/Makefile
-  lib/atscppapi/examples/post_buffer/Makefile
-  lib/atscppapi/examples/remap_plugin/Makefile
-  lib/atscppapi/examples/serverresponse/Makefile
-  lib/atscppapi/examples/stat_example/Makefile
-  lib/atscppapi/examples/timeout_example/Makefile
-  lib/atscppapi/examples/transactionhook/Makefile
-  lib/atscppapi/src/Makefile
   lib/perl/Makefile
   lib/perl/lib/Apache/TS.pm
   lib/records/Makefile
@@ -1909,27 +1901,6 @@
   plugins/regex_remap/Makefile
   plugins/stats_over_http/Makefile
   plugins/tcpinfo/Makefile
-  plugins/experimental/Makefile
-  plugins/experimental/authproxy/Makefile
-  plugins/experimental/background_fetch/Makefile
-  plugins/experimental/balancer/Makefile
-  plugins/experimental/buffer_upload/Makefile
-  plugins/experimental/channel_stats/Makefile
-  plugins/experimental/collapsed_connection/Makefile
-  plugins/experimental/custom_redirect/Makefile
-  plugins/experimental/escalate/Makefile
-  plugins/experimental/esi/Makefile
-  plugins/experimental/geoip_acl/Makefile
-  plugins/experimental/healthchecks/Makefile
-  plugins/experimental/hipes/Makefile
-  plugins/experimental/metalink/Makefile
-  plugins/experimental/remap_stats/Makefile
-  plugins/experimental/regex_revalidate/Makefile
-  plugins/experimental/s3_auth/Makefile
-  plugins/experimental/stale_while_revalidate/Makefile
-  plugins/experimental/ts_lua/Makefile
-  plugins/experimental/url_sig/Makefile
-  plugins/experimental/xdebug/Makefile
   proxy/Makefile
   proxy/api/ts/Makefile
   proxy/config/Makefile
@@ -1953,6 +1924,59 @@
   tools/tsxs
 ])
 
+AS_IF([test "x$enable_experimental_plugins" = xyes], [
+  AC_CONFIG_FILES([
+    plugins/experimental/Makefile
+    plugins/experimental/authproxy/Makefile
+    plugins/experimental/background_fetch/Makefile
+    plugins/experimental/balancer/Makefile
+    plugins/experimental/buffer_upload/Makefile
+    plugins/experimental/channel_stats/Makefile
+    plugins/experimental/collapsed_connection/Makefile
+    plugins/experimental/custom_redirect/Makefile
+    plugins/experimental/escalate/Makefile
+    plugins/experimental/esi/Makefile
+    plugins/experimental/geoip_acl/Makefile
+    plugins/experimental/healthchecks/Makefile
+    plugins/experimental/hipes/Makefile
+    plugins/experimental/metalink/Makefile
+    plugins/experimental/remap_stats/Makefile
+    plugins/experimental/regex_revalidate/Makefile
+    plugins/experimental/s3_auth/Makefile
+    plugins/experimental/stale_while_revalidate/Makefile
+    plugins/experimental/ts_lua/Makefile
+    plugins/experimental/url_sig/Makefile
+    plugins/experimental/xdebug/Makefile
+])])
+
+AS_IF([test "x$enable_cppapi" = xyes], [
+  AC_CONFIG_FILES([
+  lib/atscppapi/Makefile
+  lib/atscppapi/examples/Makefile
+  lib/atscppapi/examples/async_http_fetch/Makefile
+  lib/atscppapi/examples/async_timer/Makefile
+  lib/atscppapi/examples/clientredirect/Makefile
+  lib/atscppapi/examples/clientrequest/Makefile
+  lib/atscppapi/examples/customresponse/Makefile
+  lib/atscppapi/examples/boom/Makefile
+  lib/atscppapi/examples/globalhook/Makefile
+  lib/atscppapi/examples/gzip_transformation/Makefile
+  lib/atscppapi/examples/helloworld/Makefile
+  lib/atscppapi/examples/intercept/Makefile
+  lib/atscppapi/examples/internal_transaction_handling/Makefile
+  lib/atscppapi/examples/logger_example/Makefile
+  lib/atscppapi/examples/multiple_transaction_hooks/Makefile
+  lib/atscppapi/examples/null_transformation_plugin/Makefile
+  lib/atscppapi/examples/post_buffer/Makefile
+  lib/atscppapi/examples/remap_plugin/Makefile
+  lib/atscppapi/examples/serverresponse/Makefile
+  lib/atscppapi/examples/stat_example/Makefile
+  lib/atscppapi/examples/timeout_example/Makefile
+  lib/atscppapi/examples/transactionhook/Makefile
+  lib/atscppapi/src/Makefile
+])])
+
+
 # -----------------------------------------------------------------------------
 # 7. autoheader TEMPLATES
 
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cf45bd6..48da294 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -39,14 +39,17 @@
 # Note: The LUA_LDFLAGS is a bit of a hack, since LuaJIT on OmniOS needs
 #       the -m64 flag. See configure.ac.
 #
+if ENABLE_LUAJIT
 LUA_CFLAGS=$(CFLAGS) -DLUA_COMPAT_ALL -DLUA_USE_POSIX -DLUA_USE_DLOPEN
 
 all-local:
 	@echo "Making all in luajit"
 	test -d "$(top_srcdir)/$(subdir)/luajit/src" || (cd "$(top_srcdir)" && git submodule update --init)
 	test -d "$(top_builddir)/$(subdir)/luajit/src" || cp -rf "$(srcdir)/luajit" "$(top_builddir)/$(subdir)/"
-	cd luajit && $(MAKE) $(AM_MAKEFLAGS) PREFIX="$(prefix)" CC="$(CC)" CFLAGS="$(LUA_CFLAGS)" LDFLAGS="@LUA_LDFLAGS@"
+	cd luajit && $(MAKE) $(AM_MAKEFLAGS) BUILDMODE="static" PREFIX="$(prefix)" CC="$(CC)" \
+	                     CFLAGS="$(LUA_CFLAGS)" LDFLAGS="@LUA_LDFLAGS@"
 
 clean-local:
 	test "$(top_srcdir)" != "$(top_builddir)" || (cd "$(top_builddir)/$(subdir)/luajit" && make clean)
 	test "$(top_srcdir)" = "$(top_builddir)" || rm -rf "$(top_builddir)/$(subdir)/luajit"
+endif
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index a810f8a..07da928 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -26,3 +26,9 @@
   stats_over_http \
   tcpinfo \
   experimental
+
+if BUILD_EXPERIMENTAL_PLUGINS
+
+SUBDIRS += experimental
+
+endif
diff --git a/plugins/experimental/Makefile.am b/plugins/experimental/Makefile.am
index 05ca267..249c435 100644
--- a/plugins/experimental/Makefile.am
+++ b/plugins/experimental/Makefile.am
@@ -14,8 +14,6 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-if BUILD_EXPERIMENTAL_PLUGINS
-
 SUBDIRS = \
  authproxy \
  background_fetch \
@@ -34,8 +32,9 @@
  remap_stats \
  s3_auth \
  stale_while_revalidate \
- ts_lua \
  url_sig \
  xdebug
 
+if ENABLE_LUAJIT
+  SUBDIRS += ts_lua
 endif
diff --git a/proxy/Makefile.am b/proxy/Makefile.am
index e40c8e9..f714fbf 100644
--- a/proxy/Makefile.am
+++ b/proxy/Makefile.am
@@ -217,7 +217,6 @@
   $(top_builddir)/lib/records/librecprocess.a \
   $(top_builddir)/iocore/eventsystem/libinkevent.a \
   $(which_libts) \
-  $(LUAJIT:%=$(top_builddir)/lib/luajit/src/%) \
   @HWLOC_LIBS@ \
   @LIBPCRE@ \
   @OPENSSL_LIBS@ \
@@ -232,6 +231,9 @@
   @SPDYLAY_LIBS@ \
   -lm
 
+if ENABLE_LUAJIT
+  traffic_server_LDADD += $(LUAJIT:%=$(top_builddir)/lib/luajit/src/%)
+endif
 
 # On Darwin LuaJIT requires magic link options, otherwise it will crash in luaL_openlibs() at startup. See
 # http://luajit.org/install.html.