This is an automated email from the ASF dual-hosted git repository. rrm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit ba93177dc5f8cc4a943b96b704170b5eba43ce91 Author: Randall Meyer <[email protected]> AuthorDate: Tue Jul 10 16:27:34 2018 -0700 Enhances detection of luajit if --with-luajit is specified, it will be used, otherwise use pkg-config or look in /usr and /usr/local --- build/luajit.m4 | 176 +++++++++++++++++++++++++++++++++++++ configure.ac | 44 +--------- doc/admin-guide/plugins/lua.en.rst | 6 +- plugins/lua/Makefile.inc | 2 +- src/traffic_server/Makefile.inc | 4 + 5 files changed, 187 insertions(+), 45 deletions(-) diff --git a/build/luajit.m4 b/build/luajit.m4 new file mode 100644 index 0000000..6ca0251 --- /dev/null +++ b/build/luajit.m4 @@ -0,0 +1,176 @@ +dnl -------------------------------------------------------- -*- autoconf -*- +dnl Licensed to the Apache Software Foundation (ASF) under one or more +dnl contributor license agreements. See the NOTICE file distributed with +dnl this work for additional information regarding copyright ownership. +dnl The ASF licenses this file to You under the Apache License, Version 2.0 +dnl (the "License"); you may not use this file except in compliance with +dnl the License. You may obtain a copy of the License at +dnl +dnl http://www.apache.org/licenses/LICENSE-2.0 +dnl +dnl Unless required by applicable law or agreed to in writing, software +dnl distributed under the License is distributed on an "AS IS" BASIS, +dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +dnl See the License for the specific language governing permissions and +dnl limitations under the License. + +dnl +dnl luajit.m4: Trafficserver's luajit autoconf macros +dnl + +dnl +dnl TS_CHECK_LUAJIT: look for luajit libraries and headers +dnl +AC_DEFUN([TS_CHECK_LUAJIT], [ +has_luajit=0 +AC_ARG_WITH(luajit, [AC_HELP_STRING([--with-luajit=DIR], [use a specific luajit library])], +[ + if test "x$withval" != "xyes" && test "x$withval" != "x"; then + luajit_base_dir="$withval" + if test "$withval" != "no"; then + has_luajit=1 + + case "$withval" in + *":"*) + luajit_include="`echo $withval | sed -e 's/:.*$//'`" + luajit_ldflags="`echo $withval | sed -e 's/^.*://'`" + AC_MSG_CHECKING(checking for luajit includes in $luajit_include libs in $luajit_ldflags) + ;; + *) + # looking for versioned subdir + for version in 2.0 2.1 ; do + dir="$withval/include/luajit-$version" + AC_MSG_CHECKING(checking for luajit in $dir) + if test -d $dir; then + AC_MSG_RESULT([ok]) + luajit_include=$dir + break + else + AC_MSG_RESULT([not found]) + fi + done + + if test "x$luajit_include" = "x"; then + AC_MSG_ERROR([*** could not find luajit include dir ***]) + fi + + luajit_ldflags="$withval/lib" + ;; + esac + + fi + fi + + if test -d $luajit_include && test -d $luajit_ldflags && test -f $luajit_include/luajit.h; then + AC_MSG_RESULT([ok]) + else + AC_MSG_RESULT([not found]) + fi + +if test "$has_luajit" != "0"; then + saved_ldflags=$LDFLAGS + saved_cppflags=$CPPFLAGS + luajit_have_headers=0 + luajit_have_libs=0 + + TS_ADDTO(CPPFLAGS, [-I${luajit_include}]) + if test "$luajit_base_dir" != "/usr"; then + TS_ADDTO(LDFLAGS, [-L${luajit_ldflags}]) + TS_ADDTO_RPATH(${luajit_ldflags}) + fi + + AC_CHECK_LIB([luajit-5.1], luaopen_jit, [luajit_have_libs=1]) + if test "$luajit_have_libs" == "1"; then + AC_CHECK_HEADERS(luajit.h, [luajit_have_headers=1]) + fi + + if test "$luajit_have_headers" == "1"; then + AC_SUBST([LUAJIT_LDFLAGS], ["-L${luajit_ldflags} -lluajit-5.1"]) + AC_SUBST([LUAJIT_CPPFLAGS], [-I${luajit_include}]) + enable_luajit=yes + else + has_luajit=0 + AC_MSG_ERROR([*** luajit requested but either libluajit-5.1 or luajit.h cannot be found ***]) + fi + + CPPFLAGS=$saved_cppflags + LDFLAGS=$saved_ldflags +fi +], +[ +# use pkg-config to search for it +# + +PKG_CHECK_MODULES([LUAJIT], [luajit >= 2.0.4], [ + AC_SUBST([LUAJIT_LDFLAGS], [$LUAJIT_LIBS]) + AC_SUBST([LUAJIT_CPPFLAGS], [$LUAJIT_CFLAGS]) + enable_luajit=yes +], +[ +# look in /usr and /usr/local for what we need +# + +AC_MSG_CHECKING([for luajit location]) + # looking for versioned subdir + for version in 2.0 2.1; do + for lua_prefix in /usr/local /usr; do + dir="$lua_prefix/include/luajit-$version" + + if test -d $dir; then + luajit_base_dir=$lua_prefix + luajit_include=$dir + luajit_ldflags=$lua_prefix/lib + break + fi + done + done + + if test "x$luajit_base_dir" = "x"; then + enable_luajit=no + AC_MSG_RESULT([not found]) + else + enable_luajit=yes + AC_MSG_RESULT([$dir]) + fi + +if test "$enable_luajit" != "no"; then + saved_ldflags=$LDFLAGS + saved_cppflags=$CPPFLAGS + luajit_have_headers=0 + luajit_have_libs=0 + + TS_ADDTO(CPPFLAGS, [-I${luajit_include}]) + if test "$luajit_base_dir" != "/usr"; then + TS_ADDTO(LDFLAGS, [-L${luajit_ldflags}]) + TS_ADDTO_RPATH(${luajit_ldflags}) + fi + + AC_CHECK_LIB([luajit-5.1], luaopen_jit, [luajit_have_libs=1]) + if test "$luajit_have_libs" == "1"; then + AC_CHECK_HEADERS(luajit.h, [luajit_have_headers=1]) + fi + + if test "$luajit_have_headers" == "1"; then + AC_SUBST([LUAJIT_LDFLAGS], ["-L${luajit_ldflags} -lluajit-5.1"]) + AC_SUBST([LUAJIT_CPPFLAGS], [-I${luajit_include}]) + enable_luajit=yes + else + has_luajit=0 + fi + + CPPFLAGS=$saved_cppflags + LDFLAGS=$saved_ldflags +fi + +]) +]) + +TS_ARG_ENABLE_VAR([has],[luajit]) +AM_CONDITIONAL([HAS_LUAJIT], [test 0 -ne $has_luajit]) + +# On Darwin, LuaJIT requires magic link options for a program loading or running with LuaJIT, +# otherwise it will crash in luaL_openlibs() at startup. See http://luajit.org/install.html for more details +AC_SUBST([LUAJIT_DARWIN_LDFLAGS], ["-Wl,-pagezero_size,10000 -Wl,-image_base,100000000"]) +AM_CONDITIONAL([IS_DARWIN], [test x$(uname) = xDarwin]) + +]) diff --git a/configure.ac b/configure.ac index a53428d..100d5ed 100644 --- a/configure.ac +++ b/configure.ac @@ -358,18 +358,6 @@ AC_ARG_WITH([profiler], ) AC_MSG_RESULT([$with_profiler]) -# System luajit -AC_MSG_CHECKING([whether to enable luajit]) -AC_ARG_ENABLE([luajit], - [AS_HELP_STRING([--enable-luajit],[enable support for system-installed luajit])], - [enable_luajit=yes], - [enable_luajit=no] -) -AC_MSG_RESULT([$enable_luajit]) -TS_ARG_ENABLE_VAR([has],[luajit]) -AM_CONDITIONAL([HAS_LUAJIT], [test 0 -ne $has_luajit]) - - # Disable all static library builds AC_DISABLE_STATIC @@ -1234,35 +1222,6 @@ TS_CHECK_ZLIB TS_CHECK_LZMA # -# System LuaJIT -# - -if test "x$enable_luajit" == "xyes"; then - saveLIBS=$LIBS - LIBS="" - AC_CHECK_HEADER(lua.h, [], - [LUAJIT_PKGCONFIG=1]) - AC_CHECK_LIB(luajit-5.1, luaL_newstate, [], - [LUAJIT_PKGCONFIG=1]) - if test "x$LUAJIT_PKGCONFIG" != "x"; then - PKG_CHECK_MODULES([LUAJIT], [luajit < 2.1.0, luajit >= 2.0.0], [ - AC_SUBST([LIBLUAJIT], [$LUAJIT_LIBS]) - TS_ADDTO(AM_CPPFLAGS, [$LUAJIT_CFLAGS]) - # On Darwin LuaJIT requires magic link options, otherwise it will crash in luaL_openlibs() at startup. See - # http://luajit.org/install.html. - case $host_os_def in - darwin) - LUAJIT_LDFLAGS="-Wl,-pagezero_size,10000 -Wl,-image_base,100000000" - ;; - esac - ], [AC_MSG_ERROR([*** luajit requested but either libluajit-5.1 or lua.h cannot be found ***])]) - else - AC_SUBST([LIBLUAJIT], [$LIBS]) - fi - LIBS=$saveLIBS -fi - -# # Tcl macros provided by build/tcl.m4 # # this will error out if tclConfig.sh is not found @@ -1318,6 +1277,9 @@ fi # Check for optional brotli library TS_CHECK_BROTLI +# Check for optional luajit library +TS_CHECK_LUAJIT + # # Enable experimental/uri_singing plugin # This is here, instead of above, because it needs to know if PCRE is available. diff --git a/doc/admin-guide/plugins/lua.en.rst b/doc/admin-guide/plugins/lua.en.rst index 81576da..8818b65 100644 --- a/doc/admin-guide/plugins/lua.en.rst +++ b/doc/admin-guide/plugins/lua.en.rst @@ -68,13 +68,13 @@ Synopsis Installation ============ -This plugin is only built if LuaJIT (>2.0.4) is installed and the configure option +This plugin is only built if LuaJIT (>2.0.4) is installed. The configure option :: - --enable-luajit + --with-luajit=<path to luajit prefix> -is given at build time. +can be used to specify a LuaJIT install. Otherwise, configure will use pkg-config to find a viable installation. Configuration ============= diff --git a/plugins/lua/Makefile.inc b/plugins/lua/Makefile.inc index 954d284..adcdde5 100644 --- a/plugins/lua/Makefile.inc +++ b/plugins/lua/Makefile.inc @@ -15,7 +15,7 @@ # limitations under the License. lua_tslua_la_CPPFLAGS = $(AM_CPPFLAGS) $(LUAJIT_CPPFLAGS) -lua_tslua_la_LDFLAGS = $(AM_LDFLAGS) $(LIBLUAJIT) +lua_tslua_la_LDFLAGS = $(AM_LDFLAGS) $(LUAJIT_LDFLAGS) pkglib_LTLIBRARIES += lua/tslua.la diff --git a/src/traffic_server/Makefile.inc b/src/traffic_server/Makefile.inc index 4ae3687..804248f 100644 --- a/src/traffic_server/Makefile.inc +++ b/src/traffic_server/Makefile.inc @@ -95,3 +95,7 @@ traffic_server_traffic_server_LDADD += \ @OPENSSL_LIBS@ \ @YAMLCPP_LIBS@ \ -lm + +if IS_DARWIN +traffic_server_traffic_server_LDADD += $(LUAJIT_DARWIN_LDFLAGS) +endif
