diff --git a/configure.ac b/configure.ac
index 55c388eb..96df0598 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,6 +587,32 @@ AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
AC_SUBST(emacs_local_vars_end, ['End:'])
+# Bindings.
+AC_ARG_ENABLE([python],
+ AC_HELP_STRING([--enable-python],
+ [build the Python3 bindings]),
+ [enable_python=$enableval],
+ [enable_python=auto])
+AX_PKG_SWIG
+if test -z "$SWIG"; then
+ if test $enable_python = yes; then
+ die=yes
+ AC_MSG_NOTICE([[
+***
+*** You need SWIG to build the Python bindings.
+***]])
+ else
+ enable_python=no
+ fi
+else
+ if test $enable_python = auto; then
+ enable_python=yes
+ fi
+fi
+if test $enable_python = yes; then
+ AM_PATH_PYTHON([3.2])
+ AX_SWIG_PYTHON
+fi
# Last check.
die=no
@@ -632,7 +658,8 @@ AC_CONFIG_FILES(Makefile src/Makefile
src/versioninfo.rc
src/gpgme.h)
AC_CONFIG_FILES(src/gpgme-config, chmod +x src/gpgme-config)
-AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
+AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd
+ lang/python/Makefile])
AC_OUTPUT
echo "
@@ -644,6 +671,8 @@ echo "
UI Server: $uiserver
FD Passing: $use_descriptor_passing
GPGME Pthread: $have_pthread
+
+ Python bindings: $enable_python
"
if test "x${gpg_config_script_warn}" != x; then
cat <.
+
+EXTRA_DIST = README.rst
+
+# Cleanup gpgme.h from deprecated functions and typedefs.
+gpgme.h: ../../src/gpgme.h
+ $(PYTHON) $(srcdir)/gpgme-h-clean.py $< >$@
+
+# For VPATH builds we need to copy some files because Python's
+# distutils are not VPATH-aware.
+copystamp: $(srcdir)/pyme $(srcdir)/helpers.c $(srcdir)/helpers.h
+ if test "$(srcdir)" != "$(builddir)" ; then cp -a $^ . ; fi
+ touch $@
+
+gpgme_wrap.c pyme/pygpgme.py: gpgme.i gpgme.h copystamp
+ $(SWIG) -python -py3 $(SWIGOPT) \
+ -o $(builddir)/gpgme_wrap.c -outdir $(builddir)/pyme \
+ $<
+
+all-local: gpgme_wrap.c pyme/pygpgme.py copystamp
+ $(PYTHON) $(srcdir)/setup.py build --verbose
+
+clean-local:
+ rm -rf -- build gpgme.h gpgme_wrap.c pyme/pygpgme.py copystamp
+ if test "$(srcdir)" != "$(builddir)" ; then \
+ rm -rf pyme helpers.c helpers.h ; \
+ fi
+
+install-exec-local:
+ $(PYTHON) $(srcdir)/setup.py install \
+ --prefix $(DESTDIR)$(prefix) \
+ --record $(DESTDIR)$(pythondir)/pyme/install_files.txt \
+ --verbose
+
+uninstall-local:
+ xargs <$(DESTDIR)$(pythondir)/pyme/install_files.txt -- rm -rf --
+ rm -rf -- $(DESTDIR)$(pythondir)/pyme
diff --git a/lang/python/setup.py b/lang/python/setup.py
index 562c08f4..f3d91431 100755
--- a/lang/python/setup.py
+++ b/lang/python/setup.py
@@ -22,31 +22,23 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# END OF COPYRIGHT #
-
from distutils.core import setup, Extension
-from distutils.command.build_ext import build_ext
import os, os.path, sys
import subprocess
-sys.path.append("pyme")
-import version
+sys.path.insert(0, os.path.dirname(__file__))
+import pyme.version
def getconfig(what):
- try:
- process = subprocess.Popen(["gpgme-config", "--%s" % what],
- stdout=subprocess.PIPE)
- confdata = process.communicate()[0]
- except OSError as e:
- if e.errno == os.errno.ENOENT:
- raise RuntimeError("Could not call gpgme-config, perhaps install libgpgme-dev")
- else:
- raise
+ confdata = subprocess.Popen(["../../src/gpgme-config", "--%s" % what],
+ stdout=subprocess.PIPE).communicate()[0]
return [x for x in confdata.decode('utf-8').split() if x != '']
include_dirs = [os.getcwd()]
define_macros = []
-library_dirs = []
+library_dirs = ["../../src/.libs"] # XXX uses libtool internals
libs = getconfig('libs')
+
for item in getconfig('cflags'):
if item.startswith("-I"):
include_dirs.append(item[2:])
@@ -82,16 +74,6 @@ if uname_s.startswith("MINGW32"):
library_dirs.append(os.path.join(tgt, item))
break
-try:
- subprocess.call("swig")
-except OSError as e:
- if e.errno == os.errno.ENOENT:
- raise RuntimeError("Could not call swig, perhaps install swig.")
- else:
- raise
-
-subprocess.call(["make swig"], shell=True)
-
swige = Extension("pyme._pygpgme", ["gpgme_wrap.c", "helpers.c"],
include_dirs = include_dirs,
define_macros = define_macros,
@@ -99,15 +81,15 @@ swige = Extension("pyme._pygpgme", ["gpgme_wrap.c", "helpers.c"],
extra_link_args = libs)
setup(name = "pyme",
- version = version.versionstr,
- description = version.description,
- author = version.author,
- author_email = version.author_email,
- url = version.homepage,
+ version=pyme.version.versionstr,
+ description=pyme.version.description,
+ author=pyme.version.author,
+ author_email=pyme.version.author_email,
+ url=pyme.version.homepage,
ext_modules=[swige],
packages = ['pyme', 'pyme.constants', 'pyme.constants.data',
'pyme.constants.keylist', 'pyme.constants.sig'],
- license = version.copyright + \
+ license=pyme.version.copyright + \
", Licensed under the GPL version 2 and the LGPL version 2.1"
)
diff --git a/m4/ax_pkg_swig.m4 b/m4/ax_pkg_swig.m4
new file mode 100644
index 00000000..d836eec8
--- /dev/null
+++ b/m4/ax_pkg_swig.m4
@@ -0,0 +1,135 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PKG_SWIG([major.minor.micro], [action-if-found], [action-if-not-found])
+#
+# DESCRIPTION
+#
+# This macro searches for a SWIG installation on your system. If found,
+# then SWIG is AC_SUBST'd; if not found, then $SWIG is empty. If SWIG is
+# found, then SWIG_LIB is set to the SWIG library path, and AC_SUBST'd.
+#
+# You can use the optional first argument to check if the version of the
+# available SWIG is greater than or equal to the value of the argument. It
+# should have the format: N[.N[.N]] (N is a number between 0 and 999. Only
+# the first N is mandatory.) If the version argument is given (e.g.
+# 1.3.17), AX_PKG_SWIG checks that the swig package is this version number
+# or higher.
+#
+# As usual, action-if-found is executed if SWIG is found, otherwise
+# action-if-not-found is executed.
+#
+# In configure.in, use as:
+#
+# AX_PKG_SWIG(1.3.17, [], [ AC_MSG_ERROR([SWIG is required to build..]) ])
+# AX_SWIG_ENABLE_CXX
+# AX_SWIG_MULTI_MODULE_SUPPORT
+# AX_SWIG_PYTHON
+#
+# LICENSE
+#
+# Copyright (c) 2008 Sebastian Huber
+# Copyright (c) 2008 Alan W. Irwin
+# Copyright (c) 2008 Rafael Laboissiere
+# Copyright (c) 2008 Andrew Collier
+# Copyright (c) 2011 Murray Cumming
+#
+# 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 2 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 .
+#
+# 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 11
+
+AC_DEFUN([AX_PKG_SWIG],[
+ # Ubuntu has swig 2.0 as /usr/bin/swig2.0
+ AC_PATH_PROGS([SWIG],[swig swig2.0])
+ if test -z "$SWIG" ; then
+ m4_ifval([$3],[$3],[:])
+ elif test -n "$1" ; then
+ AC_MSG_CHECKING([SWIG version])
+ [swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
+ AC_MSG_RESULT([$swig_version])
+ if test -n "$swig_version" ; then
+ # Calculate the required version number components
+ [required=$1]
+ [required_major=`echo $required | sed 's/[^0-9].*//'`]
+ if test -z "$required_major" ; then
+ [required_major=0]
+ fi
+ [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
+ [required_minor=`echo $required | sed 's/[^0-9].*//'`]
+ if test -z "$required_minor" ; then
+ [required_minor=0]
+ fi
+ [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
+ [required_patch=`echo $required | sed 's/[^0-9].*//'`]
+ if test -z "$required_patch" ; then
+ [required_patch=0]
+ fi
+ # Calculate the available version number components
+ [available=$swig_version]
+ [available_major=`echo $available | sed 's/[^0-9].*//'`]
+ if test -z "$available_major" ; then
+ [available_major=0]
+ fi
+ [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
+ [available_minor=`echo $available | sed 's/[^0-9].*//'`]
+ if test -z "$available_minor" ; then
+ [available_minor=0]
+ fi
+ [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
+ [available_patch=`echo $available | sed 's/[^0-9].*//'`]
+ if test -z "$available_patch" ; then
+ [available_patch=0]
+ fi
+ # Convert the version tuple into a single number for easier comparison.
+ # Using base 100 should be safe since SWIG internally uses BCD values
+ # to encode its version number.
+ required_swig_vernum=`expr $required_major \* 10000 \
+ \+ $required_minor \* 100 \+ $required_patch`
+ available_swig_vernum=`expr $available_major \* 10000 \
+ \+ $available_minor \* 100 \+ $available_patch`
+
+ if test $available_swig_vernum -lt $required_swig_vernum; then
+ AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version.])
+ SWIG=''
+ m4_ifval([$3],[$3],[])
+ else
+ AC_MSG_CHECKING([for SWIG library])
+ SWIG_LIB=`$SWIG -swiglib`
+ AC_MSG_RESULT([$SWIG_LIB])
+ m4_ifval([$2],[$2],[])
+ fi
+ else
+ AC_MSG_WARN([cannot determine SWIG version])
+ SWIG=''
+ m4_ifval([$3],[$3],[])
+ fi
+ fi
+ AC_SUBST([SWIG_LIB])
+])
diff --git a/m4/m4_ax_swig_python.m4 b/m4/m4_ax_swig_python.m4
new file mode 100644
index 00000000..bf22558f
--- /dev/null
+++ b/m4/m4_ax_swig_python.m4
@@ -0,0 +1,64 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_swig_python.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_SWIG_PYTHON([use-shadow-classes = {no, yes}])
+#
+# DESCRIPTION
+#
+# Checks for Python and provides the $(AX_SWIG_PYTHON_CPPFLAGS), and
+# $(AX_SWIG_PYTHON_OPT) output variables.
+#
+# $(AX_SWIG_PYTHON_OPT) contains all necessary SWIG options to generate
+# code for Python. Shadow classes are enabled unless the value of the
+# optional first argument is exactly 'no'. If you need multi module
+# support (provided by the AX_SWIG_MULTI_MODULE_SUPPORT macro) use
+# $(AX_SWIG_PYTHON_LIBS) to link against the appropriate library. It
+# contains the SWIG Python runtime library that is needed by the type
+# check system for example.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Sebastian Huber
+# Copyright (c) 2008 Alan W. Irwin
+# Copyright (c) 2008 Rafael Laboissiere
+# Copyright (c) 2008 Andrew Collier
+#
+# 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 2 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 .
+#
+# 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 10
+
+AU_ALIAS([SWIG_PYTHON], [AX_SWIG_PYTHON])
+AC_DEFUN([AX_SWIG_PYTHON],[
+ AC_REQUIRE([AX_PKG_SWIG])
+ AC_REQUIRE([AX_PYTHON_DEVEL])
+ test "x$1" != "xno" || swig_shadow=" -noproxy"
+ AC_SUBST([AX_SWIG_PYTHON_OPT],[-python$swig_shadow])
+ AC_SUBST([AX_SWIG_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS])
+])