From aa56e3d752ed647bc1f7b877304da7fceb650e0c Mon Sep 17 00:00:00 2001 From: oetiker Date: Mon, 20 Oct 2008 06:06:16 +0000 Subject: [PATCH] - Lua module build and install process rewritten using automake+libtool - improved check for compat-5.1 availability -- Fidelis Assis git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1621 a5681a0c-68f1-0310-ab6d-d61299d08faa --- bindings/Makefile.am | 14 +- bindings/lua/README | 33 ++- bindings/lua/compat-5.1r5/compat-5.1.c | 97 ++++++++ bindings/lua/compat-5.1r5/compat-5.1.h | 13 ++ bindings/lua/compat-5.1r5/compat-5.1.lua | 267 +++++++++++++++++++++++ bindings/lua/rrdlua.c | 10 +- bindings/lua/test.lua | 98 --------- bindings/lua/test.lua.bottom | 90 ++++++++ configure.ac | 142 ++++++------ 9 files changed, 570 insertions(+), 194 deletions(-) create mode 100644 bindings/lua/compat-5.1r5/compat-5.1.c create mode 100644 bindings/lua/compat-5.1r5/compat-5.1.h create mode 100644 bindings/lua/compat-5.1r5/compat-5.1.lua delete mode 100644 bindings/lua/test.lua create mode 100644 bindings/lua/test.lua.bottom diff --git a/bindings/Makefile.am b/bindings/Makefile.am index f6c8d98..1fa0272 100644 --- a/bindings/Makefile.am +++ b/bindings/Makefile.am @@ -3,19 +3,21 @@ if BUILD_TCL SUB_tcl = tcl endif +if BUILD_LUA +SUB_lua = lua +endif -SUBDIRS = $(SUB_tcl) +SUBDIRS = $(SUB_tcl) $(SUB_lua) # the following files are not mentioned in any other Makefile EXTRA_DIST = perl-piped/MANIFEST perl-piped/README perl-piped/Makefile.PL perl-piped/RRDp.pm perl-piped/t/base.t \ perl-shared/ntmake.pl perl-shared/MANIFEST perl-shared/README perl-shared/Makefile.PL perl-shared/RRDs.pm perl-shared/RRDs.xs perl-shared/t/base.t \ ruby/CHANGES ruby/README ruby/extconf.rb ruby/main.c ruby/test.rb \ - python/ACKNOWLEDGEMENT python/AUTHORS python/COPYING python/README python/rrdtoolmodule.c python/setup.py \ - lua/README lua/test.lua lua/rrdlua.c lua/Makefile.lua + python/ACKNOWLEDGEMENT python/AUTHORS python/COPYING python/README python/rrdtoolmodule.c python/setup.py # add the following to the all target -all-local: @COMP_PERL@ @COMP_RUBY@ @COMP_PYTHON@ @COMP_LUA@ +all-local: @COMP_PERL@ @COMP_RUBY@ @COMP_PYTHON@ install-data-local: test -f perl-piped/Makefile && cd perl-piped && $(MAKE) install || true @@ -34,9 +36,6 @@ ruby: python: cd python && env BUILDLIBDIR=../../src/.libs $(PYTHON) setup.py build_ext --rpath=$(libdir) && env LIBDIR=../../src/.libs $(PYTHON) setup.py build -lua: - cd lua && $(LUA) Makefile.lua > Makefile && $(MAKE) - # rules for building the perl module perl_piped: perl-piped/Makefile cd perl-piped && $(MAKE) @@ -57,6 +56,5 @@ clean-local: test -f perl-shared/Makefile && cd perl-shared && $(MAKE) clean || true test -f perl-shared/Makefile && rm -f perl-shared/Makefile || true test -f ruby/Makefile && cd ruby && $(MAKE) clean && rm Makefile || true - test -f lua/Makefile && cd lua && $(MAKE) clean && rm Makefile || true test -d python/build && cd python && rm -rf build || true ##END## diff --git a/bindings/lua/README b/bindings/lua/README index 0eaaccc..a42339d 100644 --- a/bindings/lua/README +++ b/bindings/lua/README @@ -3,17 +3,17 @@ RRDLua is a Lua module for RRD functions. - Configuration From the top dir of RRDtool package, run "./configure", or - "./configure --enable-lua-site-install" if you prefer to install it - in Lua's search path. + "./configure --enable-lua-site-install" if you prefer to install in + Lua's search path. - You should have lua and lua-dev packages installed before executing - configure. + You should have lua 5.0, or superior, and respective lua-dev packages + installed before executing configure. - Compilation and installation Run 'make' and 'sudo make install'. If you don't enable lua-site-install, - the Lua module will be installed together with RRDtool, under the subdir - lib/lua/. + the Lua modules will be installed together with RRDtool, under the subdir + lib/lua/. - Testing @@ -26,11 +26,11 @@ RRDLua is a Lua module for RRD functions. Start your programs with: - --------------------------------------------------------------- - package.cpath = '/usr/local/rrdtool-1.3.2/lib/lua/5.1/?.so;' .. + ------..----------------------------------------------------------- + package.cpath = ' +#include +#include "lua.h" +#include "lauxlib.h" +#include "compat-5.1.h" + +static void getfield(lua_State *L, int idx, const char *name) { + const char *end = strchr(name, '.'); + lua_pushvalue(L, idx); + while (end) { + lua_pushlstring(L, name, end - name); + lua_gettable(L, -2); + lua_remove(L, -2); + if (lua_isnil(L, -1)) return; + name = end+1; + end = strchr(name, '.'); + } + lua_pushstring(L, name); + lua_gettable(L, -2); + lua_remove(L, -2); +} + +static void setfield(lua_State *L, int idx, const char *name) { + const char *end = strchr(name, '.'); + lua_pushvalue(L, idx); + while (end) { + lua_pushlstring(L, name, end - name); + lua_gettable(L, -2); + /* create table if not found */ + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_newtable(L); + lua_pushlstring(L, name, end - name); + lua_pushvalue(L, -2); + lua_settable(L, -4); + } + lua_remove(L, -2); + name = end+1; + end = strchr(name, '.'); + } + lua_pushstring(L, name); + lua_pushvalue(L, -3); + lua_settable(L, -3); + lua_pop(L, 2); +} + +LUALIB_API void luaL_module(lua_State *L, const char *libname, + const luaL_reg *l, int nup) { + if (libname) { + getfield(L, LUA_GLOBALSINDEX, libname); /* check whether lib already exists */ + if (lua_isnil(L, -1)) { + int env, ns; + lua_pop(L, 1); /* get rid of nil */ + lua_pushliteral(L, "require"); + lua_gettable(L, LUA_GLOBALSINDEX); /* look for require */ + lua_getfenv(L, -1); /* getfenv(require) */ + lua_remove(L, -2); /* remove function require */ + env = lua_gettop(L); + + lua_newtable(L); /* create namespace for lib */ + ns = lua_gettop(L); + getfield(L, env, "package.loaded"); /* get package.loaded table */ + if (lua_isnil(L, -1)) { /* create package.loaded table */ + lua_pop(L, 1); /* remove previous result */ + lua_newtable(L); + lua_pushvalue(L, -1); + setfield(L, env, "package.loaded"); + } + else if (!lua_istable(L, -1)) + luaL_error(L, "name conflict for library `%s'", libname); + lua_pushstring(L, libname); + lua_pushvalue(L, ns); + lua_settable(L, -3); /* package.loaded[libname] = ns */ + lua_pop(L, 1); /* get rid of package.loaded table */ + lua_pushvalue(L, ns); /* copy namespace */ + setfield(L, LUA_GLOBALSINDEX, libname); + lua_remove (L, env); /* remove env */ + } + lua_insert(L, -(nup+1)); /* move library table to below upvalues */ + } + for (; l->name; l++) { + int i; + lua_pushstring(L, l->name); + for (i=0; ifunc, nup); + lua_settable(L, -(nup+3)); + } + lua_pop(L, nup); /* remove upvalues */ +} + diff --git a/bindings/lua/compat-5.1r5/compat-5.1.h b/bindings/lua/compat-5.1r5/compat-5.1.h new file mode 100644 index 0000000..001d7dd --- /dev/null +++ b/bindings/lua/compat-5.1r5/compat-5.1.h @@ -0,0 +1,13 @@ +/* +** Compat-5.1 +** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat/) +** $Id$ +*/ + +#ifndef COMPAT_H + +LUALIB_API void luaL_module(lua_State *L, const char *libname, + const luaL_reg *l, int nup); +#define luaL_openlib luaL_module + +#endif diff --git a/bindings/lua/compat-5.1r5/compat-5.1.lua b/bindings/lua/compat-5.1r5/compat-5.1.lua new file mode 100644 index 0000000..0938d56 --- /dev/null +++ b/bindings/lua/compat-5.1r5/compat-5.1.lua @@ -0,0 +1,267 @@ +-- +-- Compat-5.1 +-- Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/compat) +-- According to Lua 5.1 +-- $Id: compat-5.1.lua,v 1.22 2006/02/20 21:12:47 carregal Exp $ +-- + +_COMPAT51 = "Compat-5.1 R5" + +local LUA_DIRSEP = '/' +local LUA_OFSEP = '_' +local OLD_LUA_OFSEP = '' +local POF = 'luaopen_' +local LUA_PATH_MARK = '?' +local LUA_IGMARK = ':' + +local assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type = assert, error, getfenv, ipairs, loadfile, loadlib, pairs, setfenv, setmetatable, type +local find, format, gfind, gsub, sub = string.find, string.format, string.gfind, string.gsub, string.sub + +-- +-- avoid overwriting the package table if it's already there +-- +package = package or {} +local _PACKAGE = package + +package.path = LUA_PATH or os.getenv("LUA_PATH") or + ("./?.lua;" .. + "/usr/local/share/lua/5.0/?.lua;" .. + "/usr/local/share/lua/5.0/?/?.lua;" .. + "/usr/local/share/lua/5.0/?/init.lua" ) + +package.cpath = LUA_CPATH or os.getenv("LUA_CPATH") or + "./?.so;" .. + "./l?.so;" .. + "/usr/local/lib/lua/5.0/?.so;" .. + "/usr/local/lib/lua/5.0/l?.so" + +-- +-- make sure require works with standard libraries +-- +package.loaded = package.loaded or {} +package.loaded.debug = debug +package.loaded.string = string +package.loaded.math = math +package.loaded.io = io +package.loaded.os = os +package.loaded.table = table +package.loaded.base = _G +package.loaded.coroutine = coroutine +local _LOADED = package.loaded + +-- +-- avoid overwriting the package.preload table if it's already there +-- +package.preload = package.preload or {} +local _PRELOAD = package.preload + + +-- +-- looks for a file `name' in given path +-- +local function findfile (name, pname) + name = gsub (name, "%.", LUA_DIRSEP) + local path = _PACKAGE[pname] + assert (type(path) == "string", format ("package.%s must be a string", pname)) + for c in gfind (path, "[^;]+") do + c = gsub (c, "%"..LUA_PATH_MARK, name) + local f = io.open (c) + if f then + f:close () + return c + end + end + return nil -- not found +end + + +-- +-- check whether library is already loaded +-- +local function loader_preload (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + assert (type(_PRELOAD) == "table", "`package.preload' must be a table") + return _PRELOAD[name] +end + + +-- +-- Lua library loader +-- +local function loader_Lua (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local filename = findfile (name, "path") + if not filename then + return false + end + local f, err = loadfile (filename) + if not f then + error (format ("error loading module `%s' (%s)", name, err)) + end + return f +end + + +local function mkfuncname (name) + name = gsub (name, "^.*%"..LUA_IGMARK, "") + name = gsub (name, "%.", LUA_OFSEP) + return POF..name +end + +local function old_mkfuncname (name) + --name = gsub (name, "^.*%"..LUA_IGMARK, "") + name = gsub (name, "%.", OLD_LUA_OFSEP) + return POF..name +end + +-- +-- C library loader +-- +local function loader_C (name) + assert (type(name) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local filename = findfile (name, "cpath") + if not filename then + return false + end + local funcname = mkfuncname (name) + local f, err = loadlib (filename, funcname) + if not f then + funcname = old_mkfuncname (name) + f, err = loadlib (filename, funcname) + if not f then + error (format ("error loading module `%s' (%s)", name, err)) + end + end + return f +end + + +local function loader_Croot (name) + local p = gsub (name, "^([^.]*).-$", "%1") + if p == "" then + return + end + local filename = findfile (p, "cpath") + if not filename then + return + end + local funcname = mkfuncname (name) + local f, err, where = loadlib (filename, funcname) + if f then + return f + elseif where ~= "init" then + error (format ("error loading module `%s' (%s)", name, err)) + end +end + +-- create `loaders' table +package.loaders = package.loaders or { loader_preload, loader_Lua, loader_C, loader_Croot, } +local _LOADERS = package.loaders + + +-- +-- iterate over available loaders +-- +local function load (name, loaders) + -- iterate over available loaders + assert (type (loaders) == "table", "`package.loaders' must be a table") + for i, loader in ipairs (loaders) do + local f = loader (name) + if f then + return f + end + end + error (format ("module `%s' not found", name)) +end + +-- sentinel +local sentinel = function () end + +-- +-- new require +-- +function _G.require (modname) + assert (type(modname) == "string", format ( + "bad argument #1 to `require' (string expected, got %s)", type(name))) + local p = _LOADED[modname] + if p then -- is it there? + if p == sentinel then + error (format ("loop or previous error loading module '%s'", modname)) + end + return p -- package is already loaded + end + local init = load (modname, _LOADERS) + _LOADED[modname] = sentinel + local actual_arg = _G.arg + _G.arg = { modname } + local res = init (modname) + if res then + _LOADED[modname] = res + end + _G.arg = actual_arg + if _LOADED[modname] == sentinel then + _LOADED[modname] = true + end + return _LOADED[modname] +end + + +-- findtable +local function findtable (t, f) + assert (type(f)=="string", "not a valid field name ("..tostring(f)..")") + local ff = f.."." + local ok, e, w = find (ff, '(.-)%.', 1) + while ok do + local nt = rawget (t, w) + if not nt then + nt = {} + t[w] = nt + elseif type(t) ~= "table" then + return sub (f, e+1) + end + t = nt + ok, e, w = find (ff, '(.-)%.', e+1) + end + return t +end + +-- +-- new package.seeall function +-- +function _PACKAGE.seeall (module) + local t = type(module) + assert (t == "table", "bad argument #1 to package.seeall (table expected, got "..t..")") + local meta = getmetatable (module) + if not meta then + meta = {} + setmetatable (module, meta) + end + meta.__index = _G +end + + +-- +-- new module function +-- +function _G.module (modname, ...) + local ns = _LOADED[modname] + if type(ns) ~= "table" then + ns = findtable (_G, modname) + if not ns then + error (string.format ("name conflict for module '%s'", modname)) + end + _LOADED[modname] = ns + end + if not ns._NAME then + ns._NAME = modname + ns._M = ns + ns._PACKAGE = gsub (modname, "[^.]*$", "") + end + setfenv (2, ns) + for i, f in ipairs (arg) do + f (ns) + end +end diff --git a/bindings/lua/rrdlua.c b/bindings/lua/rrdlua.c index bef3e66..a5b9fb7 100644 --- a/bindings/lua/rrdlua.c +++ b/bindings/lua/rrdlua.c @@ -27,11 +27,11 @@ #include "../../src/rrd_tool.h" #ifdef LUA50 - #ifdef HAVE_COMPAT51 - #include "compat-5.1.h" - #else - #include "compat-5.1r5/compat-5.1.h" - #endif +#ifdef HAVE_COMPAT51 +#include "compat-5.1.h" +#else +#include "compat-5.1r5/compat-5.1.h" +#endif #endif extern void rrd_freemem(void *mem); diff --git a/bindings/lua/test.lua b/bindings/lua/test.lua deleted file mode 100644 index 541330c..0000000 --- a/bindings/lua/test.lua +++ /dev/null @@ -1,98 +0,0 @@ --- Test script adapted from the one in the Ruby binding. - -local rrd = require "rrd" - -local name = "test.rrd" -local start = 300 * math.floor(os.time() / 300) - -io.write('\n-- Creating ', name, '\n') -rrd.create( - name, - "--start", start-1, - "--step", "300", - "DS:a:GAUGE:600:U:U", - "DS:b:GAUGE:600:U:U", - "RRA:AVERAGE:0.5:1:300") - -local num_points = 0 -for t=start, start+300*300, 300 do - local s = string.format('%d:%d:%f', t, - math.random(100), math.sin(t/800)*50+50) - rrd.update(name, s) - num_points = num_points + 1 -end - -io.write('rrd file created with ', num_points, ' points, from ', start, - ' to ', start+300*300, '\n') - -io.write('\n-- Testing rrd.info\n') -local info = rrd.info(name) -for k,v in pairs(info) do - io.write(k, '=', v, '\n') -end -io.write('\n') - -io.write('-- Testing rrd.fetch\n') -io.write("fetching data from ", name, ' - interval: ', start, ' to ', - start+300*300, '\n') -local fstart, fend, fstep, fnames, fdata = - rrd.fetch(name, "--start", start, "--end", start+300*300+10, "AVERAGE") -io.write('got ', #fdata[1], ' data sources with ', #fdata, - ' data points each.\n') - --- uncomment below to print fetched data ----[[ -io.write('\n-- Printing fetched data\n') -io.write(' ') -for i, n in ipairs(fnames) do - io.write(n, ' ') -end -io.write('\n') -for i, v in ipairs(fdata) do - local time = fstart + (i-1)*fstep - io.write(string.format('%s (%d): ', os.date("%c", time), time)) - for _, w in ipairs(v) do - io.write(string.format('%e ', w)) - end - io.write('\n') -end -io.write('\n') ---]] - -io.write('\n-- Testing rrd.graphv - creates test.png and returns values\n') -local t = rrd.graphv( - "test.png", - "--title", "Enjoy Lua RRDTool module!", - "--start", start+3600, - "--end", "start + 1000 min", - "--interlace", - "--imgformat", "PNG", - "--width=450", - "DEF:a=" .. name .. ":a:AVERAGE", - "DEF:b=" .. name .. ":b:AVERAGE", - "CDEF:line=TIME,2400,%,300,LT,a,UNKN,IF", - "AREA:b#00b6e4:beta", - "AREA:line#0022e9:alpha", - "LINE3:line#ff0000", - "VDEF:va=a,AVERAGE", - "VDEF:vb=b,AVERAGE", - "PRINT:va:%5.2lf", - "PRINT:vb:%5.2lf") - -io.write('The graph "test.png" was created.\n') - --- uncomment below to print graphv returned data ---[[ -io.write('\n-- Printing returned values\n') -io.write('print[0]: ', t['print[0]'], '\n') -io.write('print[1]: ', t['print[1]'], '\n') -for k, v in pairs(t) do - if not string.match(k, '^print%[%d+%]') then - io.write(k, ': ', v, '\n') - end -end -io.write('\n') ---]] - -io.write('Use your preferred viewer to display the graph.\n\n') - diff --git a/bindings/lua/test.lua.bottom b/bindings/lua/test.lua.bottom new file mode 100644 index 0000000..caa590c --- /dev/null +++ b/bindings/lua/test.lua.bottom @@ -0,0 +1,90 @@ + +local rrd = require 'rrd' + +local name = 'test.rrd' +local start = 300 * math.floor(os.time() / 300) + +io.write('\n-- Creating ', name, '\n') +rrd.create( + name, + '--start', start-1, + '--step', '300', + 'DS:a:GAUGE:600:U:U', + 'DS:b:GAUGE:600:U:U', + 'RRA:AVERAGE:0.5:1:300') + +local num_points = 0 +for t=start, start+300*300, 300 do + local s = string.format('%d:%d:%f', t, + math.random(100), math.sin(t/800)*50+50) + rrd.update(name, s) + num_points = num_points + 1 +end + +io.write('rrd file created with ', num_points, ' points, from ', start, + ' to ', start+300*300, '\n') + +io.write('\n-- Testing rrd.info\n') +local info = rrd.info(name) +for k,v in pairs(info) do + io.write(k, '=', v, '\n') +end +io.write('\n') + +io.write('-- Testing rrd.fetch\n') +io.write('fetching data from ', name, ' - interval: ', start, ' to ', + start+300*300, '\n') +local fstart, fstep, fnames, fdata = + rrd.fetch(name, '--start', start, '--end', start+300*300+10, 'AVERAGE') +io.write('got ', table.getn(fdata[1]), ' data sources with ', table.getn(fdata), + ' data points each.\n') + +io.write('\n-- Printing fetched data\n') +io.write(' ') +for i, n in ipairs(fnames) do + io.write(n, ' ') +end +io.write('\n') +for i, v in ipairs(fdata) do + local time = fstart + (i-1)*fstep + io.write(string.format('%s (%d): ', os.date('%c', time), time)) + for _, w in ipairs(v) do + io.write(string.format('%e ', w)) + end + io.write('\n') +end +io.write('\n') + +io.write('\n-- Testing rrd.graphv - creates test.png and returns values\n') +local t = rrd.graphv( + 'test.png', + '--title', 'Enjoy Lua RRDtool module!', + '--start', start+3600, + '--end', 'start + 1000 min', + '--interlace', + '--imgformat', 'PNG', + '--width=450', + 'DEF:a=' .. name .. ':a:AVERAGE', + 'DEF:b=' .. name .. ':b:AVERAGE', + 'CDEF:line=TIME,2400,%,300,LT,a,UNKN,IF', + 'AREA:b#00b6e4:beta', + 'AREA:line#0022e9:alpha', + 'LINE3:line#ff0000', + 'VDEF:va=a,AVERAGE', + 'VDEF:vb=b,AVERAGE', + 'PRINT:va:%5.2lf', + 'PRINT:vb:%5.2lf') + +io.write('\n-- Returned values:\n') +io.write('print[0]: ', t['print[0]'], '\n') +io.write('print[1]: ', t['print[1]'], '\n') +for k, v in pairs(t) do + if not string.find(k, '^print%[%d+%]') then + io.write(k, ': ', v, '\n') + end +end +io.write('\n') + +io.write('-- The graph "test.png" was created.\n') +io.write('-- Use your preferred viewer to display it.\n\n') + diff --git a/configure.ac b/configure.ac index a2ece2b..04f9a11 100644 --- a/configure.ac +++ b/configure.ac @@ -651,19 +651,19 @@ LUA_EOF AC_MSG_RESULT([no, version found is $LUA_MAJOR.$LUA_MINOR]) else AC_MSG_RESULT([$LUA_MAJOR.$LUA_MINOR found]) - vdot=$LUA_MAJOR.$LUA_MINOR - vndot=$LUA_MAJOR$LUA_MINOR + lua_vdot=$LUA_MAJOR.$LUA_MINOR + lua_vndot=$LUA_MAJOR$LUA_MINOR lua_version=$LUA_MAJOR.$LUA_MINOR.$LUA_POINT - AC_CHECK_HEADERS(lua$vndot/lua.h, - [AC_CHECK_HEADERS(lua$vndot/lualib.h, - [AC_CHECK_HEADER(lua$vndot/lauxlib.h, - [lua_headerdir=lua$vndot], + AC_CHECK_HEADERS(lua$lua_vndot/lua.h, + [AC_CHECK_HEADERS(lua$lua_vndot/lualib.h, + [AC_CHECK_HEADER(lua$lua_vndot/lauxlib.h, + [lua_headerdir=lua$lua_vndot], [])], [])], - [AC_CHECK_HEADERS(lua$vdot/lua.h, - [AC_CHECK_HEADERS(lua$vdot/lualib.h, - [AC_CHECK_HEADER(lua$vdot/lauxlib.h, - [lua_headerdir=lua$vdot], + [AC_CHECK_HEADERS(lua$lua_vdot/lua.h, + [AC_CHECK_HEADERS(lua$lua_vdot/lualib.h, + [AC_CHECK_HEADER(lua$lua_vdot/lauxlib.h, + [lua_headerdir=lua$lua_vdot], [])], [])], [AC_CHECK_HEADERS(lua.h, @@ -682,23 +682,20 @@ LUA_EOF if test "$COMP_LUA" != "lua"; then enable_lua=no - AC_MSG_WARN([Lua $vdot found but not lua.h, lualib.h and lauxlib.h! Please install the -dev packages for Lua $vdot]) + AC_MSG_WARN([Lua $lua_vdot found but not lua.h, lualib.h and lauxlib.h! Please install the -dev packages for Lua $lua_vdot]) else # OK, headers found, let's check the libraries (LIBS is not used) LIBS= lua_havelib=no LUA_HAVE_COMPAT51=DONT_HAVE_COMPAT51 - AC_SEARCH_LIBS(lua_call, lua$vdot lua$vndot lua, - [AC_SEARCH_LIBS(luaL_register, lua$vdot lua$vndot lua, - [lua_havelib=LUA$vndot], - [AC_SEARCH_LIBS(luaL_module, lualib$vndot lualib$vdot lualib, - [lua_havelib=$vndot ; - AC_CHECK_HEADERS(lua$vndot/compat-5.1.h, - [LUA_HAVE_COMPAT51=HAVE_COMPAT51], [], - [[#include - #include ]])], - [AC_SEARCH_LIBS(luaL_openlib, lualib$vdot lualib$vndot lualib, - [lua_havelib=$vndot], + AC_SEARCH_LIBS(lua_call, lua$lua_vdot lua$lua_vndot lua, + [AC_SEARCH_LIBS(luaL_register, lua$lua_vdot lua$lua_vndot lua, + [lua_havelib=LUA$lua_vndot], + [AC_SEARCH_LIBS(luaL_module, lualib$lua_vndot lualib$lua_vdot lualib, + [lua_havelib=$lua_vndot; $LUA -l compat-5.1 2>/dev/null; + test "$?" = "0" && LUA_HAVE_COMPAT51=HAVE_COMPAT51], + [AC_SEARCH_LIBS(luaL_openlib, lualib$lua_vdot lualib$lua_vndot lualib, + [lua_havelib=$lua_vndot], [COMP_LUA=], [-lm])], [-lm])], [-lm])], [COMP_LUA=], [-lm]) lua_libs=$LIBS @@ -706,69 +703,70 @@ LUA_EOF # Options to pass when configuring Lua module if test "$lua_havelib" != "no"; then - # OK, headers and libs found - # try to set lua include, lib and C installation dirs with pkg-config + # OK, headers and libs found. Try to set lua flags + # and modules installation dirs with pkg-config if test "$PKGCONFIG" != "no"; then - if test "$vndot" = "50"; then + if test "$lua_vndot" = "50"; then lua_pkg_prefix=lualib else lua_pkg_prefix=lua fi # try with dot, without dot and finally without version - for f in $lua_pkg_prefix$vdot $lua_pkg_prefix$vndot $lua_pkg_prefix; do - lua_cflags=$($PKGCONFIG --cflags $f 2>/dev/null) - if test "$lua_cflags" != ""; then - # OK, found CFLAGS. Get Lua LFLAGS and lib install dir - LUA_CFLAGS=$lua_cflags - LUA_LFLAGS=$($PKGCONFIG --libs $f) - LUA_INSTALL_CMOD=$($PKGCONFIG --variable=INSTALL_CMOD $f) - break + for f in $lua_pkg_prefix$lua_vdot $lua_pkg_prefix$lua_vndot $lua_pkg_prefix; do + lua_exec_prefix=`$PKGCONFIG --variable=prefix $f 2>/dev/null` + # same binaries? + if test "$lua_exec_prefix/bin/lua" = "$LUA"; then + # OK, found CFLAGS. Get Lua LFLAGS and modules install dir + LUA_CFLAGS=`$PKGCONFIG --cflags $f 2>/dev/null` + LUA_LFLAGS=`$PKGCONFIG --libs $f 2>/dev/null` + LUA_INSTALL_CMOD=`$PKGCONFIG --variable=INSTALL_CMOD $f 2>/dev/null` + LUA_INSTALL_LMOD=`$PKGCONFIG --variable=INSTALL_LMOD $f 2>/dev/null` + break fi done fi - # if not set with pkg-config, use default values in src package - if test "$LUA_CFLAGS" = ""; then - AC_MSG_WARN(Setting Lua include and lib dirs to defaults in src package) - LUA_CFLAGS="-I/usr/local/include -I/usr/local/include/lua -I/usr/local/include/lua/$vdot" - LUA_LFLAGS="-L/usr/local/lib -L/usr/local/lib/lua -L/usr/local/lib/lua/$vdot $lua_libs" - LUA_INSTALL_CMOD="/usr/local/lib/lua/$vdot" + LUA_RRD_LIBDIR="$langpref/lib/lua/$lua_vdot" + # if lua 5.0 can't find compat-5.1, force installation of + # compat-5.1.lua together with RRDtool. + if test "$lua_vdot" = "5.0" -a "$LUA_HAVE_COMPAT51" != "HAVE_COMPAT51"; then + lua_need_compat51=1 + LUA_INSTALL_LMOD="$LUA_RRD_LIBDIR" fi - LUA_SRCS=rrdlua.c - LUA_OBJS=rrdlua.o - # If Lua 5.0, we need compat-5.1. Add ours unless already - # integrated as in Debian/Ubuntu 5.0 -dev packages. - if test "$vdot" = "5.0" -a "$LUA_HAVE_COMPAT51" != "HAVE_COMPAT51"; then - LUA_SRCS="rrdlua.c compat-5.1r5/compat-5.1.c" - LUA_OBJS="rrdlua.o compat-5.1r5/compat-5.1.o" + + # if not set with pkg-config, use default values in src packages compat-5.1, lua 5.1 + if test "$LUA_CFLAGS" = ""; then + AC_MSG_WARN(Setting Lua include and lib flags to defaults in compat-5.1 and lua 5.1 sources) + LUA_CFLAGS="-I/usr/local/include -I/usr/local/include/lua -I/usr/local/include/lua/$lua_vdot" + LUA_LFLAGS="-L/usr/local/lib -L/usr/local/lib/lua -L/usr/local/lib/lua/$lua_vdot $lua_libs" + LUA_INSTALL_CMOD="/usr/local/lib/lua/$lua_vdot" fi dnl pass additional lua options - # if lua-site-install is not set, overwrite LUA_INSTALL_CMOD already - # found and install together with RRDtool, under $langpref. - LUA_RRD_LANGPREF="$langpref/lib/lua" + dnl if lua-site-install is not set, overwrite LUA_INSTALL_CMOD already + dnl found and install together with RRDtool, under $langpref. AC_ARG_ENABLE(lua-site-install, - [ --enable-lua-site-install by default the rrdtool lua modules are installed - together with rrdtool in $prefix/lib/lua. You have to - add $prefix/lib/lua/$lua_version/?.so to package.cpath - for lua to find the rrd.so file. When you set this - option the Lua module will get installed wherever - your Lua setup thinks it is best.], + [ --enable-lua-site-install by default the lua module is installed + together with rrdtool in $prefix/lib/lua/$lua_version. + You have to add $prefix/lib/lua/$lua_version/?.so to + package.cpath for lua to find 'rrd.so'. For lua 5.0 + you may also need to change LUA_PATH to the same dir, + to require 'compat-5.1'. When you set this option the + lua modules will get installed wherever your Lua + setup thinks it is best. + WARNING: if you set this option, system lua modules + compat-5.1.lua and rrd.so, if any, may be overwritten.], [], - [LUA_INSTALL_CMOD="$LUA_RRD_LANGPREF/$vdot"]) + [LUA_INSTALL_CMOD="$LUA_RRD_LIBDIR"; LUA_INSTALL_LMOD="$LUA_RRD_LIBDIR"]) + LUA_DEFINES="-DLUA$lua_vndot -D$LUA_HAVE_COMPAT51" AC_SUBST(LUA) AC_SUBST(COMP_LUA) - AC_SUBST(LUA_MAJOR) - AC_SUBST(LUA_MINOR) - AC_SUBST(LUA_POINT) - AC_SUBST(LUA_RRD_LANGPREF) AC_SUBST(LUA_INSTALL_CMOD) - AC_SUBST(LUA_HAVE_COMPAT51) + AC_SUBST(LUA_INSTALL_LMOD) AC_SUBST(LUA_CFLAGS) AC_SUBST(LUA_LFLAGS) - AC_SUBST(LUA_SRCS) - AC_SUBST(LUA_OBJS) + AC_SUBST(LUA_DEFINES) else enable_lua=no AC_MSG_RESULT([Lua headers found but not the libraries! Please reinstall the dev packages for Lua $LUA_MAJOR.$LUA_MINOR]) @@ -776,7 +774,14 @@ LUA_EOF fi fi fi - +dnl If Lua 5.0, we need compat-5.1. Add ours unless already +dnl integrated as in Debian/Ubuntu 5.0 -dev packages. +AM_CONDITIONAL(LUA_NEED_OUR_COMPAT51, + [test "$lua_vdot" = "5.0" -a "$LUA_HAVE_COMPAT51" != "HAVE_COMPAT51"]) +AM_CONDITIONAL(LUA_SITE_CINSTALL, [test "$LUA_INSTALL_CMOD" != "$LUA_RRD_LIBDIR"]) +AM_CONDITIONAL(LUA_SITE_LINSTALL, [test "$LUA_INSTALL_LMOD" != "$LUA_RRD_LIBDIR"]) +AM_CONDITIONAL(LUA50, [test "$lua_vndot" = "50"]) +AM_CONDITIONAL(BUILD_LUA, [test "$enable_lua" = "yes"]) enable_tcl_site=no @@ -874,7 +879,7 @@ AC_CONFIG_FILES([bindings/Makefile]) AC_CONFIG_FILES([bindings/tcl/Makefile]) AC_CONFIG_FILES([bindings/tcl/ifOctets.tcl]) AC_CONFIG_FILES([Makefile]) -AC_CONFIG_FILES([bindings/lua/Makefile.lua]) +AC_CONFIG_FILES([bindings/lua/Makefile]) AC_CONFIG_COMMANDS([default],[[ chmod +x examples/*.pl]],[[]]) AC_OUTPUT @@ -908,9 +913,14 @@ echo " Ruby Modules: $COMP_RUBY" echo " Ruby Binary: $RUBY" echo " Ruby Options: $RUBY_MAKE_OPTIONS" echo " Build Lua Bindings: $enable_lua" +if test "$enable_lua" = "yes"; then echo " Lua Binary: $LUA" echo " Lua Version: $lua_version" -echo " Lua module dir: $LUA_INSTALL_CMOD" +echo " Lua C-modules dir: $LUA_INSTALL_CMOD" +if test "$lua_need_compat51" = "1"; then +echo " Lua Lua-modules dir: $LUA_INSTALL_LMOD" +fi +fi echo " Build Tcl Bindings: $enable_tcl" echo " Build Python Bindings: $enable_python" echo " Build rrdcgi: $enable_rrdcgi" -- 2.30.2