@@ -3,6 +3,7 @@ ngx_addon_name="ngx_js_module"
33NJS_OPENSSL=${NJS_OPENSSL:-YES}
44NJS_LIBXSLT=${NJS_LIBXSLT:-YES}
55NJS_ZLIB=${NJS_ZLIB:-YES}
6+ NJS_QUICKJS=${NJS_QUICKJS:-YES}
67
78NJS_DEPS="$ngx_addon_dir/ngx_js.h \
89    $ngx_addon_dir/ngx_js_fetch.h \
@@ -12,9 +13,78 @@ NJS_SRCS="$ngx_addon_dir/ngx_js.c \
1213    $ngx_addon_dir/ngx_js_regex.c \
1314    $ngx_addon_dir/ngx_js_shared_dict.c"
1415
16+ QJS_DEPS=""
17+ QJS_SRCS=""
18+ 
1519NJS_OPENSSL_LIB=
1620NJS_XSLT_LIB=
1721NJS_ZLIB_LIB=
22+ NJS_QUICKJS_LIB=
23+ NJS_QUICKJS_INC=
24+ NJS_HAVE_QUICKJS=
25+ 
26+ if [ $NJS_QUICKJS != NO ]; then
27+ 
28+     ngx_feature="QuickJS library -lquickjs.lto"
29+     ngx_feature_name=NJS_HAVE_QUICKJS
30+     ngx_feature_run=yes
31+     ngx_feature_incs="#if defined(__GNUC__) && (__GNUC__ >= 8)
32+                       #pragma GCC diagnostic push
33+                       #pragma GCC diagnostic ignored \"-Wcast-function-type\"
34+                       #endif
35+ 
36+                       #include <quickjs.h>"
37+     ngx_feature_path=""
38+     ngx_feature_libs="-lquickjs.lto -lm -ldl -lpthread"
39+     ngx_feature_test="JSRuntime *rt;
40+ 
41+                       rt = JS_NewRuntime();
42+                       (void) JS_GetClassID;
43+                       JS_FreeRuntime(rt);
44+                       return 0;"
45+     . auto/feature
46+ 
47+     if [ $ngx_found = no ]; then
48+         ngx_feature="QuickJS library -lquickjs"
49+         ngx_feature_libs="-lquickjs -lm -ldl -lpthread"
50+ 
51+         . auto/feature
52+     fi
53+ 
54+     if [ $ngx_found = no ]; then
55+         ngx_feature="QuickJS library -I/usr/include/quickjs/ -L/usr/lib/quickjs/ -lquickjs.lto"
56+         ngx_feature_path="/usr/include/quickjs/"
57+         ngx_feature_libs="-L/usr/lib/quickjs/ -lquickjs.lto -lm -ldl -lpthread"
58+ 
59+         . auto/feature
60+     fi
61+ 
62+     if [ $ngx_found = no ]; then
63+         ngx_feature="QuickJS library -I/usr/include/quickjs/ -L/usr/lib/quickjs/ -lquickjs"
64+         ngx_feature_libs="-L/usr/lib/quickjs/ -lquickjs -lm -ldl -lpthread"
65+ 
66+         . auto/feature
67+     fi
68+ 
69+     if [ $ngx_found = yes ]; then
70+ 
71+         ngx_feature="QuickJS JS_NewTypedArray()"
72+         ngx_feature_test="(void) JS_NewTypedArray;
73+                           return 0;"
74+ 
75+         . auto/feature
76+ 
77+         if [ $ngx_found = yes ]; then
78+             have=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY . auto/have
79+         fi
80+ 
81+         NJS_HAVE_QUICKJS=YES
82+         NJS_QUICKJS_LIB="$ngx_feature_libs"
83+         NJS_QUICKJS_INC="$ngx_feature_path"
84+ 
85+         echo " enabled QuickJS engine"
86+     fi
87+ fi
1888
1989if [ $NJS_OPENSSL != NO ]; then
2090    NJS_OPENSSL_LIB=OPENSSL
@@ -37,17 +107,30 @@ if [ $NJS_ZLIB != NO ]; then
37107    have=NJS_HAVE_ZLIB . auto/have
38108    NJS_SRCS="$NJS_SRCS $ngx_addon_dir/../external/njs_zlib_module.c"
39109
110+     if [ "$NJS_HAVE_QUICKJS" = "YES" ];  then
111+         NJS_SRCS="$NJS_SRCS $ngx_addon_dir/../external/qjs_zlib_module.c"
112+     fi
113+ 
40114    echo " enabled zlib module"
41115fi
42116
117+ 
118+ NJS_ENGINE_DEP="$ngx_addon_dir/../build/libnjs.a"
119+ NJS_ENGINE_LIB="$ngx_addon_dir/../build/libnjs.a"
120+ if [ "$NJS_HAVE_QUICKJS" = "YES" ];  then
121+     NJS_ENGINE_DEP="$ngx_addon_dir/../build/libqjs.a"
122+     NJS_ENGINE_LIB="$ngx_addon_dir/../build/libnjs.a $ngx_addon_dir/../build/libqjs.a"
123+ fi
124+ 
43125if [ $HTTP != NO ]; then
44126    ngx_module_type=HTTP_AUX_FILTER
45127    ngx_module_name=ngx_http_js_module
46-     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build"
47-     ngx_module_deps="$ngx_addon_dir/../build/libnjs.a $NJS_DEPS"
48-     ngx_module_srcs="$ngx_addon_dir/ngx_http_js_module.c $NJS_SRCS"
128+     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build \
129+                      $NJS_QUICKJS_INC"
130+     ngx_module_deps="$NJS_ENGINE_DEP $NJS_DEPS $QJS_DEPS"
131+     ngx_module_srcs="$ngx_addon_dir/ngx_http_js_module.c $NJS_SRCS $QJS_SRCS"
49132    ngx_module_libs="PCRE $NJS_OPENSSL_LIB $NJS_XSLT_LIB $NJS_ZLIB_LIB \
50-                      $ngx_addon_dir/../build/libnjs.a  -lm"
133+                      $NJS_QUICKJS_LIB $NJS_ENGINE_LIB  -lm"
51134
52135    . auto/module
53136
59142if [ $STREAM != NO ]; then
60143    ngx_module_type=STREAM
61144    ngx_module_name=ngx_stream_js_module
62-     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build"
63-     ngx_module_deps="$ngx_addon_dir/../build/libnjs.a $NJS_DEPS"
64-     ngx_module_srcs="$ngx_addon_dir/ngx_stream_js_module.c $NJS_SRCS"
145+     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build \
146+                      $NJS_QUICKJS_INC"
147+     ngx_module_deps="$NJS_ENGINE_DEP $NJS_DEPS $QJS_DEPS"
148+     ngx_module_srcs="$ngx_addon_dir/ngx_stream_js_module.c $NJS_SRCS $QJS_SRCS"
65149    ngx_module_libs="PCRE $NJS_OPENSSL_LIB $NJS_XSLT_LIB $NJS_ZLIB_LIB \
66-                      $ngx_addon_dir/../build/libnjs.a  -lm"
150+                      $NJS_QUICKJS_LIB $NJS_ENGINE_LIB  -lm"
67151
68152    . auto/module
69153fi
0 commit comments