-from distutils.core import setup, Extension
-from os import *
-from os import _exit
-from errno import *
-import sys
-from sys import stdin, stdout, stderr
-
-def progoutput(cmd):
- p = popen(cmd)
- out = p.readline()
- if p.read() != '': raise 'extra junk from %s' % cmd
- p.close()
- return out.rstrip('\n')
-
-incdirs = []
-libdirs = []
-libs = []
-
-def libconfig(lib, ver):
- config = lib + '-config'
- if system('%s --check %s' % (config, ver)):
- raise '%s version %s not found' % (lib, ver)
- version = progoutput('%s --version' % config)
- for i in progoutput('%s --cflags' % config).split():
- if i[:2] == '-I': incdirs.append(i[2:])
- else: raise 'strange cflags item %s' % i
- for i in progoutput('%s --libs' % config).split():
- if i[:2] == '-L': libdirs.append(i[2:])
- elif i[:2] == '-l': libs.append(i[2:])
- else: raise 'strange libs item %s' % i
-
-def uniquify(l):
- u = {}
- o = []
- for i in l:
- if i not in u:
- o.append(i)
- u[i] = 1
- return o
-
-cflags = []
-libs = []
-libconfig('catacomb', '2.1.0')
-libconfig('mLib', '2.0.3')
-
-class SubprocessFailure (Exception):
- def __init__(me, file, rc):
- me.args = (file, rc)
- me.file = file
- me.rc = rc
- def __str__(me):
- if WIFEXITED(me.rc):
- return '%s failed (rc = %d)' % (me.file, WEXITSTATUS(me.rc))
- elif WIFSIGNALED(me.rc):
- return '%s died (signal %d)' % (me.file, WTERMSIG(me.rc))
- else:
- return '%s died inexplicably' % (me.file)
-
-for g in ['algorithms.h']:
- if type(g) == tuple:
- fin, fout = g
- else:
- root, ext = path.splitext(g)
- fin = root + '.py'
- fout = g
- stin = stat(fin)
- try:
- stout = stat(fout)
- updatep = stin.st_mtime > stout.st_mtime
- except OSError, err:
- if err.errno == ENOENT:
- updatep = True
- else:
- raise
- if updatep:
- kid = fork()
- print 'running %s to create %s' % (fin, fout)
- fnew = fout + '.new'
- if kid == 0:
- try:
- out = file(fnew, 'w')
- dup2(out.fileno(), stdout.fileno())
- out.close()
- execl(sys.executable, sys.executable, fin)
- except:
- stderr.write('error running %s -> %s: %s\n' %
- (fin, fout, sys.exc_info()[1]))
- _exit(127)
- _, rc = waitpid(kid, 0)
- if rc:
- raise SubprocessFailure, (fin, rc)
- rename(fnew, fout)
-
-cat = Extension('catacomb._base',
- ['catacomb.c', 'bytestring.c',
- 'rand.c', 'algorithms.c', 'pubkey.c', 'pgen.c',
- 'mp.c', 'field.c', 'ec.c', 'group.c', 'passphrase.c'],
- ##extra_compile_args = ['-O0'],
- include_dirs = uniquify(incdirs),
- library_dirs = uniquify(libdirs),
- libraries = uniquify(libs))
-
-setup(name = 'Catacomb',
- version = '2.1.0',
- description = 'Interface to Catacomb cryptographic library',
- url = 'http://tux.nsict.org/~mdw/Catacomb-2.1.0',
- author = 'Straylight/Edgeware',
- author_email = 'mdw@nsict.org',
- license = 'GNU General Public License',
- packages = ['catacomb'],
- scripts = ['pwsafe'],
- ext_modules = [cat])
+import distutils.core as DC
+import mdwsetup as MS
+
+MS.pkg_config('catacomb', '2.3.0.1+4')
+MS.pkg_config('mLib', '2.0.4')
+
+cat = DC.Extension('catacomb._base',
+ ['catacomb.c', 'bytestring.c', 'buffer.c',
+ 'rand.c', 'algorithms.c', 'pubkey.c', 'pgen.c',
+ 'mp.c', 'field.c', 'ec.c', 'group.c', 'passphrase.c',
+ 'share.c', 'key.c', 'util.c'],
+ ##extra_compile_args = ['-O0'],
+ include_dirs = MS.uniquify(MS.INCLUDEDIRS),
+ library_dirs = MS.uniquify(MS.LIBDIRS),
+ libraries = MS.uniquify(MS.LIBS))
+
+MS.setup(name = 'catacomb-python',
+ description = 'Interface to Catacomb cryptographic library',
+ url = 'https://git.distorted.org.uk/~mdw/catacomb-python/',
+ author = 'Straylight/Edgeware',
+ author_email = 'mdw@distorted.org.uk',
+ license = 'GNU General Public License',
+ packages = ['catacomb'],
+ scripts = ['pwsafe'],
+ genfiles = [MS.Generate('algorithms.h')],
+ unittest_dir = "t",
+ unittests = ["t-misc", "t-algorithms", "t-bytes", "t-buffer",
+ "t-convert", "t-ec", "t-field", "t-group", "t-key",
+ "t-mp", "t-passphrase", "t-pgen", "t-pubkey",
+ "t-rand", "t-rat", "t-share"],
+ ext_modules = [cat])