From faf44dc4217e89ca5b388ea2f5ca20361bee93d2 Mon Sep 17 00:00:00 2001 From: Daniel Salzman Date: Tue, 20 Nov 2018 16:33:07 +0100 Subject: [PATCH] python: improve libknot detection --- .gitignore | 3 +-- configure.ac | 8 +++++--- python/.gitignore | 2 ++ python/Makefile.am | 2 +- python/libknot/__init__.py | 1 - python/libknot/__init__.py.in | 3 +++ python/libknot/control.py | 12 +++++++++++- 7 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 python/.gitignore delete mode 100644 python/libknot/__init__.py create mode 100644 python/libknot/__init__.py.in diff --git a/.gitignore b/.gitignore index 4aad9342b..40c4fc2f2 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,6 @@ Makefile Makefile.in version.h -/python/setup.py /samples/knot.sample.conf /src/knot/modules/static_modules.h @@ -84,4 +83,4 @@ version.h # eclipse /.project /.cproject -/.settings/ \ No newline at end of file +/.settings/ diff --git a/configure.ac b/configure.ac index 30f688aba..391ce947b 100644 --- a/configure.ac +++ b/configure.ac @@ -21,9 +21,10 @@ AC_CANONICAL_HOST # Update library versions # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -AC_SUBST([libknot_VERSION_INFO],["-version-info 8:0:0"]) -AC_SUBST([libdnssec_VERSION_INFO],["-version-info 6:0:0"]) -AC_SUBST([libzscanner_VERSION_INFO],["-version-info 2:0:0"]) +AC_SUBST([python_libknot_VERSION], ["8"]) +AC_SUBST([libknot_VERSION_INFO], ["-version-info 8:0:0"]) +AC_SUBST([libdnssec_VERSION_INFO], ["-version-info 6:0:0"]) +AC_SUBST([libzscanner_VERSION_INFO], ["-version-info 2:0:0"]) AC_SUBST([KNOT_VERSION_MAJOR], knot_VERSION_MAJOR) AC_SUBST([KNOT_VERSION_MINOR], knot_VERSION_MINOR) @@ -701,6 +702,7 @@ AC_CONFIG_FILES([Makefile distro/Makefile python/Makefile python/setup.py + python/libknot/__init__.py src/Makefile src/knot/modules/static_modules.h ]) diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 000000000..6c6ff74f0 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,2 @@ +/libknot/__init__.py +/setup.py diff --git a/python/Makefile.am b/python/Makefile.am index c7db41739..629c2e41e 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -1,4 +1,4 @@ EXTRA_DIST = \ - libknot/__init__.py \ + libknot/__init__.py.in \ libknot/control.py \ setup.py.in diff --git a/python/libknot/__init__.py b/python/libknot/__init__.py deleted file mode 100644 index 73a2b107b..000000000 --- a/python/libknot/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Python libknot interface.""" diff --git a/python/libknot/__init__.py.in b/python/libknot/__init__.py.in new file mode 100644 index 000000000..a13b36945 --- /dev/null +++ b/python/libknot/__init__.py.in @@ -0,0 +1,3 @@ +"""Python libknot interface.""" + +LIBKNOT_VERSION = "@python_libknot_VERSION@" diff --git a/python/libknot/control.py b/python/libknot/control.py index 433ad3598..ced1be628 100644 --- a/python/libknot/control.py +++ b/python/libknot/control.py @@ -45,7 +45,17 @@ def load_lib(path=None): """Loads the libknot library.""" if path is None: - path = "libknot.dylib" if sys.platform == "darwin" else "libknot.so" + version = "" + try: + from libknot import LIBKNOT_VERSION + version = ".%u" % int(LIBKNOT_VERSION) + except: + pass + + if sys.platform == "darwin": + path = "libknot%s.dylib" % version + else: + path = "libknot.so%s" % version LIB = cdll.LoadLibrary(path) global CTL_ALLOC