From 4f9085f8f57a9b76af06852a6c1ca4d00fd4fd2b Mon Sep 17 00:00:00 2001 From: Nate Bargmann Date: Wed, 26 Jul 2017 06:33:42 -0500 Subject: [PATCH] Bindings tweaks for Python and TCL Remove execute bits for all test scripts and install them into doc/examples. Make sure check-py and check-tcl targets work. Set a conditional for Python3 or Python2 and install/test the correct script file. Use Makefile variables instead of configure substitutions wherever possible. Generate tcltest.tcl at make time to insert installation library path into the script so that tests pass. --- bindings/Makefile.am | 82 ++++++++++++++++-------- bindings/luatest.lua | 0 bindings/perltest.pl | 0 bindings/py3test.py | 0 bindings/pytest.py | 0 bindings/{tcltest.tcl => tcltest.tcl.in} | 4 +- configure.ac | 30 +++++---- 7 files changed, 75 insertions(+), 41 deletions(-) mode change 100755 => 100644 bindings/luatest.lua mode change 100755 => 100644 bindings/perltest.pl mode change 100755 => 100644 bindings/py3test.py mode change 100755 => 100644 bindings/pytest.py rename bindings/{tcltest.tcl => tcltest.tcl.in} (94%) mode change 100755 => 100644 diff --git a/bindings/Makefile.am b/bindings/Makefile.am index bf299b062..716686222 100644 --- a/bindings/Makefile.am +++ b/bindings/Makefile.am @@ -3,24 +3,29 @@ # more information on swig at http://www.swig.org # -AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/bindings $(PYTHON_CPPFLAGS) @TCL_INCLUDE_SPEC@ +AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/bindings $(PYTHON_CPPFLAGS) \ + $(TCL_INCLUDE_SPEC) AM_CFLAGS = -fno-strict-aliasing SWGFILES = hamlib.swg ignore.swg rig.swg rotator.swg -SWGDEP=$(top_srcdir)/include/hamlib/rig.h $(top_srcdir)/include/hamlib/riglist.h \ - $(top_srcdir)/include/hamlib/rotator.h $(top_srcdir)/include/hamlib/rotlist.h \ +SWGDEP = \ + $(top_srcdir)/include/hamlib/rig.h \ + $(top_srcdir)/include/hamlib/riglist.h \ + $(top_srcdir)/include/hamlib/rotator.h \ + $(top_srcdir)/include/hamlib/rotlist.h \ $(SWGFILES) EXTRA_DIST = $(SWGFILES) \ - Makefile.PL perltest.pl tcltest.tcl pytest.py py3test.py luatest.lua \ - README.python + Makefile.PL perltest.pl tcltest.tcl.in pytest.py py3test.py \ + luatest.lua README.python -noinst_SCRIPTS = perltest.pl tcltest.tcl pytest.py py3test.py hamlibvb.bas luatest.lua +exampledir = $(docdir)/examples +example_DATA = -BUILT_SOURCES= -MOSTLYCLEANFILES= +BUILT_SOURCES = +MOSTLYCLEANFILES = if ENABLE_PERL @@ -29,10 +34,11 @@ if ENABLE_PERL BUILT_SOURCES += hamlibperl_wrap.c MOSTLYCLEANFILES += hamlibperl_wrap.c Hamlib.pm Hamlib.bs Hamlib-pl.mk.old +example_DATA += perltest.pl hamlibperl_wrap.c: hamlib.swg $(SWIGDEP) - $(SWIG) -perl5 -shadow @AM_CPPFLAGS@ -I$(top_srcdir)/bindings -o $@ \ - `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg + $(SWIG) -perl5 -shadow $(AM_CPPFLAGS) -I$(top_srcdir)/bindings \ + -o $@ `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg Hamlib-pl.mk: $(srcdir)/Makefile.PL test -f Makefile.PL || $(LN_S) $(srcdir)/Makefile.PL Makefile.PL @@ -81,9 +87,19 @@ if ENABLE_PYTHON pyexec_ltlib = _Hamlib.la -MOSTLYCLEANFILES+= hamlibpy_wrap.c Hamlib.py *.pyc +MOSTLYCLEANFILES += hamlibpy_wrap.c Hamlib.py *.pyc BUILT_SOURCES += hamlibpy_wrap.c Hamlib.py +# Set by AM_CONDITIONAL in configure.ac +if PYVER_3 +pytest = py3test.py +else !PYVER_3 +pytest = pytest.py +endif +# PYVER_3 + +example_DATA += $(pytest) + nodist_pyexec_PYTHON = Hamlib.py nodist__Hamlib_la_SOURCES = hamlibpy_wrap.c @@ -95,13 +111,14 @@ _Hamlib_la_LTLIBRARIES = $(pyexec_ltlib) all-py: $(pyexec_ltlib) check-py: all-py - $(srcdir)/pytest.py || echo "Python test failed" 1>&2 + PYTHONPATH=$(builddir):$(builddir)/.libs $(PYTHON) $(srcdir)/$(pytest) \ + || echo "Python test failed" 1>&2 Hamlib.py: hamlibpy_wrap.c hamlibpy_wrap.c: hamlib.swg $(SWGDEP) $(SWIG) -python $(AM_CPPFLAGS) -I$(top_srcdir)/bindings \ - -o $@ `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg + -o $@ `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg install-py: clean-py: @@ -116,24 +133,26 @@ if ENABLE_TCL ########################################## # Tcl binding -BUILT_SOURCES+= hamlibtcl_wrap.c -MOSTLYCLEANFILES+= hamlibtcl_wrap.c pkgIndex.tcl +BUILT_SOURCES += hamlibtcl_wrap.c +MOSTLYCLEANFILES += hamlibtcl_wrap.c pkgIndex.tcl tcltest.tcl +example_DATA += tcltest.tcl tcl_ltlib = hamlibtcl.la -tcldir = $(libdir)/tcl/Hamlib +tcldir = $(libdir)/tcl$(TCL_VERSION)/Hamlib -PKG_VER=@ABI_VERSION@.@ABI_REVISION@ -DLL=hamlibtcl-$(PKG_VER)@TCL_SHLIB_SUFFIX@ +PKG_VER = $(ABI_VERSION).$(ABI_REVISION) +DLL = hamlibtcl-$(PKG_VER)$(TCL_SHLIB_SUFFIX) nodist_hamlibtcl_la_SOURCES = hamlibtcl_wrap.c -hamlibtcl_la_LDFLAGS = -no-undefined -module -release $(PKG_VER) -avoid-version @TCL_LIB_SPEC@ -hamlibtcl_la_LIBADD = $(top_builddir)/src/libhamlib.la +hamlibtcl_la_LDFLAGS = -no-undefined -module -release $(PKG_VER) -avoid-version +hamlibtcl_la_LIBADD = $(top_builddir)/src/libhamlib.la $(TCL_LIB_SPEC) hamlibtcl_ladir = $(tcldir) hamlibtcl_la_DATA = pkgIndex.tcl -# Install hamlibtcl.la into the tcltk/Hamlib directory set by $hamlibtcl_ladir +# Install hamlibtcl.la into the $(tcldir)/Hamlib directory +# set by $(hamlibtcl_ladir) hamlibtcl_la_LTLIBRARIES = $(tcl_ltlib) # Having the first occurance of 'hamlib' capitalized seemed to cause confusion @@ -142,13 +161,19 @@ pkgIndex.tcl: Makefile echo 'package ifneeded hamlib $(PKG_VER) [list load [file join $$dir $(DLL)] Hamlib]' > pkgIndex.tcl hamlibtcl_wrap.c: hamlib.swg $(SWGDEP) - $(SWIG) -tcl -pkgversion $(PKG_VER) @AM_CPPFLAGS@ -I$(top_srcdir)/bindings -o $@ \ - `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg + $(SWIG) -tcl -pkgversion $(PKG_VER) $(AM_CPPFLAGS) -I$(top_srcdir)/bindings \ + -o $@ `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg -all-tcl: pkgIndex.tcl $(tcl_ltlib) +do_subst = sed -e 's,[@]tcldir[@],$(tcldir),g' + +tcltest.tcl: tcltest.tcl.in Makefile + $(do_subst) < $(srcdir)/tcltest.tcl.in > tcltest.tcl + +all-tcl: pkgIndex.tcl $(tcl_ltlib) tcltest.tcl check-tcl: all-tcl - TCLLIBPATH=$(builddir)/.libs $(srcdir)/tcltest.tcl || echo "Tcl test failed" 1>&2 + TCLLIBPATH=$(builddir)/.libs tclsh $(builddir)/tcltest.tcl \ + || echo "Tcl test failed" 1>&2 install-tcl: clean-tcl: @@ -164,8 +189,9 @@ if ENABLE_LUA luaexec_ltlib = Hamliblua.la -MOSTLYCLEANFILES+= hamliblua_wrap.c +MOSTLYCLEANFILES += hamliblua_wrap.c BUILT_SOURCES += hamliblua_wrap.c +example_DATA += luatest.lua nodist_luaexec_LUA = Hamlib.lua nodist_Hamliblua_la_SOURCES = hamliblua_wrap.c @@ -184,8 +210,8 @@ check-lua: all-lua 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 + $(SWIG) -lua $(AM_CPPFLAGS) -I$(top_srcdir)/bindings \ + -o $@ `test -f hamlib.swg || echo '$(srcdir)/'`hamlib.swg install-lua: clean-lua: diff --git a/bindings/luatest.lua b/bindings/luatest.lua old mode 100755 new mode 100644 diff --git a/bindings/perltest.pl b/bindings/perltest.pl old mode 100755 new mode 100644 diff --git a/bindings/py3test.py b/bindings/py3test.py old mode 100755 new mode 100644 diff --git a/bindings/pytest.py b/bindings/pytest.py old mode 100755 new mode 100644 diff --git a/bindings/tcltest.tcl b/bindings/tcltest.tcl.in old mode 100755 new mode 100644 similarity index 94% rename from bindings/tcltest.tcl rename to bindings/tcltest.tcl.in index 722fe279d..f53a36afc --- a/bindings/tcltest.tcl +++ b/bindings/tcltest.tcl.in @@ -3,10 +3,10 @@ exec tclsh "$0" "$@" # Edit the path below to reflect installed Hamlib extension -lappend ::auto_path /usr/local/lib/tcl/Hamlib +lappend ::auto_path @tcldir@ ## Brute force loading -#load "/usr/local/lib/tcltk/Hamlib/hamlibtcl.so" Hamlib +#load "@tcldir@/hamlibtcl.so" Hamlib ## Preferred package loading package require hamlib diff --git a/configure.ac b/configure.ac index b0afeca9f..e0df18f91 100644 --- a/configure.ac +++ b/configure.ac @@ -457,10 +457,10 @@ BINDING_LIB_TARGETS="" dnl Check if cxx-binding not wanted, default is to build it # C++ binding -AC_MSG_CHECKING([whether to build C++ binding and demo]) +AC_MSG_CHECKING([whether to build C++ binding]) AC_ARG_WITH([cxx-binding], [AS_HELP_STRING([--without-cxx-binding], - [do not build C++ binding and demo @<:@default=yes@:>@])], + [do not build C++ binding @<:@default=yes@:>@])], [cf_with_cxx_binding=$withval], [cf_with_cxx_binding=$cf_with_cxx]) AC_MSG_RESULT([$cf_with_cxx_binding]) @@ -472,10 +472,10 @@ AS_IF([test x"${cf_with_cxx_binding}" = "xyes"], dnl Check if perl-binding is wanted, default is to not build it # Perl binding -AC_MSG_CHECKING([whether to build perl binding and demo]) +AC_MSG_CHECKING([whether to build perl binding]) AC_ARG_WITH([perl-binding], [AS_HELP_STRING([--with-perl-binding], - [build perl binding and demo @<:@default=no@:>@])], + [build perl binding @<:@default=no@:>@])], [cf_with_perl_binding=$withval], [cf_with_perl_binding=no]) AC_MSG_RESULT([$cf_with_perl_binding]) @@ -498,10 +498,10 @@ AM_CONDITIONAL([ENABLE_PERL], [test x"${cf_with_perl_binding}" = "xyes"]) dnl Check for python availability, so we can enable HamlibPy # Python bindings -AC_MSG_CHECKING([whether to build python binding and demo]) +AC_MSG_CHECKING([whether to build python binding]) AC_ARG_WITH([python-binding], [AS_HELP_STRING([--with-python-binding], - [build python binding and demo @<:@default=no@:>@])], + [build python binding @<:@default=no@:>@])], [cf_with_python_binding=$withval], [cf_with_python_binding=no]) AC_MSG_RESULT([$cf_with_python_binding]) @@ -523,18 +523,23 @@ AS_IF([test x"${cf_with_python_binding}" = "xyes"],[ AM_CONDITIONAL([ENABLE_PYTHON], [test x"${cf_with_python_binding}" = "xyes"]) +dnl Determine whether to install pytest.py or py3test.py to $(docdir)/examples +AM_PYTHON_CHECK_VERSION([${PYTHON}], [3.0], [pyver_3="yes"], [pyver_3="no"]) +AM_CONDITIONAL([PYVER_3], [test x"${pyver_3}" = x"yes"]) + # Tcl binding -AC_MSG_CHECKING([Whether to build Tcl bindings and demos]) +AC_MSG_CHECKING([Whether to build Tcl bindings]) AC_ARG_WITH([tcl-binding], [AS_HELP_STRING([--with-tcl-binding], - [build Tcl binding and demo @<:@default=no@:>@])], + [build Tcl binding @<:@default=no@:>@])], [build_tcl=$withval], [build_tcl=no]) AC_MSG_RESULT([$build_tcl]) dnl SC_PATH_TCLCONFIG and SC_LOAD_TCLCONFIG from macros/tcl.m4 AS_IF([test x"${build_tcl}" = "xyes"],[ + dnl Search for and load tclConfig.sh. SC_PATH_TCLCONFIG SC_LOAD_TCLCONFIG @@ -555,16 +560,19 @@ AS_IF([test x"${build_tcl}" = "xyes"],[ BINDING_LIB_TARGETS="${BINDING_LIB_TARGETS} \$(tcl_ltlib)"]) AM_CONDITIONAL([ENABLE_TCL], [test x"${build_tcl}" = "xyes"]) +dnl These variables are set once tclConfig.sh is loaded. +AC_SUBST([TCL_VERSION]) 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_MSG_CHECKING([whether to build lua binding]) AC_ARG_WITH([lua-binding], [AS_HELP_STRING([--with-lua-binding], - [build lua binding and demo @<:@default=no@:>@])], + [build lua binding @<:@default=no@:>@])], [cf_with_lua_binding=$withval], [cf_with_lua_binding=no]) AC_MSG_RESULT([$cf_with_lua_binding]) @@ -587,6 +595,7 @@ AS_IF([test x"${cf_with_lua_binding}" = "xyes"],[ 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"], [# macros/ax_pkg_swig.m4 @@ -749,7 +758,6 @@ sartek/Makefile src/Makefile c++/Makefile bindings/Makefile -bindings/hamlibvb.bas tests/Makefile doc/Makefile doc/hamlib.cfg