1 ngx_feature="Lua library"
2 ngx_feature_libs="-llua -lm"
5 ngx_feature_incs="#include <lauxlib.h>"
7 ngx_feature_test="#if LUA_VERSION_NUM != 501
8 # error unsupported Lua language version
10 (void) luaL_newstate();"
14 if [ -n "$LUAJIT_INC" -o -n "$LUAJIT_LIB" ]; then
15 # explicitly set LuaJIT paths
17 if [ "$NGX_PLATFORM" = win32 ]; then
18 ngx_feature="LuaJIT library in $LUAJIT_LIB and $LUAJIT_INC (win32)"
19 ngx_feature_path="$LUAJIT_INC"
20 ngx_lua_opt_I="-I$LUAJIT_INC"
21 ngx_lua_opt_L="-L$LUAJIT_LIB"
23 # ensure that our -I$LUAJIT_INC and -L$LUAJIT_LIB is at the first.
24 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
25 CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
26 SAVED_NGX_TEST_LD_OPT="$NGX_TEST_LD_OPT"
27 NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
29 # LuaJIT's win32 build uses the library file name lua51.dll.
30 ngx_feature_libs="$ngx_lua_opt_L -llua51"
35 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
36 NGX_TEST_LD_OPT="$SAVED_NGX_TEST_LD_OPT"
39 # attempt to link with -ldl, static linking on Linux requires it.
40 ngx_feature="LuaJIT library in $LUAJIT_LIB and $LUAJIT_INC (specified by the LUAJIT_LIB and LUAJIT_INC env, with -ldl)"
41 ngx_feature_path="$LUAJIT_INC"
42 ngx_lua_opt_I="-I$LUAJIT_INC"
43 ngx_lua_opt_L="-L$LUAJIT_LIB"
45 # ensure that our -I$LUAJIT_INC and -L$LUAJIT_LIB is at the first.
46 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
47 CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
48 SAVED_NGX_TEST_LD_OPT="$NGX_TEST_LD_OPT"
49 NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
51 if [ $NGX_RPATH = YES ]; then
52 ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 -lm -ldl"
54 ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 -lm -ldl"
60 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
61 NGX_TEST_LD_OPT="$SAVED_NGX_TEST_LD_OPT"
63 if [ $ngx_found = no ]; then
65 ngx_feature="LuaJIT library in $LUAJIT_LIB and $LUAJIT_INC (specified by the LUAJIT_LIB and LUAJIT_INC env)"
66 ngx_feature_path="$LUAJIT_INC"
67 ngx_lua_opt_I="-I$LUAJIT_INC"
68 ngx_lua_opt_L="-L$LUAJIT_LIB"
70 # ensure that our -I$LUAJIT_INC and -L$LUAJIT_LIB is at the first.
71 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
72 CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
73 SAVED_NGX_TEST_LD_OPT="$NGX_TEST_LD_OPT"
74 NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
76 if [ $NGX_RPATH = YES ]; then
77 ngx_feature_libs="-R$LUAJIT_LIB $ngx_lua_opt_L -lluajit-5.1 -lm"
79 ngx_feature_libs="$ngx_lua_opt_L -lluajit-5.1 -lm"
85 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
86 NGX_TEST_LD_OPT="$SAVED_NGX_TEST_LD_OPT"
90 if [ $ngx_found = no ]; then
92 $0: error: ngx_http_lua_module requires the Lua or LuaJIT library and LUAJIT_LIB is defined as $LUAJIT_LIB and LUAJIT_INC (path for lua.h) $LUAJIT_INC, but we cannot find LuaJIT there.
97 case "$NGX_PLATFORM" in
99 case "$NGX_MACHINE" in
100 amd64 | x86_64 | i386)
101 echo "adding extra linking options needed by LuaJIT"
102 ngx_feature_libs="$ngx_feature_libs -pagezero_size 10000 -image_base 100000000"
114 if [ -n "$LUA_INC" -o -n "$LUA_LIB" ]; then
115 # explicitly set Lua paths
116 ngx_feature="Lua library in $LUA_LIB and $LUA_INC (specified by the LUA_LIB and LUA_INC env)"
117 ngx_feature_path="$LUA_INC"
118 ngx_lua_opt_I="-I$LUA_INC"
119 ngx_lua_opt_L="-L$LUA_LIB"
121 # ensure that our -I$LUA_INC and -L$LUA_LIB is at the first.
122 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
123 CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
124 SAVED_NGX_TEST_LD_OPT="$NGX_TEST_LD_OPT"
125 NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
127 if [ $NGX_RPATH = YES ]; then
128 ngx_feature_libs="-R$LUA_LIB $ngx_lua_opt_L -llua -lm -ldl"
130 ngx_feature_libs="$ngx_lua_opt_L -llua -lm -ldl"
136 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
137 NGX_TEST_LD_OPT="$SAVED_NGX_TEST_LD_OPT"
139 if [ $ngx_found = no ]; then
142 ngx_feature_path="$LUA_INC"
143 ngx_lua_opt_I="-I$LUA_INC"
144 ngx_lua_opt_L="-L$LUA_LIB"
146 # ensure that our -I$LUA_INC and -L$LUA_LIB is at the first.
147 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
148 CC_TEST_FLAGS="$ngx_lua_opt_I $CC_TEST_FLAGS"
149 SAVED_NGX_TEST_LD_OPT="$NGX_TEST_LD_OPT"
150 NGX_TEST_LD_OPT="$ngx_lua_opt_L $NGX_TEST_LD_OPT"
152 if [ $NGX_RPATH = YES ]; then
153 ngx_feature_libs="-R$LUA_LIB $ngx_lua_opt_L -llua -lm"
155 ngx_feature_libs="$ngx_lua_opt_L -llua -lm"
161 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
162 NGX_TEST_LD_OPT="$SAVED_NGX_TEST_LD_OPT"
165 if [ $ngx_found = no ]; then
167 $0: error: ngx_http_lua_module requires the Lua or LuaJIT library and LUA_LIB is defined as $LUA_LIB and LUA_INC (path for lua.h) is $LUA_INC, but we cannot find standard Lua there.
173 ngx_feature="Lua library"
174 ngx_feature_libs="-llua -lm"
177 if [ $ngx_found = no ]; then
179 ngx_feature="Lua library in /usr/local/"
180 ngx_feature_path="/usr/local/include/lua-5.1"
181 if [ $NGX_RPATH = YES ]; then
182 ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -llua -lm"
184 ngx_feature_libs="-L/usr/local/lib -llua5.1 -lm"
189 if [ $ngx_found = no ]; then
191 ngx_feature="Lua library in /usr/local/"
192 ngx_feature_path="/usr/local/include"
193 if [ $NGX_RPATH = YES ]; then
194 ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -llua -lm"
196 ngx_feature_libs="-L/usr/local/lib -llua -lm"
201 if [ $ngx_found = no ]; then
203 ngx_feature="Lua library in /usr/pkg/"
204 ngx_feature_path="/usr/pkg/include/"
205 if [ $NGX_RPATH = YES ]; then
206 ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lm -llua"
208 ngx_feature_libs="-L/usr/pkg/lib -lm -llua"
213 if [ $ngx_found = no ]; then
215 ngx_feature="Lua library in /opt/local/"
216 ngx_feature_path="/opt/local/include"
217 if [ $NGX_RPATH = YES ]; then
218 ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lm -llua"
220 ngx_feature_libs="-L/opt/local/lib -lm -llua"
225 if [ $ngx_found = no ]; then
227 ngx_feature="Lua library in /usr/local/*/lua51/"
228 ngx_feature_path="/usr/local/include/lua51"
229 if [ $NGX_RPATH = YES ]; then
230 ngx_feature_libs="-R/usr/local/lib/lua51 -L/usr/local/lib/lua51 -llua -lm"
232 ngx_feature_libs="-L/usr/local/lib/lua51 -llua -lm"
237 if [ $ngx_found = no ]; then
239 ngx_feature="Lua library in /usr/"
240 ngx_feature_path="/usr/include/lua5.1"
241 if [ $NGX_RPATH = YES ]; then
242 ngx_feature_libs="-R/usr/lib -L/usr/lib -lm -llua5.1"
244 ngx_feature_libs="-L/usr/lib -lm -llua5.1"
249 if [ $ngx_found = no ]; then
250 # FreeBSD with luajit-2.0 from ports collection
251 ngx_feature="LuaJIT library in /usr/local/"
252 ngx_feature_path="/usr/local/include/luajit-2.0"
253 if [ $NGX_RPATH = YES ]; then
254 ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lluajit-5.1 -lm"
256 ngx_feature_libs="-L/usr/local/lib -lluajit-5.1 -lm"
261 if [ $ngx_found = no ]; then
262 # Gentoo with LuaJIT-2.0, try with -ldl
263 ngx_feature="LuaJIT library in /usr/"
264 ngx_feature_path="/usr/include/luajit-2.0"
265 if [ $NGX_RPATH = YES ]; then
266 ngx_feature_libs="-R/usr/lib -L/usr/lib -lm -lluajit-5.1 -ldl"
268 ngx_feature_libs="-L/usr/lib -lm -lluajit-5.1 -ldl"
273 if [ $ngx_found = no ]; then
274 # Gentoo with LuaJIT 2.0
275 ngx_feature="LuaJIT library in /usr/"
276 ngx_feature_path="/usr/include/luajit-2.0"
277 if [ $NGX_RPATH = YES ]; then
278 ngx_feature_libs="-R/usr/lib -L/usr/lib -lm -lluajit-5.1"
280 ngx_feature_libs="-L/usr/lib -lm -lluajit-5.1"
290 if [ $ngx_found = yes ]; then
291 # this is a hack to persuade nginx's build system to favor
292 # the paths set by our user environments:
293 CFLAGS="$ngx_lua_opt_I $CFLAGS"
294 NGX_LD_OPT="$ngx_lua_opt_L $NGX_LD_OPT"
296 ngx_module_incs="$ngx_module_incs $ngx_feature_path"
297 ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
300 $0: error: ngx_http_lua_module requires the Lua library.
305 ngx_addon_name=ngx_http_lua_module
307 $ngx_addon_dir/src/ngx_http_lua_script.c \
308 $ngx_addon_dir/src/ngx_http_lua_log.c \
309 $ngx_addon_dir/src/ngx_http_lua_subrequest.c \
310 $ngx_addon_dir/src/ngx_http_lua_ndk.c \
311 $ngx_addon_dir/src/ngx_http_lua_control.c \
312 $ngx_addon_dir/src/ngx_http_lua_time.c \
313 $ngx_addon_dir/src/ngx_http_lua_misc.c \
314 $ngx_addon_dir/src/ngx_http_lua_variable.c \
315 $ngx_addon_dir/src/ngx_http_lua_string.c \
316 $ngx_addon_dir/src/ngx_http_lua_output.c \
317 $ngx_addon_dir/src/ngx_http_lua_headers.c \
318 $ngx_addon_dir/src/ngx_http_lua_req_body.c \
319 $ngx_addon_dir/src/ngx_http_lua_uri.c \
320 $ngx_addon_dir/src/ngx_http_lua_args.c \
321 $ngx_addon_dir/src/ngx_http_lua_ctx.c \
322 $ngx_addon_dir/src/ngx_http_lua_regex.c \
323 $ngx_addon_dir/src/ngx_http_lua_module.c \
324 $ngx_addon_dir/src/ngx_http_lua_headers_out.c \
325 $ngx_addon_dir/src/ngx_http_lua_headers_in.c \
326 $ngx_addon_dir/src/ngx_http_lua_directive.c \
327 $ngx_addon_dir/src/ngx_http_lua_consts.c \
328 $ngx_addon_dir/src/ngx_http_lua_exception.c \
329 $ngx_addon_dir/src/ngx_http_lua_util.c \
330 $ngx_addon_dir/src/ngx_http_lua_cache.c \
331 $ngx_addon_dir/src/ngx_http_lua_contentby.c \
332 $ngx_addon_dir/src/ngx_http_lua_rewriteby.c \
333 $ngx_addon_dir/src/ngx_http_lua_accessby.c \
334 $ngx_addon_dir/src/ngx_http_lua_setby.c \
335 $ngx_addon_dir/src/ngx_http_lua_capturefilter.c \
336 $ngx_addon_dir/src/ngx_http_lua_clfactory.c \
337 $ngx_addon_dir/src/ngx_http_lua_pcrefix.c \
338 $ngx_addon_dir/src/ngx_http_lua_headerfilterby.c \
339 $ngx_addon_dir/src/ngx_http_lua_shdict.c \
340 $ngx_addon_dir/src/ngx_http_lua_socket_tcp.c \
341 $ngx_addon_dir/src/ngx_http_lua_api.c \
342 $ngx_addon_dir/src/ngx_http_lua_logby.c \
343 $ngx_addon_dir/src/ngx_http_lua_sleep.c \
344 $ngx_addon_dir/src/ngx_http_lua_semaphore.c\
345 $ngx_addon_dir/src/ngx_http_lua_coroutine.c \
346 $ngx_addon_dir/src/ngx_http_lua_bodyfilterby.c \
347 $ngx_addon_dir/src/ngx_http_lua_initby.c \
348 $ngx_addon_dir/src/ngx_http_lua_initworkerby.c \
349 $ngx_addon_dir/src/ngx_http_lua_socket_udp.c \
350 $ngx_addon_dir/src/ngx_http_lua_req_method.c \
351 $ngx_addon_dir/src/ngx_http_lua_phase.c \
352 $ngx_addon_dir/src/ngx_http_lua_uthread.c \
353 $ngx_addon_dir/src/ngx_http_lua_timer.c \
354 $ngx_addon_dir/src/ngx_http_lua_config.c \
355 $ngx_addon_dir/src/ngx_http_lua_worker.c \
356 $ngx_addon_dir/src/ngx_http_lua_ssl_certby.c \
357 $ngx_addon_dir/src/ngx_http_lua_ssl_ocsp.c \
358 $ngx_addon_dir/src/ngx_http_lua_lex.c \
359 $ngx_addon_dir/src/ngx_http_lua_balancer.c \
360 $ngx_addon_dir/src/ngx_http_lua_ssl_session_storeby.c \
361 $ngx_addon_dir/src/ngx_http_lua_ssl_session_fetchby.c \
362 $ngx_addon_dir/src/ngx_http_lua_ssl.c \
366 $ngx_addon_dir/src/ddebug.h \
367 $ngx_addon_dir/src/ngx_http_lua_script.h \
368 $ngx_addon_dir/src/ngx_http_lua_log.h \
369 $ngx_addon_dir/src/ngx_http_lua_subrequest.h \
370 $ngx_addon_dir/src/ngx_http_lua_ndk.h \
371 $ngx_addon_dir/src/ngx_http_lua_control.h \
372 $ngx_addon_dir/src/ngx_http_lua_time.h \
373 $ngx_addon_dir/src/ngx_http_lua_string.h \
374 $ngx_addon_dir/src/ngx_http_lua_misc.h \
375 $ngx_addon_dir/src/ngx_http_lua_variable.h \
376 $ngx_addon_dir/src/ngx_http_lua_output.h \
377 $ngx_addon_dir/src/ngx_http_lua_headers.h \
378 $ngx_addon_dir/src/ngx_http_lua_uri.h \
379 $ngx_addon_dir/src/ngx_http_lua_req_body.h \
380 $ngx_addon_dir/src/ngx_http_lua_args.h \
381 $ngx_addon_dir/src/ngx_http_lua_ctx.h \
382 $ngx_addon_dir/src/ngx_http_lua_regex.h \
383 $ngx_addon_dir/src/ngx_http_lua_common.h \
384 $ngx_addon_dir/src/ngx_http_lua_directive.h \
385 $ngx_addon_dir/src/ngx_http_lua_headers_out.h \
386 $ngx_addon_dir/src/ngx_http_lua_headers_in.h \
387 $ngx_addon_dir/src/ngx_http_lua_consts.h \
388 $ngx_addon_dir/src/ngx_http_lua_exception.h \
389 $ngx_addon_dir/src/ngx_http_lua_util.h \
390 $ngx_addon_dir/src/ngx_http_lua_cache.h \
391 $ngx_addon_dir/src/ngx_http_lua_contentby.h \
392 $ngx_addon_dir/src/ngx_http_lua_rewriteby.h \
393 $ngx_addon_dir/src/ngx_http_lua_accessby.h \
394 $ngx_addon_dir/src/ngx_http_lua_setby.h \
395 $ngx_addon_dir/src/ngx_http_lua_capturefilter.h \
396 $ngx_addon_dir/src/ngx_http_lua_clfactory.h \
397 $ngx_addon_dir/src/ngx_http_lua_pcrefix.h \
398 $ngx_addon_dir/src/ngx_http_lua_headerfilterby.h \
399 $ngx_addon_dir/src/ngx_http_lua_shdict.h \
400 $ngx_addon_dir/src/ngx_http_lua_socket_tcp.h \
401 $ngx_addon_dir/src/api/ngx_http_lua_api.h \
402 $ngx_addon_dir/src/ngx_http_lua_logby.h \
403 $ngx_addon_dir/src/ngx_http_lua_sleep.h \
404 $ngx_addon_dir/src/ngx_http_lua_semaphore.h\
405 $ngx_addon_dir/src/ngx_http_lua_coroutine.h \
406 $ngx_addon_dir/src/ngx_http_lua_bodyfilterby.h \
407 $ngx_addon_dir/src/ngx_http_lua_initby.h \
408 $ngx_addon_dir/src/ngx_http_lua_initworkerby.h \
409 $ngx_addon_dir/src/ngx_http_lua_socket_udp.h \
410 $ngx_addon_dir/src/ngx_http_lua_req_method.h \
411 $ngx_addon_dir/src/ngx_http_lua_phase.h \
412 $ngx_addon_dir/src/ngx_http_lua_probe.h \
413 $ngx_addon_dir/src/ngx_http_lua_uthread.h \
414 $ngx_addon_dir/src/ngx_http_lua_timer.h \
415 $ngx_addon_dir/src/ngx_http_lua_config.h \
416 $ngx_addon_dir/src/ngx_http_lua_worker.h \
417 $ngx_addon_dir/src/ngx_http_lua_ssl_certby.h \
418 $ngx_addon_dir/src/ngx_http_lua_lex.h \
419 $ngx_addon_dir/src/ngx_http_lua_balancer.h \
420 $ngx_addon_dir/src/ngx_http_lua_ssl_session_storeby.h \
421 $ngx_addon_dir/src/ngx_http_lua_ssl_session_fetchby.h \
422 $ngx_addon_dir/src/ngx_http_lua_ssl.h \
425 CFLAGS="$CFLAGS -DNDK_SET_VAR"
427 ngx_feature="export symbols by default (-E)"
428 ngx_feature_libs="-Wl,-E"
431 ngx_feature_incs="#include <stdio.h>"
433 ngx_feature_test='printf("hello");'
437 if [ $ngx_found = yes ]; then
438 CORE_LIBS="-Wl,-E $CORE_LIBS"
442 ngx_feature="export symbols by default (--export-all-symbols)"
443 ngx_feature_libs="-Wl,--export-all-symbols"
446 ngx_feature_incs="#include <stdio.h>"
448 ngx_feature_test='printf("hello");'
452 if [ $ngx_found = yes ]; then
453 CORE_LIBS="-Wl,--export-all-symbols $CORE_LIBS"
456 NGX_DTRACE_PROVIDERS="$NGX_DTRACE_PROVIDERS $ngx_addon_dir/dtrace/ngx_lua_provider.d"
457 NGX_TAPSET_SRCS="$NGX_TAPSET_SRCS $ngx_addon_dir/tapset/ngx_lua.stp"
462 CORE_INCS="$CORE_INCS $ngx_addon_dir/src/api"
464 ngx_feature="SO_PASSCRED"
466 ngx_feature_name="NGX_HTTP_LUA_HAVE_SO_PASSCRED"
468 ngx_feature_incs="#include <sys/types.h>
469 #include <sys/socket.h>"
471 ngx_feature_test='setsockopt(1, SOL_SOCKET, SO_PASSCRED, NULL, 0);'
475 ngx_feature="mmap(sbrk(0))"
477 ngx_feature_name="NGX_HTTP_LUA_HAVE_MMAP_SBRK"
479 ngx_feature_incs="#include <unistd.h>
482 #include <sys/mman.h>
483 #define align_ptr(p, a) \
484 (u_char *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
487 #if defined(__x86_64__)
488 exit(mmap(align_ptr(sbrk(0), getpagesize()), 1, PROT_READ,
489 MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0) < (void *) 0x40000000LL
495 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
496 CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
500 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
502 ngx_feature="__attribute__(constructor)"
504 ngx_feature_name="NGX_HTTP_LUA_HAVE_CONSTRUCTOR"
506 ngx_feature_incs="#include <stdlib.h>
508 __attribute__((constructor))
509 static void foo(void)
514 ngx_feature_test="exit(a);"
515 SAVED_CC_TEST_FLAGS="$CC_TEST_FLAGS"
516 CC_TEST_FLAGS="-Werror -Wall $CC_TEST_FLAGS"
520 CC_TEST_FLAGS="$SAVED_CC_TEST_FLAGS"
522 if test -n "$ngx_module_link"; then
523 ngx_module_type=HTTP_AUX_FILTER
524 ngx_module_name=$ngx_addon_name
525 ngx_module_deps="$HTTP_LUA_DEPS"
526 ngx_module_srcs="$HTTP_LUA_SRCS"
530 HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
531 NGX_ADDON_SRCS="$NGX_ADDON_SRCS $HTTP_LUA_SRCS"
532 NGX_ADDON_DEPS="$NGX_ADDON_DEPS $HTTP_LUA_DEPS"
534 CORE_INCS="$CORE_INCS $ngx_module_incs"
535 CORE_LIBS="$CORE_LIBS $ngx_module_libs"
538 #CFLAGS=$"$CFLAGS -DLUA_DEFAULT_PATH='\"/usr/local/openresty/lualib/?.lua\"'"
539 #CFLAGS=$"$CFLAGS -DLUA_DEFAULT_CPATH='\"/usr/local/openresty/lualib/?.so\"'"