2015-05-05 17:09:44 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2016-06-09 10:38:50 +00:00
|
|
|
# Copyright (C) 2016 g10 Code GmbH
|
2015-05-05 17:09:44 +00:00
|
|
|
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
|
|
|
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
from distutils.core import setup, Extension
|
|
|
|
import os, os.path, sys
|
2016-07-11 14:38:37 +00:00
|
|
|
import glob
|
2015-05-05 17:09:44 +00:00
|
|
|
import subprocess
|
|
|
|
|
2016-07-11 14:38:37 +00:00
|
|
|
# Out-of-tree build of the pyme3 bindings.
|
|
|
|
gpg_error_config = "gpg-error-config"
|
|
|
|
gpgme_config = "gpgme-config"
|
|
|
|
gpgme_h = ""
|
|
|
|
library_dirs = []
|
|
|
|
extra_swig_opts = []
|
|
|
|
|
|
|
|
if os.path.exists("../../src/gpgme-config"):
|
|
|
|
# In-tree build.
|
|
|
|
in_tree = True
|
|
|
|
gpgme_config = "../../src/gpgme-config"
|
|
|
|
gpgme_h = "../../src/gpgme.h"
|
|
|
|
library_dirs = ["../../src/.libs"] # XXX uses libtool internals
|
|
|
|
extra_swig_opts = ["-DHAVE_DATA_H=1"]
|
|
|
|
|
|
|
|
try:
|
|
|
|
subprocess.check_call([gpg_error_config, '--version'],
|
|
|
|
stdout=subprocess.DEVNULL)
|
|
|
|
except:
|
|
|
|
sys.exit("Could not find gpg-error-config. " +
|
|
|
|
"Please install the libgpg-error development package.")
|
|
|
|
|
|
|
|
try:
|
|
|
|
subprocess.check_call([gpgme_config, '--version'],
|
|
|
|
stdout=subprocess.DEVNULL)
|
|
|
|
except:
|
|
|
|
sys.exit("Could not find gpgme-config. " +
|
|
|
|
"Please install the libgpgme development package.")
|
|
|
|
|
|
|
|
def getconfig(what, config=gpgme_config):
|
|
|
|
confdata = subprocess.Popen([config, "--%s" % what],
|
2016-05-11 09:42:00 +00:00
|
|
|
stdout=subprocess.PIPE).communicate()[0]
|
2015-05-05 17:09:44 +00:00
|
|
|
return [x for x in confdata.decode('utf-8').split() if x != '']
|
|
|
|
|
2016-07-11 14:38:37 +00:00
|
|
|
version = version_raw = getconfig("version")[0]
|
|
|
|
if '-' in version:
|
|
|
|
version = version.split('-')[0]
|
|
|
|
major, minor, patch = map(int, version.split('.'))
|
|
|
|
|
|
|
|
if not (major > 1 or (major == 1 and minor >= 6)):
|
|
|
|
sys.exit('Need at least GPGME version 1.6, found {}.'.format(version_raw))
|
|
|
|
|
|
|
|
if not gpgme_h:
|
|
|
|
gpgme_h = os.path.join(getconfig("prefix")[0], "include", "gpgme.h")
|
|
|
|
|
|
|
|
gpg_error_prefix = getconfig("prefix", config=gpg_error_config)[0]
|
|
|
|
gpg_error_h = os.path.join(gpg_error_prefix, "include", "gpg-error.h")
|
|
|
|
if not os.path.exists(gpg_error_h):
|
|
|
|
gpg_error_h = \
|
|
|
|
glob.glob(os.path.join(gpg_error_prefix, "include",
|
|
|
|
"*", "gpg-error.h"))[0]
|
|
|
|
|
|
|
|
print("Building pyme3 using {} and {}.".format(gpgme_h, gpg_error_h))
|
|
|
|
|
|
|
|
# Cleanup gpgme.h from deprecated functions and typedefs.
|
|
|
|
subprocess.check_call(["python3", "gpgme-h-clean.py", gpgme_h],
|
|
|
|
stdout=open("gpgme.h", "w"))
|
|
|
|
subprocess.check_call(["python3", "gpgme-h-clean.py", gpg_error_h],
|
|
|
|
stdout=open("errors.i", "w"))
|
|
|
|
|
2015-05-05 17:09:44 +00:00
|
|
|
include_dirs = [os.getcwd()]
|
|
|
|
define_macros = []
|
|
|
|
libs = getconfig('libs')
|
2016-05-11 09:42:00 +00:00
|
|
|
|
2015-05-05 17:09:44 +00:00
|
|
|
for item in getconfig('cflags'):
|
|
|
|
if item.startswith("-I"):
|
|
|
|
include_dirs.append(item[2:])
|
|
|
|
elif item.startswith("-D"):
|
|
|
|
defitem = item[2:].split("=", 1)
|
|
|
|
if len(defitem)==2:
|
|
|
|
define_macros.append((defitem[0], defitem[1]))
|
|
|
|
else:
|
|
|
|
define_macros.append((defitem[0], None))
|
|
|
|
|
|
|
|
# Adjust include and library locations in case of win32
|
|
|
|
uname_s = os.popen("uname -s").read()
|
|
|
|
if uname_s.startswith("MINGW32"):
|
2016-05-10 11:30:30 +00:00
|
|
|
mnts = [x.split()[0:3:2] for x in os.popen("mount").read().split("\n") if x]
|
2015-05-05 17:09:44 +00:00
|
|
|
tmplist = sorted([(len(x[1]), x[1], x[0]) for x in mnts])
|
|
|
|
tmplist.reverse()
|
|
|
|
extra_dirs = []
|
|
|
|
for item in include_dirs:
|
|
|
|
for ln, mnt, tgt in tmplist:
|
|
|
|
if item.startswith(mnt):
|
|
|
|
item = os.path.normpath(item[ln:])
|
|
|
|
while item[0] == os.path.sep:
|
|
|
|
item = item[1:]
|
|
|
|
extra_dirs.append(os.path.join(tgt, item))
|
|
|
|
break
|
|
|
|
include_dirs += extra_dirs
|
|
|
|
for item in [x[2:] for x in libs if x.startswith("-L")]:
|
|
|
|
for ln, mnt, tgt in tmplist:
|
|
|
|
if item.startswith(mnt):
|
|
|
|
item = os.path.normpath(item[ln:])
|
|
|
|
while item[0] == os.path.sep:
|
|
|
|
item = item[1:]
|
|
|
|
library_dirs.append(os.path.join(tgt, item))
|
|
|
|
break
|
|
|
|
|
2016-07-11 14:38:37 +00:00
|
|
|
# We build an Extension using SWIG, which generates a Python module.
|
|
|
|
# By default, the 'build_py' step is run before 'build_ext', and
|
|
|
|
# therefore the generated Python module is not copied into the build
|
|
|
|
# directory.
|
|
|
|
# Bug: http://bugs.python.org/issue1016626
|
|
|
|
# Workaround:
|
|
|
|
# http://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
|
|
|
|
from distutils.command.build import build
|
|
|
|
class BuildExtFirstHack(build):
|
|
|
|
def run(self):
|
|
|
|
self.run_command('build_ext')
|
|
|
|
build.run(self)
|
|
|
|
|
|
|
|
swige = Extension("pyme._pygpgme", ["gpgme.i", "helpers.c"],
|
|
|
|
swig_opts = ['-py3', '-builtin',
|
|
|
|
'-outdir', 'pyme'] + extra_swig_opts,
|
2015-05-05 17:09:44 +00:00
|
|
|
include_dirs = include_dirs,
|
|
|
|
define_macros = define_macros,
|
|
|
|
library_dirs = library_dirs,
|
|
|
|
extra_link_args = libs)
|
|
|
|
|
2016-07-11 14:38:37 +00:00
|
|
|
setup(name="pyme3",
|
|
|
|
cmdclass={'build': BuildExtFirstHack},
|
2016-06-09 10:38:50 +00:00
|
|
|
version="@VERSION@",
|
|
|
|
description='Python bindings for GPGME GnuPG cryptography library',
|
2016-07-12 14:20:35 +00:00
|
|
|
# XXX add a long description
|
|
|
|
#long_description=long_description,
|
2016-06-09 10:38:50 +00:00
|
|
|
author='The GnuPG hackers',
|
|
|
|
author_email='gnupg-devel@gnupg.org',
|
|
|
|
url='https://www.gnupg.org',
|
2015-05-05 17:09:44 +00:00
|
|
|
ext_modules=[swige],
|
|
|
|
packages = ['pyme', 'pyme.constants', 'pyme.constants.data',
|
2016-05-10 11:30:30 +00:00
|
|
|
'pyme.constants.keylist', 'pyme.constants.sig'],
|
2016-07-12 14:20:35 +00:00
|
|
|
license="LGPL2.1+ (the library), GPL2+ (tests and examples)",
|
|
|
|
classifiers=[
|
|
|
|
'Development Status :: 4 - Beta',
|
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'Topic :: Software Development :: Build Tools',
|
|
|
|
'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)',
|
|
|
|
'Programming Language :: Python :: 3',
|
|
|
|
'Programming Language :: Python :: 3 :: Only',
|
|
|
|
'Programming Language :: Python :: 3.4',
|
|
|
|
'Programming Language :: Python :: 3.5',
|
|
|
|
'Programming Language :: Python :: 3.6',
|
|
|
|
'Operating System :: POSIX',
|
|
|
|
'Operating System :: Microsoft :: Windows',
|
|
|
|
'Topic :: Communications :: Email',
|
|
|
|
'Topic :: Security :: Cryptography',
|
|
|
|
],
|
2015-05-05 17:09:44 +00:00
|
|
|
)
|