From 32ef993e056ae2039fb023775381007dc3f598d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?agentzh=20=28=E7=AB=A0=E4=BA=A6=E6=98=A5=29?= Date: Wed, 10 Aug 2011 10:44:17 +0800 Subject: [PATCH] more progress on lua-cjson bundling. it now works on Mac OS X, FreeBSD, and Linux, at least. --- .../lua_cjson-1.0.2-array_detection_fix.patch | 13 +++++ t/sanity.t | 58 ++++++++++++++++++- util/configure | 34 +++++++---- util/mirror-tarballs | 3 + 4 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 patches/lua_cjson-1.0.2-array_detection_fix.patch diff --git a/patches/lua_cjson-1.0.2-array_detection_fix.patch b/patches/lua_cjson-1.0.2-array_detection_fix.patch new file mode 100644 index 0000000..dcbfb55 --- /dev/null +++ b/patches/lua_cjson-1.0.2-array_detection_fix.patch @@ -0,0 +1,13 @@ +diff --git a/lua_cjson.c b/lua_cjson.c +index 4b1915a..b46e915 100644 +--- a/lua_cjson.c ++++ b/lua_cjson.c +@@ -501,7 +501,7 @@ static int lua_array_length(lua_State *l, json_config_t *cfg) + /* table, startkey */ + while (lua_next(l, -2) != 0) { + /* table, key, value */ +- if (lua_isnumber(l, -2) && ++ if (lua_type(l, -2) == LUA_TNUMBER && + (k = lua_tonumber(l, -2))) { + /* Integer >= 1 ? */ + if (floor(k) == k && k >= 1) { diff --git a/t/sanity.t b/t/sanity.t index d3cbb90..1dd5ab1 100644 --- a/t/sanity.t +++ b/t/sanity.t @@ -219,12 +219,12 @@ Type the following commands to build and install: all: cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) linux - cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib + cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib CC=gcc cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) install: cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) install INSTALL_TOP=$(DESTDIR)/usr/local/openresty/lua - cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib + cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib CC=gcc cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) install DESTDIR=$(DESTDIR) clean: @@ -1483,3 +1483,57 @@ install: clean: rm -rf build + + +=== TEST 30: default (on Mac OS X) +--- ONLY +--- cmd: ./configure --dry-run --platform=darwin +--- out +platform: macosx (darwin) +cp -rp bundle/ build/ +cd build +cd lua-5.1.4 +gmake macosx +gmake install INSTALL_TOP=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua +export LUA_LIB='$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/lib' +export LUA_INC='$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include' +cd .. +cd nginx-1.0.5 +./configure --prefix=/usr/local/openresty/nginx \ + --add-module=../ngx_devel_kit-0.2.17 \ + --add-module=../echo-nginx-module-0.37rc1 \ + --add-module=../xss-nginx-module-0.03rc3 \ + --add-module=../set-misc-nginx-module-0.22rc2 \ + --add-module=../form-input-nginx-module-0.07rc5 \ + --add-module=../encrypted-session-nginx-module-0.01 \ + --add-module=../ngx_lua-0.2.1rc4 \ + --add-module=../headers-more-nginx-module-0.15 \ + --add-module=../srcache-nginx-module-0.12 \ + --add-module=../array-var-nginx-module-0.03rc1 \ + --add-module=../memc-nginx-module-0.12 \ + --add-module=../redis2-nginx-module-0.07 \ + --add-module=../upstream-keepalive-nginx-module-0.3 \ + --add-module=../auth-request-nginx-module-0.2 \ + --add-module=../rds-json-nginx-module-0.12rc1 \ + --with-http_ssl_module +cd ../.. +Type the following commands to build and install: + gmake + gmake install +--- makefile +.PHONY: all install clean + +all: + cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) macosx + cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib LDFLAGS='-bundle -undefined dynamic_lookup' CC=gcc + cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) + +install: + cd $OPENRESTY_BUILD_DIR/lua-5.1.4 && $(MAKE) install INSTALL_TOP=$(DESTDIR)/usr/local/openresty/lua + cd $OPENRESTY_BUILD_DIR/lua-cjson-1.0.2 && $(MAKE) install DESTDIR=$(DESTDIR) LUA_INCLUDE_DIR=$OPENRESTY_BUILD_DIR/lua-root/usr/local/openresty/lua/include LUA_LIB_DIR=/usr/local/openresty/lualib LDFLAGS='-bundle -undefined dynamic_lookup' CC=gcc + cd $OPENRESTY_BUILD_DIR/nginx-1.0.5 && $(MAKE) install DESTDIR=$(DESTDIR) + +clean: + rm -rf build + + diff --git a/util/configure b/util/configure index 9f5c1a9..4f72146 100755 --- a/util/configure +++ b/util/configure @@ -528,32 +528,44 @@ _END_ print $in <<"_EOC_"; -CFLAGS=\$"\$CFLAGS -DLUA_DEFAULT_PATH='\\"$lualib_prefix/?.lua\\"'" -CFLAGS=\$"\$CFLAGS -DLUA_DEFAULT_CPATH='\\"$lualib_prefix/?.so\\"'" +ngx_lua_dquote='"' +CFLAGS="\$CFLAGS -DLUA_DEFAULT_PATH='\$ngx_lua_dquote$lualib_prefix/?.lua\$ngx_lua_dquote'" +CFLAGS="\$CFLAGS -DLUA_DEFAULT_CPATH='\$ngx_lua_dquote$lualib_prefix/?.so\$ngx_lua_dquote'" _EOC_ close $in; unless ($opts->{no_lua_cjson}) { my $dir = auto_complete 'lua-cjson'; - - if (!defined $dir) { die "No lua-cjson found"; } - my $install; - if ($on_solaris) { - $install = "$root_dir/build/install"; - } else { - $install = "install"; - } + my $lua_inc; + if ($opts->{luajit}) { + $lua_inc = $ENV{LUAJIT_INC}; - my $lua_inc = $ENV{LUA_INC}; + } else { + $lua_inc = $ENV{LUA_INC}; + } my $extra_opts = " DESTDIR=\$(DESTDIR) LUA_INCLUDE_DIR=$lua_inc " . "LUA_LIB_DIR=$lualib_prefix"; + if ($on_solaris) { + $extra_opts .= " INSTALL=$root_dir/build/install"; + } + + if ($platform eq 'macosx') { + $extra_opts .= " LDFLAGS='-bundle -undefined dynamic_lookup'"; + } + + if (defined $cc) { + $extra_opts .= " CC=$cc"; + } else { + $extra_opts .= " CC=gcc"; + } + push @make_cmds, "cd $root_dir/build/$dir && ". "\$(MAKE)$extra_opts"; diff --git a/util/mirror-tarballs b/util/mirror-tarballs index 4e9433f..c8a7779 100755 --- a/util/mirror-tarballs +++ b/util/mirror-tarballs @@ -206,6 +206,9 @@ cd .. ver=1.0.2 $root/util/get-tarball "http://www.kyne.com.au/~mark/software/lua-cjson-$ver.tar.gz" -O "lua-cjson-$ver.tar.gz" || exit 1 tar -xzf lua-cjson-$ver.tar.gz || exit 1 +cd lua-cjson-$ver || exit 1 +patch -p1 < $root/patches/lua_cjson-$ver-array_detection_fix.patch || exit 1 +cd .. #################################