kopia lustrzana https://github.com/Hamlib/Hamlib
Added Lua binding and demo script
rodzic
bbbbf3c6cd
commit
2b657e7c9d
12
INSTALL
12
INSTALL
|
@ -286,6 +286,7 @@ are:
|
|||
--with-python-binding build python binding and demo [default=no]
|
||||
--with-tcl-binding build Tcl binding and demo [default=no]
|
||||
--with-tcl=PATH directory containing tcl configuration (tclConfig.sh)
|
||||
--with-lua-binding build lua binding and demo [default=no]
|
||||
|
||||
Optional features that may require specialized hardware are:
|
||||
|
||||
|
@ -301,12 +302,12 @@ Bindings notes
|
|||
you can disable this optional part by passing `--without-cxx-binding'
|
||||
to the configure script (may happen under MacOSX).
|
||||
|
||||
Note that the Perl, Python, and TCL bindings are disabled by default so
|
||||
Note that the Perl, Python, Lua and TCL bindings are disabled by default so
|
||||
they will need to be specifically enabled for language binding support (this
|
||||
has no effect on rigctld/rotctld). You may get a make error (which means it
|
||||
will quit before compilation is complete) if the
|
||||
--with-[perl|python|tcl]-binding option(s) are given and the Swig package is
|
||||
not installed.
|
||||
--with-[perl|python|tcl|lua]-binding option(s) are given and the Swig package
|
||||
is not installed.
|
||||
|
||||
Perl and Python bindings should be installed into a 'configure' runtime
|
||||
discovered location under the default prefix.
|
||||
|
@ -319,7 +320,10 @@ packages and since there seemed to be no common location among distributions,
|
|||
this path was chosen abitrarily. Any patches to improve installation path
|
||||
discovery of local packages are welcome.
|
||||
|
||||
When running 'make uninstall' the installed files for the Python and TCL
|
||||
Lua binding will be installed into $(libdir)/lua/$(LUA_VERSION) (default).
|
||||
For non-default settings, see notes at other bindings.
|
||||
|
||||
When running 'make uninstall' the installed files for the Python, Lua and TCL
|
||||
modules are removed. The Perl files will remain due to a design decision
|
||||
of the Perl MakeMaker module. Installed Perl binding files will need to be
|
||||
removed manually.
|
||||
|
|
|
@ -14,9 +14,9 @@ SWGDEP=$(top_srcdir)/include/hamlib/rig.h $(top_srcdir)/include/hamlib/riglist.h
|
|||
$(SWGFILES)
|
||||
|
||||
EXTRA_DIST = $(SWGFILES) \
|
||||
Makefile.PL perltest.pl tcltest.tcl pytest.py
|
||||
Makefile.PL perltest.pl tcltest.tcl pytest.py luatest.lua
|
||||
|
||||
noinst_SCRIPTS = perltest.pl tcltest.tcl pytest.py hamlibvb.bas
|
||||
noinst_SCRIPTS = perltest.pl tcltest.tcl pytest.py hamlibvb.bas luatest.lua
|
||||
|
||||
BUILT_SOURCES=
|
||||
MOSTLYCLEANFILES=
|
||||
|
@ -157,6 +157,43 @@ uninstall-tcl:
|
|||
endif
|
||||
# TCL
|
||||
|
||||
if ENABLE_LUA
|
||||
##########################################
|
||||
# Lua binding
|
||||
|
||||
luaexec_ltlib = Hamliblua.la
|
||||
|
||||
MOSTLYCLEANFILES+= hamliblua_wrap.c
|
||||
BUILT_SOURCES += hamliblua_wrap.c
|
||||
|
||||
nodist_luaexec_LUA = Hamlib.lua
|
||||
nodist_Hamliblua_la_SOURCES = hamliblua_wrap.c
|
||||
|
||||
Hamliblua_la_CPPFLAGS = $(LUA_INCLUDE) -I$(top_srcdir)/include -I$(top_srcdir)/src
|
||||
Hamliblua_la_LDFLAGS = -no-undefined -module -avoid-version
|
||||
Hamliblua_la_LIBADD = $(top_builddir)/src/libhamlib.la
|
||||
Hamliblua_ladir = $(luaexecdir)
|
||||
Hamliblua_la_LTLIBRARIES = $(luaexec_ltlib)
|
||||
|
||||
all-lua: $(luaexec_ltlib)
|
||||
|
||||
check-lua: all-lua
|
||||
LUA_CPATH="$(abs_builddir)/.libs/?.so" $(srcdir)/luatest.lua || echo "Lua test failed" 1>&2
|
||||
|
||||
Hamlib.lua: hamliblua_wrap.c
|
||||
|
||||
hamliblua_wrap.c: hamlib.swg $(SWGDEP)
|
||||
$(SWIG) -lua @AM_CPPFLAGS@ -I$(top_srcdir)/bindings -o $@ \
|
||||
`test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg
|
||||
|
||||
install-lua:
|
||||
clean-lua:
|
||||
distclean-lua:
|
||||
uninstall-lua:
|
||||
|
||||
endif
|
||||
# Lua
|
||||
|
||||
|
||||
all-local: @BINDING_ALL@
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
|
||||
#ifndef SWIGLUA
|
||||
%module Hamlib
|
||||
#else
|
||||
%module Hamliblua
|
||||
#endif
|
||||
|
||||
%{
|
||||
/*
|
||||
|
@ -32,6 +36,7 @@
|
|||
#include "misc.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
%}
|
||||
|
||||
/*
|
||||
|
@ -41,7 +46,9 @@
|
|||
|
||||
%include typemaps.i
|
||||
%include exception.i
|
||||
#ifndef SWIGLUA
|
||||
%include cstring.i
|
||||
#endif
|
||||
#ifdef SWIGPYTHON
|
||||
%include python/file.i
|
||||
|
||||
|
@ -125,17 +132,63 @@
|
|||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SWIGLUA
|
||||
|
||||
%typemap(out) int [ANY] {
|
||||
int len,i;
|
||||
len = $1_dim0;
|
||||
lua_createtable (L, len, 0);
|
||||
for(i=0; i<len; i++) {
|
||||
lua_pushinteger(L, (i+1)); // Lua starts list index with 1
|
||||
lua_pushinteger(L, (lua_Integer)$1[i]);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
SWIG_arg++;
|
||||
}
|
||||
|
||||
%typemap(varout) int [ANY] {
|
||||
int len,i;
|
||||
len = $1_dim0;
|
||||
lua_createtable (L, len, 0);
|
||||
for(i=0; i<len; i++) {
|
||||
lua_pushinteger(L, (i+1)); // Lua starts list index with 1
|
||||
lua_pushinteger(L, (lua_Integer)$1[i]);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
SWIG_arg++;
|
||||
}
|
||||
|
||||
%typemap(in,numinputs=0) char * OUTPUT (char *returnstr) {
|
||||
char returnstr[1024];
|
||||
$1 = returnstr;
|
||||
}
|
||||
|
||||
%typemap(argout) char * OUTPUT {
|
||||
lua_pushstring(L,(char *)$1); SWIG_arg++;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
%apply double *OUTPUT { double *distance, double *azimuth };
|
||||
%apply int *OUTPUT { int *degrees, int *minutes, double *seconds, int *sw };
|
||||
%apply int *OUTPUT { int *degrees, double *minutes, int *sw };
|
||||
%apply double *OUTPUT { double *longitude, double *latitude };
|
||||
%apply char *OUTPUT { char *locator_res };
|
||||
|
||||
%apply char *OUTPUT { char *locator_res };
|
||||
%apply char *OUTPUT { char *hamlib_version2 };
|
||||
%apply char *OUTPUT { char *hamlib_copyright2 };
|
||||
%apply char *OUTPUT { char *returnstr };
|
||||
|
||||
#ifndef SWIGLUA
|
||||
#ifndef SWIG_CSTRING_UNIMPL
|
||||
/* longlat2locator */
|
||||
%cstring_bounded_output(char *locator_res, 13)
|
||||
%cstring_bounded_output(char *hamlib_version2, 4)
|
||||
%cstring_bounded_output(char *hamlib_copyright2, 4)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
%immutable confparams::name;
|
||||
|
@ -147,6 +200,8 @@
|
|||
%immutable rig_caps::mfg_name;
|
||||
%immutable rig_caps::version;
|
||||
%immutable rig_caps::copyright;
|
||||
%immutable hamlib_version2;
|
||||
%immutable hamlib_copyright2;
|
||||
|
||||
%immutable clone_combo_set;
|
||||
%immutable clone_combo_get;
|
||||
|
|
|
@ -206,3 +206,14 @@
|
|||
%ignore rot_reset;
|
||||
%ignore rot_move;
|
||||
%ignore rot_get_info;
|
||||
|
||||
%ignore hamlib_copyright2;
|
||||
%ignore hamlib_version2;
|
||||
|
||||
#ifdef SWIGLUA
|
||||
%ignore Rig::set_level(setting_t,int,vfo_t);
|
||||
%ignore Rig::set_level(char const *,int,vfo_t);
|
||||
%ignore Rig::set_parm(setting_t,int);
|
||||
%ignore Rig::set_parm(char const *,int);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -0,0 +1,123 @@
|
|||
#!/usr/bin/lua
|
||||
|
||||
Hamlib = require("Hamliblua")
|
||||
|
||||
-- you can see the Hamlib properties:
|
||||
-- for key,value in pairs(Hamlib) do print(key,value) end
|
||||
|
||||
function doStartup()
|
||||
print(string.format("%s test, %s\n", _VERSION, Hamlib.hamlib_version))
|
||||
|
||||
|
||||
-- Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_TRACE)
|
||||
Hamlib.rig_set_debug (Hamlib.RIG_DEBUG_NONE)
|
||||
|
||||
-- Init RIG_MODEL_DUMMY
|
||||
my_rig = Hamlib.Rig (Hamlib.RIG_MODEL_DUMMY)
|
||||
-- you can see the Rig properties:
|
||||
-- for key,value in pairs(my_rig) do print(key,value) end
|
||||
|
||||
my_rig:set_conf("rig_pathname", "/dev/Rig")
|
||||
|
||||
my_rig:set_conf("retry", "5")
|
||||
my_rig:open()
|
||||
|
||||
-- 1073741944 is token value for "itu_region"
|
||||
-- but using get_conf is much more convenient
|
||||
region = my_rig:get_conf(1073741944)
|
||||
regionstr = my_rig:get_conf("itu_region")
|
||||
tpath = my_rig:get_conf("rig_pathname")
|
||||
retry = my_rig:get_conf("retry")
|
||||
|
||||
print (string.format("status(str):\t\t%s", Hamlib.rigerror(my_rig.error_status)))
|
||||
print (string.format("get_conf:\t\tpath = %s, retry = %s, ITU region = %s, ITU region (str) = %s", tpath, retry, region, regionstr))
|
||||
|
||||
my_rig:set_freq(Hamlib.RIG_VFO_B, 5700000000)
|
||||
my_rig:set_vfo(Hamlib.RIG_VFO_B)
|
||||
print(string.format("freq:\t\t\t%d", my_rig:get_freq()))
|
||||
my_rig:set_freq(Hamlib.RIG_VFO_A, 145550000)
|
||||
my_rig:set_vfo(Hamlib.RIG_VFO_A)
|
||||
|
||||
mode, width = my_rig:get_mode()
|
||||
print(string.format("mode:\t\t\t%s\nbandwidth:\t\t%s", Hamlib.rig_strrmode(mode), width))
|
||||
|
||||
my_rig:set_mode(Hamlib.RIG_MODE_CW)
|
||||
mode, width = my_rig:get_mode()
|
||||
print(string.format("mode:\t\t\t%s\nbandwidth:\t\t%d", Hamlib.rig_strrmode(mode), width))
|
||||
|
||||
print(string.format("ITU_region:\t\t%s", my_rig.state.itu_region))
|
||||
print(string.format("Backend copyright:\t%s",my_rig.caps.copyright))
|
||||
|
||||
print(string.format("Model:\t\t\t%s", my_rig.caps.model_name))
|
||||
print(string.format("Manufacturer:\t\t%s", my_rig.caps.mfg_name))
|
||||
print(string.format("Backend version:\t%s", my_rig.caps.version))
|
||||
print(string.format("Backend license:\t%s", my_rig.caps.copyright))
|
||||
print(string.format("Rig info:\t\t%s", my_rig:get_info()))
|
||||
|
||||
my_rig:set_level("VOX", 1)
|
||||
print(string.format("status:\t\t\t%s - %s", my_rig.error_status, Hamlib.rigerror(my_rig.error_status)))
|
||||
print(string.format("VOX level:\t\t%d", my_rig:get_level_i("VOX")))
|
||||
my_rig:set_level(Hamlib.RIG_LEVEL_VOX, 5)
|
||||
print(string.format("status:\t\t\t%s - %s", my_rig.error_status, Hamlib.rigerror(my_rig.error_status)))
|
||||
-- see the func name (get_level_i) and format (%d)
|
||||
print(string.format("VOX level:\t\t%d", my_rig:get_level_i(Hamlib.RIG_LEVEL_VOX)))
|
||||
|
||||
af = 12.34
|
||||
print(string.format("Setting AF to %f...", af))
|
||||
my_rig:set_level(Hamlib.RIG_LEVEL_AF, af)
|
||||
print(string.format("status:\t\t\t%s - %s", my_rig.error_status, Hamlib.rigerror(my_rig.error_status)))
|
||||
-- see the different of func name and format related to RIG_LEVEL_VOX!
|
||||
print(string.format("AF level:\t\t%f", my_rig:get_level_f("AF")))
|
||||
|
||||
print(string.format("strength:\t\t%d", my_rig:get_level_i(Hamlib.RIG_LEVEL_STRENGTH)))
|
||||
print(string.format("status:\t\t\t%s", my_rig.error_status))
|
||||
print(string.format("status(str):\t\t%s", Hamlib.rigerror(my_rig.error_status)))
|
||||
|
||||
chan = Hamlib.channel(Hamlib.RIG_VFO_B)
|
||||
|
||||
my_rig:get_channel(chan)
|
||||
print(string.format("get_channel status:\t%d", my_rig.error_status))
|
||||
|
||||
print(string.format("VFO:\t\t\t%s, %s", Hamlib.rig_strvfo(chan.vfo), chan.freq))
|
||||
print(string.format("Attenuators:\t\t%s", table.concat(my_rig.caps.attenuator, ", ")))
|
||||
|
||||
print("\nSending Morse, '73'")
|
||||
my_rig:send_morse(Hamlib.RIG_VFO_A, "73")
|
||||
|
||||
my_rig:close ()
|
||||
|
||||
print("\nSome static functions:")
|
||||
|
||||
err, lon1, lat1 = Hamlib.locator2longlat("IN98XC")
|
||||
err, lon2, lat2 = Hamlib.locator2longlat("DM33DX")
|
||||
err, loc1 = Hamlib.longlat2locator(lon1, lat1, 3)
|
||||
err, loc2 = Hamlib.longlat2locator(lon2, lat2, 3)
|
||||
print(string.format("Loc1:\t\tIN98XC -> %9.4f, %9.4f -> %s", lon1, lat1, loc1))
|
||||
print(string.format("Loc2:\t\tDM33DX -> %9.4f, %9.4f -> %s", lon2, lat2, loc2))
|
||||
|
||||
err, dist, az = Hamlib.qrb(lon1, lat1, lon2, lat2)
|
||||
longpath = Hamlib.distance_long_path(dist)
|
||||
print(string.format("Distance:\t%.3f km, azimuth %.2f, long path:\t%.3f km", dist, az, longpath))
|
||||
|
||||
-- dec2dms expects values from 180 to -180
|
||||
-- sw is 1 when deg is negative (west or south) as 0 cannot be signed
|
||||
err, deg1, mins1, sec1, sw1 = Hamlib.dec2dms(lon1)
|
||||
err, deg2, mins2, sec2, sw2 = Hamlib.dec2dms(lat1)
|
||||
|
||||
lon3 = Hamlib.dms2dec(deg1, mins1, sec1, sw1)
|
||||
lat3 = Hamlib.dms2dec(deg2, mins2, sec2, sw2)
|
||||
|
||||
if sw1 > 0 then D = 'W' else D = 'E' end
|
||||
print(string.format("Longitude:\t%4.4f, %4.0f° %.0f' %2.0f\" %1s\trecoded: %9.4f", lon1, deg1, mins1, sec1, D, lon3))
|
||||
|
||||
if sw2 > 0 then D = 'S' else D = 'N' end
|
||||
print(string.format("Latitude:\t%4.4f, %4.0f° %.0f' %2.0f\" %1s\trecoded: %9.4f", lat1, deg2, mins2, sec2, D, lat3))
|
||||
|
||||
end
|
||||
|
||||
doStartup()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ typedef channel_t * const_channel_t_p;
|
|||
#define METHOD1VGET(f, t1) t1 f (vfo_t vfo = RIG_VFO_CURR) \
|
||||
{ t1 _##t1; self->error_status = rig_##f(self->rig, vfo, &_##t1); return _##t1; }
|
||||
|
||||
|
||||
#ifndef SWIGLUA
|
||||
#define METHODSIMPLESET(f, t1, fld, chk) void set_##f (setting_t stg, t1 fld _VFO_DECL) \
|
||||
{ value_t val; if (chk) { \
|
||||
self->error_status = -RIG_EINVAL; /* invalid type */ \
|
||||
|
@ -89,6 +89,19 @@ typedef channel_t * const_channel_t_p;
|
|||
val.fld = fld; \
|
||||
self->error_status = rig_set_##f(self->rig _VFO_ARG , stg, val); \
|
||||
}
|
||||
#else
|
||||
#define METHODSIMPLESET(f, t1, fld, chk) void set_##f (setting_t stg, t1 fld _VFO_DECL) \
|
||||
{ value_t val; \
|
||||
if (chk) { \
|
||||
int ival = (int)fld; \
|
||||
val.i = fld; \
|
||||
} \
|
||||
else { \
|
||||
val.fld = fld; \
|
||||
} \
|
||||
self->error_status = rig_set_##f(self->rig _VFO_ARG , stg, val); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* RIG_CONF_ extparm's type:
|
||||
|
@ -98,6 +111,7 @@ typedef channel_t * const_channel_t_p;
|
|||
* CHECKBUTTON: val.i 0/1
|
||||
*/
|
||||
|
||||
#ifndef SWIGLUA
|
||||
#define METHODSUPERSET(f, t1, fld, chk) void set_##f (const char *name, t1 fld _VFO_DECL) \
|
||||
{ setting_t stg; value_t val; \
|
||||
stg = rig_parse_##f(name); \
|
||||
|
@ -133,6 +147,45 @@ typedef channel_t * const_channel_t_p;
|
|||
val.fld = fld; \
|
||||
self->error_status = rig_set_##f(self->rig _VFO_ARG , stg, val); \
|
||||
}
|
||||
#else
|
||||
#define METHODSUPERSET(f, t1, fld, chk) void set_##f (const char *name, t1 fld _VFO_DECL) \
|
||||
{ setting_t stg; value_t val; \
|
||||
stg = rig_parse_##f(name); \
|
||||
if (!rig_has_set_##f(self->rig, stg)) { \
|
||||
const struct confparams *cfp; \
|
||||
cfp = rig_ext_lookup(self->rig, name); \
|
||||
if (!cfp) { \
|
||||
self->error_status = -RIG_EINVAL; /* no such parameter */ \
|
||||
return; \
|
||||
} \
|
||||
switch (cfp->type) { \
|
||||
case RIG_CONF_NUMERIC: \
|
||||
val.fld = fld; \
|
||||
break; \
|
||||
case RIG_CONF_CHECKBUTTON: \
|
||||
case RIG_CONF_COMBO: \
|
||||
val.i = (int)fld; \
|
||||
break; \
|
||||
case RIG_CONF_STRING: \
|
||||
self->error_status = -RIG_EINVAL; /* invalid type */ \
|
||||
return; \
|
||||
default: \
|
||||
self->error_status = -RIG_ECONF; \
|
||||
return; \
|
||||
} \
|
||||
self->error_status = rig_set_ext_##f(self->rig _VFO_ARG, cfp->token, val); \
|
||||
return; \
|
||||
} \
|
||||
if (chk) { \
|
||||
int ival = (int)fld; \
|
||||
val.i = ival; \
|
||||
} \
|
||||
else { \
|
||||
val.fld = fld; \
|
||||
} \
|
||||
self->error_status = rig_set_##f(self->rig _VFO_ARG , stg, val); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define METHODSTRSET(f) void set_##f (const char *name, const char *s _VFO_DECL) \
|
||||
{ value_t val; /* only ext_level/parm's can have string values */ \
|
||||
|
@ -224,8 +277,10 @@ typedef channel_t * const_channel_t_p;
|
|||
*/
|
||||
%extend Rig {
|
||||
|
||||
#ifndef SWIGLUA
|
||||
#ifndef SWIG_CSTRING_UNIMPL
|
||||
%cstring_bounded_output(char *returnstr, MAX_RETURNSTR);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Rig(int rig_model) {
|
||||
|
|
28
configure.ac
28
configure.ac
|
@ -563,6 +563,33 @@ AC_SUBST([TCL_LIB_SPEC])
|
|||
AC_SUBST([TCL_INCLUDE_SPEC])
|
||||
AC_SUBST([TCL_SHLIB_SUFFIX])
|
||||
|
||||
dnl Check for lua availability, so we can enable HamlibLua
|
||||
# Lua bindings
|
||||
AC_MSG_CHECKING([whether to build lua binding and demo])
|
||||
AC_ARG_WITH([lua-binding],
|
||||
[AS_HELP_STRING([--with-lua-binding],
|
||||
[build lua binding and demo @<:@default=no@:>@])],
|
||||
[cf_with_lua_binding=$withval],
|
||||
[cf_with_lua_binding=no])
|
||||
AC_MSG_RESULT([$cf_with_lua_binding])
|
||||
|
||||
dnl AX_LUA_DEVEL from macros/ax_lua_devel.m4
|
||||
AS_IF([test x"${cf_with_lua_binding}" = "xyes"],[
|
||||
|
||||
AX_PROG_LUA([5.2], [5.4])
|
||||
AX_LUA_HEADERS
|
||||
AX_LUA_LIBS
|
||||
|
||||
BINDING_LIST="${BINDING_LIST} lua"
|
||||
BINDING_ALL="${BINDING_ALL} all-lua"
|
||||
BINDING_CHECK="${BINDING_CHECK} check-lua"
|
||||
BINDING_CLEAN="${BINDING_CLEAN} clean-lua"
|
||||
BINDING_DISTCLEAN="${BINDING_DISTCLEAN} distclean-lua"
|
||||
BINDING_INSTALL_EXEC="${BINDING_INSTALL_EXEC} install-lua"
|
||||
BINDING_UNINSTALL="${BINDING_UNINSTALL} uninstall-lua"
|
||||
BINDING_LIB_TARGETS="${BINDING_LIB_TARGETS} \$(lua_ltlib)"])
|
||||
|
||||
AM_CONDITIONAL([ENABLE_LUA], [test x"${cf_with_lua_binding}" = "xyes"])
|
||||
|
||||
dnl Only search for Swig if one or more bindings are enabled.
|
||||
AS_IF([test "x${BINDING_ALL}" != "x"],
|
||||
|
@ -761,6 +788,7 @@ echo \
|
|||
With Perl binding ${cf_with_perl_binding}
|
||||
With Python binding ${cf_with_python_binding}
|
||||
With TCL binding ${build_tcl}
|
||||
With Lua binding ${cf_with_lua_binding}
|
||||
With rigmem XML support ${cf_with_xml_support}
|
||||
With Readline support ${cf_with_readline_support}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ capability.
|
|||
Other devices, such as antenna rotors, can be placed into the Hamlib
|
||||
control scheme. Other recent developments include network interface
|
||||
servers and a USB interface capability. Language bindings are provided
|
||||
for C, C++, Perl, Python, and TCL (more to come).
|
||||
for C, C++, Perl, Python, Lua and TCL (more to come).
|
||||
|
||||
@menu
|
||||
* Overview::
|
||||
|
@ -79,10 +79,10 @@ of Hamlib's design.
|
|||
@cindex Interface, languages
|
||||
Hamlib also provides an interface library for each of several common
|
||||
@dfn{scripting} languages such as @url{http://www.perl.org, Perl, Perl},
|
||||
@url{http://www.python.org, Python, Python}, and @url{http://www.tcl.tk,
|
||||
TCL, TCL}. These language @dfn{bindings} are generated through the use
|
||||
of @url{http://www.swig.org, SWIG, SWIG} a parser/generator for multiple
|
||||
language interfaces to a C library. A native generated @emph{C++}
|
||||
@url{http://www.python.org, Python, Python}, @url{https://www.lua.org, Lua, Lua}
|
||||
and @url{http://www.tcl.tk, TCL, TCL}. These language @dfn{bindings} are
|
||||
generated through the use of @url{http://www.swig.org, SWIG, SWIG} a parser/generator
|
||||
for multiple language interfaces to a C library. A native generated @emph{C++}
|
||||
language interface is also provided.
|
||||
|
||||
@cindex Daemon, network
|
||||
|
|
|
@ -0,0 +1,664 @@
|
|||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_lua.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_PROG_LUA[([MINIMUM-VERSION], [TOO-BIG-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
|
||||
# AX_LUA_HEADERS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
|
||||
# AX_LUA_LIBS[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
|
||||
# AX_LUA_READLINE[([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])]
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Detect a Lua interpreter, optionally specifying a minimum and maximum
|
||||
# version number. Set up important Lua paths, such as the directories in
|
||||
# which to install scripts and modules (shared libraries).
|
||||
#
|
||||
# Also detect Lua headers and libraries. The Lua version contained in the
|
||||
# header is checked to match the Lua interpreter version exactly. When
|
||||
# searching for Lua libraries, the version number is used as a suffix.
|
||||
# This is done with the goal of supporting multiple Lua installs (5.1,
|
||||
# 5.2, and 5.3 side-by-side).
|
||||
#
|
||||
# A note on compatibility with previous versions: This file has been
|
||||
# mostly rewritten for serial 18. Most developers should be able to use
|
||||
# these macros without needing to modify configure.ac. Care has been taken
|
||||
# to preserve each macro's behavior, but there are some differences:
|
||||
#
|
||||
# 1) AX_WITH_LUA is deprecated; it now expands to the exact same thing as
|
||||
# AX_PROG_LUA with no arguments.
|
||||
#
|
||||
# 2) AX_LUA_HEADERS now checks that the version number defined in lua.h
|
||||
# matches the interpreter version. AX_LUA_HEADERS_VERSION is therefore
|
||||
# unnecessary, so it is deprecated and does not expand to anything.
|
||||
#
|
||||
# 3) The configure flag --with-lua-suffix no longer exists; the user
|
||||
# should instead specify the LUA precious variable on the command line.
|
||||
# See the AX_PROG_LUA description for details.
|
||||
#
|
||||
# Please read the macro descriptions below for more information.
|
||||
#
|
||||
# This file was inspired by Andrew Dalke's and James Henstridge's
|
||||
# python.m4 and Tom Payne's, Matthieu Moy's, and Reuben Thomas's ax_lua.m4
|
||||
# (serial 17). Basically, this file is a mash-up of those two files. I
|
||||
# like to think it combines the best of the two!
|
||||
#
|
||||
# AX_PROG_LUA: Search for the Lua interpreter, and set up important Lua
|
||||
# paths. Adds precious variable LUA, which may contain the path of the Lua
|
||||
# interpreter. If LUA is blank, the user's path is searched for an
|
||||
# suitable interpreter.
|
||||
#
|
||||
# If MINIMUM-VERSION is supplied, then only Lua interpreters with a
|
||||
# version number greater or equal to MINIMUM-VERSION will be accepted. If
|
||||
# TOO-BIG-VERSION is also supplied, then only Lua interpreters with a
|
||||
# version number greater or equal to MINIMUM-VERSION and less than
|
||||
# TOO-BIG-VERSION will be accepted.
|
||||
#
|
||||
# The Lua version number, LUA_VERSION, is found from the interpreter, and
|
||||
# substituted. LUA_PLATFORM is also found, but not currently supported (no
|
||||
# standard representation).
|
||||
#
|
||||
# Finally, the macro finds four paths:
|
||||
#
|
||||
# luadir Directory to install Lua scripts.
|
||||
# pkgluadir $luadir/$PACKAGE
|
||||
# luaexecdir Directory to install Lua modules.
|
||||
# pkgluaexecdir $luaexecdir/$PACKAGE
|
||||
#
|
||||
# These paths are found based on $prefix, $exec_prefix, Lua's
|
||||
# package.path, and package.cpath. The first path of package.path
|
||||
# beginning with $prefix is selected as luadir. The first path of
|
||||
# package.cpath beginning with $exec_prefix is used as luaexecdir. This
|
||||
# should work on all reasonable Lua installations. If a path cannot be
|
||||
# determined, a default path is used. Of course, the user can override
|
||||
# these later when invoking make.
|
||||
#
|
||||
# luadir Default: $prefix/share/lua/$LUA_VERSION
|
||||
# luaexecdir Default: $exec_prefix/lib/lua/$LUA_VERSION
|
||||
#
|
||||
# These directories can be used by Automake as install destinations. The
|
||||
# variable name minus 'dir' needs to be used as a prefix to the
|
||||
# appropriate Automake primary, e.g. lua_SCRIPS or luaexec_LIBRARIES.
|
||||
#
|
||||
# If an acceptable Lua interpreter is found, then ACTION-IF-FOUND is
|
||||
# performed, otherwise ACTION-IF-NOT-FOUND is preformed. If ACTION-IF-NOT-
|
||||
# FOUND is blank, then it will default to printing an error. To prevent
|
||||
# the default behavior, give ':' as an action.
|
||||
#
|
||||
# AX_LUA_HEADERS: Search for Lua headers. Requires that AX_PROG_LUA be
|
||||
# expanded before this macro. Adds precious variable LUA_INCLUDE, which
|
||||
# may contain Lua specific include flags, e.g. -I/usr/include/lua5.1. If
|
||||
# LUA_INCLUDE is blank, then this macro will attempt to find suitable
|
||||
# flags.
|
||||
#
|
||||
# LUA_INCLUDE can be used by Automake to compile Lua modules or
|
||||
# executables with embedded interpreters. The *_CPPFLAGS variables should
|
||||
# be used for this purpose, e.g. myprog_CPPFLAGS = $(LUA_INCLUDE).
|
||||
#
|
||||
# This macro searches for the header lua.h (and others). The search is
|
||||
# performed with a combination of CPPFLAGS, CPATH, etc, and LUA_INCLUDE.
|
||||
# If the search is unsuccessful, then some common directories are tried.
|
||||
# If the headers are then found, then LUA_INCLUDE is set accordingly.
|
||||
#
|
||||
# The paths automatically searched are:
|
||||
#
|
||||
# * /usr/include/luaX.Y
|
||||
# * /usr/include/lua/X.Y
|
||||
# * /usr/include/luaXY
|
||||
# * /usr/local/include/luaX.Y
|
||||
# * /usr/local/include/lua-X.Y
|
||||
# * /usr/local/include/lua/X.Y
|
||||
# * /usr/local/include/luaXY
|
||||
#
|
||||
# (Where X.Y is the Lua version number, e.g. 5.1.)
|
||||
#
|
||||
# The Lua version number found in the headers is always checked to match
|
||||
# the Lua interpreter's version number. Lua headers with mismatched
|
||||
# version numbers are not accepted.
|
||||
#
|
||||
# If headers are found, then ACTION-IF-FOUND is performed, otherwise
|
||||
# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
|
||||
# it will default to printing an error. To prevent the default behavior,
|
||||
# set the action to ':'.
|
||||
#
|
||||
# AX_LUA_LIBS: Search for Lua libraries. Requires that AX_PROG_LUA be
|
||||
# expanded before this macro. Adds precious variable LUA_LIB, which may
|
||||
# contain Lua specific linker flags, e.g. -llua5.1. If LUA_LIB is blank,
|
||||
# then this macro will attempt to find suitable flags.
|
||||
#
|
||||
# LUA_LIB can be used by Automake to link Lua modules or executables with
|
||||
# embedded interpreters. The *_LIBADD and *_LDADD variables should be used
|
||||
# for this purpose, e.g. mymod_LIBADD = $(LUA_LIB).
|
||||
#
|
||||
# This macro searches for the Lua library. More technically, it searches
|
||||
# for a library containing the function lua_load. The search is performed
|
||||
# with a combination of LIBS, LIBRARY_PATH, and LUA_LIB.
|
||||
#
|
||||
# If the search determines that some linker flags are missing, then those
|
||||
# flags will be added to LUA_LIB.
|
||||
#
|
||||
# If libraries are found, then ACTION-IF-FOUND is performed, otherwise
|
||||
# ACTION-IF-NOT-FOUND is performed. If ACTION-IF-NOT-FOUND is blank, then
|
||||
# it will default to printing an error. To prevent the default behavior,
|
||||
# set the action to ':'.
|
||||
#
|
||||
# AX_LUA_READLINE: Search for readline headers and libraries. Requires the
|
||||
# AX_LIB_READLINE macro, which is provided by ax_lib_readline.m4 from the
|
||||
# Autoconf Archive.
|
||||
#
|
||||
# If a readline compatible library is found, then ACTION-IF-FOUND is
|
||||
# performed, otherwise ACTION-IF-NOT-FOUND is performed.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2015 Reuben Thomas <rrt@sc3d.org>
|
||||
# Copyright (c) 2014 Tim Perkins <tprk77@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation, either version 3 of the License, or (at your
|
||||
# option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 39
|
||||
|
||||
dnl =========================================================================
|
||||
dnl AX_PROG_LUA([MINIMUM-VERSION], [TOO-BIG-VERSION],
|
||||
dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([AX_PROG_LUA],
|
||||
[
|
||||
dnl Check for required tools.
|
||||
AC_REQUIRE([AC_PROG_GREP])
|
||||
AC_REQUIRE([AC_PROG_SED])
|
||||
|
||||
dnl Make LUA a precious variable.
|
||||
AC_ARG_VAR([LUA], [The Lua interpreter, e.g. /usr/bin/lua5.1])
|
||||
|
||||
dnl Find a Lua interpreter.
|
||||
m4_define_default([_AX_LUA_INTERPRETER_LIST],
|
||||
[lua lua5.3 lua53 lua5.2 lua52 lua5.1 lua51 lua50])
|
||||
|
||||
m4_if([$1], [],
|
||||
[ dnl No version check is needed. Find any Lua interpreter.
|
||||
AS_IF([test "x$LUA" = 'x'],
|
||||
[AC_PATH_PROGS([LUA], [_AX_LUA_INTERPRETER_LIST], [:])])
|
||||
ax_display_LUA='lua'
|
||||
|
||||
AS_IF([test "x$LUA" != 'x:'],
|
||||
[ dnl At least check if this is a Lua interpreter.
|
||||
AC_MSG_CHECKING([if $LUA is a Lua interpreter])
|
||||
_AX_LUA_CHK_IS_INTRP([$LUA],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([not a Lua interpreter])
|
||||
])
|
||||
])
|
||||
],
|
||||
[ dnl A version check is needed.
|
||||
AS_IF([test "x$LUA" != 'x'],
|
||||
[ dnl Check if this is a Lua interpreter.
|
||||
AC_MSG_CHECKING([if $LUA is a Lua interpreter])
|
||||
_AX_LUA_CHK_IS_INTRP([$LUA],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([not a Lua interpreter])
|
||||
])
|
||||
dnl Check the version.
|
||||
m4_if([$2], [],
|
||||
[_ax_check_text="whether $LUA version >= $1"],
|
||||
[_ax_check_text="whether $LUA version >= $1, < $2"])
|
||||
AC_MSG_CHECKING([$_ax_check_text])
|
||||
_AX_LUA_CHK_VER([$LUA], [$1], [$2],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([version is out of range for specified LUA])])
|
||||
ax_display_LUA=$LUA
|
||||
],
|
||||
[ dnl Try each interpreter until we find one that satisfies VERSION.
|
||||
m4_if([$2], [],
|
||||
[_ax_check_text="for a Lua interpreter with version >= $1"],
|
||||
[_ax_check_text="for a Lua interpreter with version >= $1, < $2"])
|
||||
AC_CACHE_CHECK([$_ax_check_text],
|
||||
[ax_cv_pathless_LUA],
|
||||
[ for ax_cv_pathless_LUA in _AX_LUA_INTERPRETER_LIST none; do
|
||||
test "x$ax_cv_pathless_LUA" = 'xnone' && break
|
||||
_AX_LUA_CHK_IS_INTRP([$ax_cv_pathless_LUA], [], [continue])
|
||||
_AX_LUA_CHK_VER([$ax_cv_pathless_LUA], [$1], [$2], [break])
|
||||
done
|
||||
])
|
||||
dnl Set $LUA to the absolute path of $ax_cv_pathless_LUA.
|
||||
AS_IF([test "x$ax_cv_pathless_LUA" = 'xnone'],
|
||||
[LUA=':'],
|
||||
[AC_PATH_PROG([LUA], [$ax_cv_pathless_LUA])])
|
||||
ax_display_LUA=$ax_cv_pathless_LUA
|
||||
])
|
||||
])
|
||||
|
||||
AS_IF([test "x$LUA" = 'x:'],
|
||||
[ dnl Run any user-specified action, or abort.
|
||||
m4_default([$4], [AC_MSG_ERROR([cannot find suitable Lua interpreter])])
|
||||
],
|
||||
[ dnl Query Lua for its version number.
|
||||
AC_CACHE_CHECK([for $ax_display_LUA version],
|
||||
[ax_cv_lua_version],
|
||||
[ dnl Get the interpreter version in X.Y format. This should work for
|
||||
dnl interpreters version 5.0 and beyond.
|
||||
ax_cv_lua_version=[`$LUA -e '
|
||||
-- return a version number in X.Y format
|
||||
local _, _, ver = string.find(_VERSION, "^Lua (%d+%.%d+)")
|
||||
print(ver)'`]
|
||||
])
|
||||
AS_IF([test "x$ax_cv_lua_version" = 'x'],
|
||||
[AC_MSG_ERROR([invalid Lua version number])])
|
||||
AC_SUBST([LUA_VERSION], [$ax_cv_lua_version])
|
||||
AC_SUBST([LUA_SHORT_VERSION], [`echo "$LUA_VERSION" | $SED 's|\.||'`])
|
||||
|
||||
dnl The following check is not supported:
|
||||
dnl At times (like when building shared libraries) you may want to know
|
||||
dnl which OS platform Lua thinks this is.
|
||||
AC_CACHE_CHECK([for $ax_display_LUA platform],
|
||||
[ax_cv_lua_platform],
|
||||
[ax_cv_lua_platform=[`$LUA -e 'print("unknown")'`]])
|
||||
AC_SUBST([LUA_PLATFORM], [$ax_cv_lua_platform])
|
||||
|
||||
dnl Use the values of $prefix and $exec_prefix for the corresponding
|
||||
dnl values of LUA_PREFIX and LUA_EXEC_PREFIX. These are made distinct
|
||||
dnl variables so they can be overridden if need be. However, the general
|
||||
dnl consensus is that you shouldn't need this ability.
|
||||
AC_SUBST([LUA_PREFIX], ['${prefix}'])
|
||||
AC_SUBST([LUA_EXEC_PREFIX], ['${exec_prefix}'])
|
||||
|
||||
dnl Lua provides no way to query the script directory, and instead
|
||||
dnl provides LUA_PATH. However, we should be able to make a safe educated
|
||||
dnl guess. If the built-in search path contains a directory which is
|
||||
dnl prefixed by $prefix, then we can store scripts there. The first
|
||||
dnl matching path will be used.
|
||||
AC_CACHE_CHECK([for $ax_display_LUA script directory],
|
||||
[ax_cv_lua_luadir],
|
||||
[ AS_IF([test "x$prefix" = 'xNONE'],
|
||||
[ax_lua_prefix=$ac_default_prefix],
|
||||
[ax_lua_prefix=$prefix])
|
||||
|
||||
dnl Initialize to the default path.
|
||||
ax_cv_lua_luadir="$LUA_PREFIX/share/lua/$LUA_VERSION"
|
||||
|
||||
dnl Try to find a path with the prefix.
|
||||
_AX_LUA_FND_PRFX_PTH([$LUA], [$ax_lua_prefix], [script])
|
||||
AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
|
||||
[ dnl Fix the prefix.
|
||||
_ax_strip_prefix=`echo "$ax_lua_prefix" | $SED 's|.|.|g'`
|
||||
ax_cv_lua_luadir=`echo "$ax_lua_prefixed_path" | \
|
||||
$SED "s|^$_ax_strip_prefix|$LUA_PREFIX|"`
|
||||
])
|
||||
])
|
||||
AC_SUBST([luadir], [$ax_cv_lua_luadir])
|
||||
AC_SUBST([pkgluadir], [\${luadir}/$PACKAGE])
|
||||
|
||||
dnl Lua provides no way to query the module directory, and instead
|
||||
dnl provides LUA_PATH. However, we should be able to make a safe educated
|
||||
dnl guess. If the built-in search path contains a directory which is
|
||||
dnl prefixed by $exec_prefix, then we can store modules there. The first
|
||||
dnl matching path will be used.
|
||||
AC_CACHE_CHECK([for $ax_display_LUA module directory],
|
||||
[ax_cv_lua_luaexecdir],
|
||||
[ AS_IF([test "x$exec_prefix" = 'xNONE'],
|
||||
[ax_lua_exec_prefix=$ax_lua_prefix],
|
||||
[ax_lua_exec_prefix=$exec_prefix])
|
||||
|
||||
dnl Initialize to the default path.
|
||||
ax_cv_lua_luaexecdir="$LUA_EXEC_PREFIX/lib/lua/$LUA_VERSION"
|
||||
|
||||
dnl Try to find a path with the prefix.
|
||||
_AX_LUA_FND_PRFX_PTH([$LUA],
|
||||
[$ax_lua_exec_prefix], [module])
|
||||
AS_IF([test "x$ax_lua_prefixed_path" != 'x'],
|
||||
[ dnl Fix the prefix.
|
||||
_ax_strip_prefix=`echo "$ax_lua_exec_prefix" | $SED 's|.|.|g'`
|
||||
ax_cv_lua_luaexecdir=`echo "$ax_lua_prefixed_path" | \
|
||||
$SED "s|^$_ax_strip_prefix|$LUA_EXEC_PREFIX|"`
|
||||
])
|
||||
])
|
||||
AC_SUBST([luaexecdir], [$ax_cv_lua_luaexecdir])
|
||||
AC_SUBST([pkgluaexecdir], [\${luaexecdir}/$PACKAGE])
|
||||
|
||||
dnl Run any user specified action.
|
||||
$3
|
||||
])
|
||||
])
|
||||
|
||||
dnl AX_WITH_LUA is now the same thing as AX_PROG_LUA.
|
||||
AC_DEFUN([AX_WITH_LUA],
|
||||
[
|
||||
AC_MSG_WARN([[$0 is deprecated, please use AX_PROG_LUA instead]])
|
||||
AX_PROG_LUA
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl _AX_LUA_CHK_IS_INTRP(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([_AX_LUA_CHK_IS_INTRP],
|
||||
[
|
||||
dnl A minimal Lua factorial to prove this is an interpreter. This should work
|
||||
dnl for Lua interpreters version 5.0 and beyond.
|
||||
_ax_lua_factorial=[`$1 2>/dev/null -e '
|
||||
-- a simple factorial
|
||||
function fact (n)
|
||||
if n == 0 then
|
||||
return 1
|
||||
else
|
||||
return n * fact(n-1)
|
||||
end
|
||||
end
|
||||
print("fact(5) is " .. fact(5))'`]
|
||||
AS_IF([test "$_ax_lua_factorial" = 'fact(5) is 120'],
|
||||
[$2], [$3])
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl _AX_LUA_CHK_VER(PROG, MINIMUM-VERSION, [TOO-BIG-VERSION],
|
||||
dnl [ACTION-IF-TRUE], [ACTION-IF-FALSE])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([_AX_LUA_CHK_VER],
|
||||
[
|
||||
dnl Check that the Lua version is within the bounds. Only the major and minor
|
||||
dnl version numbers are considered. This should work for Lua interpreters
|
||||
dnl version 5.0 and beyond.
|
||||
_ax_lua_good_version=[`$1 -e '
|
||||
-- a script to compare versions
|
||||
function verstr2num(verstr)
|
||||
local _, _, majorver, minorver = string.find(verstr, "^(%d+)%.(%d+)")
|
||||
if majorver and minorver then
|
||||
return tonumber(majorver) * 100 + tonumber(minorver)
|
||||
end
|
||||
end
|
||||
local minver = verstr2num("$2")
|
||||
local _, _, trimver = string.find(_VERSION, "^Lua (.*)")
|
||||
local ver = verstr2num(trimver)
|
||||
local maxver = verstr2num("$3") or 1e9
|
||||
if minver <= ver and ver < maxver then
|
||||
print("yes")
|
||||
else
|
||||
print("no")
|
||||
end'`]
|
||||
AS_IF([test "x$_ax_lua_good_version" = "xyes"],
|
||||
[$4], [$5])
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl _AX_LUA_FND_PRFX_PTH(PROG, PREFIX, SCRIPT-OR-MODULE-DIR)
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([_AX_LUA_FND_PRFX_PTH],
|
||||
[
|
||||
dnl Get the script or module directory by querying the Lua interpreter,
|
||||
dnl filtering on the given prefix, and selecting the shallowest path. If no
|
||||
dnl path is found matching the prefix, the result will be an empty string.
|
||||
dnl The third argument determines the type of search, it can be 'script' or
|
||||
dnl 'module'. Supplying 'script' will perform the search with package.path
|
||||
dnl and LUA_PATH, and supplying 'module' will search with package.cpath and
|
||||
dnl LUA_CPATH. This is done for compatibility with Lua 5.0.
|
||||
|
||||
ax_lua_prefixed_path=[`$1 -e '
|
||||
-- get the path based on search type
|
||||
local searchtype = "$3"
|
||||
local paths = ""
|
||||
if searchtype == "script" then
|
||||
paths = (package and package.path) or LUA_PATH
|
||||
elseif searchtype == "module" then
|
||||
paths = (package and package.cpath) or LUA_CPATH
|
||||
end
|
||||
-- search for the prefix
|
||||
local prefix = "'$2'"
|
||||
local minpath = ""
|
||||
local mindepth = 1e9
|
||||
string.gsub(paths, "(@<:@^;@:>@+)",
|
||||
function (path)
|
||||
path = string.gsub(path, "%?.*$", "")
|
||||
path = string.gsub(path, "/@<:@^/@:>@*$", "")
|
||||
if string.find(path, prefix) then
|
||||
local depth = string.len(string.gsub(path, "@<:@^/@:>@", ""))
|
||||
if depth < mindepth then
|
||||
minpath = path
|
||||
mindepth = depth
|
||||
end
|
||||
end
|
||||
end)
|
||||
print(minpath)'`]
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl AX_LUA_HEADERS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([AX_LUA_HEADERS],
|
||||
[
|
||||
dnl Check for LUA_VERSION.
|
||||
AC_MSG_CHECKING([if LUA_VERSION is defined])
|
||||
AS_IF([test "x$LUA_VERSION" != 'x'],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot check Lua headers without knowing LUA_VERSION])
|
||||
])
|
||||
|
||||
dnl Make LUA_INCLUDE a precious variable.
|
||||
AC_ARG_VAR([LUA_INCLUDE], [The Lua includes, e.g. -I/usr/include/lua5.1])
|
||||
|
||||
dnl Some default directories to search.
|
||||
LUA_SHORT_VERSION=`echo "$LUA_VERSION" | $SED 's|\.||'`
|
||||
m4_define_default([_AX_LUA_INCLUDE_LIST],
|
||||
[ /usr/include/lua$LUA_VERSION \
|
||||
/usr/include/lua-$LUA_VERSION \
|
||||
/usr/include/lua/$LUA_VERSION \
|
||||
/usr/include/lua$LUA_SHORT_VERSION \
|
||||
/usr/local/include/lua$LUA_VERSION \
|
||||
/usr/local/include/lua-$LUA_VERSION \
|
||||
/usr/local/include/lua/$LUA_VERSION \
|
||||
/usr/local/include/lua$LUA_SHORT_VERSION \
|
||||
])
|
||||
|
||||
dnl Try to find the headers.
|
||||
_ax_lua_saved_cppflags=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
|
||||
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
|
||||
CPPFLAGS=$_ax_lua_saved_cppflags
|
||||
|
||||
dnl Try some other directories if LUA_INCLUDE was not set.
|
||||
AS_IF([test "x$LUA_INCLUDE" = 'x' &&
|
||||
test "x$ac_cv_header_lua_h" != 'xyes'],
|
||||
[ dnl Try some common include paths.
|
||||
for _ax_include_path in _AX_LUA_INCLUDE_LIST; do
|
||||
test ! -d "$_ax_include_path" && continue
|
||||
|
||||
AC_MSG_CHECKING([for Lua headers in])
|
||||
AC_MSG_RESULT([$_ax_include_path])
|
||||
|
||||
AS_UNSET([ac_cv_header_lua_h])
|
||||
AS_UNSET([ac_cv_header_lualib_h])
|
||||
AS_UNSET([ac_cv_header_lauxlib_h])
|
||||
AS_UNSET([ac_cv_header_luaconf_h])
|
||||
|
||||
_ax_lua_saved_cppflags=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS -I$_ax_include_path"
|
||||
AC_CHECK_HEADERS([lua.h lualib.h lauxlib.h luaconf.h])
|
||||
CPPFLAGS=$_ax_lua_saved_cppflags
|
||||
|
||||
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
|
||||
[ LUA_INCLUDE="-I$_ax_include_path"
|
||||
break
|
||||
])
|
||||
done
|
||||
])
|
||||
|
||||
AS_IF([test "x$ac_cv_header_lua_h" = 'xyes'],
|
||||
[ dnl Make a program to print LUA_VERSION defined in the header.
|
||||
dnl TODO It would be really nice if we could do this without compiling a
|
||||
dnl program, then it would work when cross compiling. But I'm not sure how
|
||||
dnl to do this reliably. For now, assume versions match when cross compiling.
|
||||
|
||||
AS_IF([test "x$cross_compiling" != 'xyes'],
|
||||
[ AC_CACHE_CHECK([for Lua header version],
|
||||
[ax_cv_lua_header_version],
|
||||
[ _ax_lua_saved_cppflags=$CPPFLAGS
|
||||
CPPFLAGS="$CPPFLAGS $LUA_INCLUDE"
|
||||
AC_RUN_IFELSE(
|
||||
[ AC_LANG_SOURCE([[
|
||||
#include <lua.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
if(argc > 1) printf("%s", LUA_VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
]])
|
||||
],
|
||||
[ ax_cv_lua_header_version=`./conftest$EXEEXT p | \
|
||||
$SED -n "s|^Lua \(@<:@0-9@:>@\{1,\}\.@<:@0-9@:>@\{1,\}\).\{0,\}|\1|p"`
|
||||
],
|
||||
[ax_cv_lua_header_version='unknown'])
|
||||
CPPFLAGS=$_ax_lua_saved_cppflags
|
||||
])
|
||||
|
||||
dnl Compare this to the previously found LUA_VERSION.
|
||||
AC_MSG_CHECKING([if Lua header version matches $LUA_VERSION])
|
||||
AS_IF([test "x$ax_cv_lua_header_version" = "x$LUA_VERSION"],
|
||||
[ AC_MSG_RESULT([yes])
|
||||
ax_header_version_match='yes'
|
||||
],
|
||||
[ AC_MSG_RESULT([no])
|
||||
ax_header_version_match='no'
|
||||
])
|
||||
],
|
||||
[ AC_MSG_WARN([cross compiling so assuming header version number matches])
|
||||
ax_header_version_match='yes'
|
||||
])
|
||||
])
|
||||
|
||||
dnl Was LUA_INCLUDE specified?
|
||||
AS_IF([test "x$ax_header_version_match" != 'xyes' &&
|
||||
test "x$LUA_INCLUDE" != 'x'],
|
||||
[AC_MSG_ERROR([cannot find headers for specified LUA_INCLUDE])])
|
||||
|
||||
dnl Test the final result and run user code.
|
||||
AS_IF([test "x$ax_header_version_match" = 'xyes'], [$1],
|
||||
[m4_default([$2], [AC_MSG_ERROR([cannot find Lua includes])])])
|
||||
])
|
||||
|
||||
dnl AX_LUA_HEADERS_VERSION no longer exists, use AX_LUA_HEADERS.
|
||||
AC_DEFUN([AX_LUA_HEADERS_VERSION],
|
||||
[
|
||||
AC_MSG_WARN([[$0 is deprecated, please use AX_LUA_HEADERS instead]])
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl AX_LUA_LIBS([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([AX_LUA_LIBS],
|
||||
[
|
||||
dnl TODO Should this macro also check various -L flags?
|
||||
|
||||
dnl Check for LUA_VERSION.
|
||||
AC_MSG_CHECKING([if LUA_VERSION is defined])
|
||||
AS_IF([test "x$LUA_VERSION" != 'x'],
|
||||
[AC_MSG_RESULT([yes])],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([cannot check Lua libs without knowing LUA_VERSION])
|
||||
])
|
||||
|
||||
dnl Make LUA_LIB a precious variable.
|
||||
AC_ARG_VAR([LUA_LIB], [The Lua library, e.g. -llua5.1])
|
||||
|
||||
AS_IF([test "x$LUA_LIB" != 'x'],
|
||||
[ dnl Check that LUA_LIBS works.
|
||||
_ax_lua_saved_libs=$LIBS
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
AC_SEARCH_LIBS([lua_load], [],
|
||||
[_ax_found_lua_libs='yes'],
|
||||
[_ax_found_lua_libs='no'])
|
||||
LIBS=$_ax_lua_saved_libs
|
||||
|
||||
dnl Check the result.
|
||||
AS_IF([test "x$_ax_found_lua_libs" != 'xyes'],
|
||||
[AC_MSG_ERROR([cannot find libs for specified LUA_LIB])])
|
||||
],
|
||||
[ dnl First search for extra libs.
|
||||
_ax_lua_extra_libs=''
|
||||
|
||||
_ax_lua_saved_libs=$LIBS
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
AC_SEARCH_LIBS([exp], [m])
|
||||
AC_SEARCH_LIBS([dlopen], [dl])
|
||||
LIBS=$_ax_lua_saved_libs
|
||||
|
||||
AS_IF([test "x$ac_cv_search_exp" != 'xno' &&
|
||||
test "x$ac_cv_search_exp" != 'xnone required'],
|
||||
[_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_exp"])
|
||||
|
||||
AS_IF([test "x$ac_cv_search_dlopen" != 'xno' &&
|
||||
test "x$ac_cv_search_dlopen" != 'xnone required'],
|
||||
[_ax_lua_extra_libs="$_ax_lua_extra_libs $ac_cv_search_dlopen"])
|
||||
|
||||
dnl Try to find the Lua libs.
|
||||
_ax_lua_saved_libs=$LIBS
|
||||
LIBS="$LIBS $LUA_LIB"
|
||||
AC_SEARCH_LIBS([lua_load],
|
||||
[ lua$LUA_VERSION \
|
||||
lua$LUA_SHORT_VERSION \
|
||||
lua-$LUA_VERSION \
|
||||
lua-$LUA_SHORT_VERSION \
|
||||
lua \
|
||||
],
|
||||
[_ax_found_lua_libs='yes'],
|
||||
[_ax_found_lua_libs='no'],
|
||||
[$_ax_lua_extra_libs])
|
||||
LIBS=$_ax_lua_saved_libs
|
||||
|
||||
AS_IF([test "x$ac_cv_search_lua_load" != 'xno' &&
|
||||
test "x$ac_cv_search_lua_load" != 'xnone required'],
|
||||
[LUA_LIB="$ac_cv_search_lua_load $_ax_lua_extra_libs"])
|
||||
])
|
||||
|
||||
dnl Test the result and run user code.
|
||||
AS_IF([test "x$_ax_found_lua_libs" = 'xyes'], [$1],
|
||||
[m4_default([$2], [AC_MSG_ERROR([cannot find Lua libs])])])
|
||||
])
|
||||
|
||||
|
||||
dnl =========================================================================
|
||||
dnl AX_LUA_READLINE([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl =========================================================================
|
||||
AC_DEFUN([AX_LUA_READLINE],
|
||||
[
|
||||
AX_LIB_READLINE
|
||||
AS_IF([test "x$ac_cv_header_readline_readline_h" != 'x' &&
|
||||
test "x$ac_cv_header_readline_history_h" != 'x'],
|
||||
[ LUA_LIBS_CFLAGS="-DLUA_USE_READLINE $LUA_LIBS_CFLAGS"
|
||||
$1
|
||||
],
|
||||
[$2])
|
||||
])
|
Ładowanie…
Reference in New Issue