-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·73 lines (65 loc) · 2.27 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
from distutils.core import setup, Extension
import os
import sys
from glob import glob
import subprocess
__version__ = "1.0.0"
extra_flags = []
# Remote repo with suitable asn1c (and prebuilt X.509 parser)
ASN1C_REPO = "https://github.com/dmbaggett/asn1c.git"
# Make sure we have an appropriate asn1c distro
rfc5280 = os.path.join("asn1c", "examples", "rfc5280.txt")
if not os.path.exists('asn1c') or not os.path.exists(rfc5280):
if os.path.exists('asn1c'):
import time
os.rename('asn1c', 'asn1c-backup-%s' % time.time())
using_remote_repo = True
try:
remotes = subprocess.Popen(["git", "remote", "-v"], stdout=subprocess.PIPE).communicate()[0].strip()
if remotes.find("arcode.com") >= 0:
using_remote_repo = False
except:
pass
if using_remote_repo:
print "You don't seem to have a suitable ASN.1 compiler; fetching it..."
process = subprocess.Popen(["git", "clone", ASN1C_REPO], shell=False)
while True:
process.poll()
if process.returncode == 0:
break
if process.returncode is not None:
print("git clone of %s failed" % ASN1C_REPO)
exit(process.returncode)
else:
print("fatal: run get-deps to get asn1c")
exit(1)
#
# Add prebuilt X.509 C sources to sources list; these are asn1c examples, but provide everything we
# need.
#
sources = glob(os.path.normpath("asn1c/examples/sample.source.PKIX1/*.c"))
sources.extend(glob(os.path.normpath("asn1c/examples/sample.source.PKCS1/*.c")))
extra_flags.extend([
'-Iasn1c/examples/sample.source.PKIX1',
'-Iasn1c/examples/sample.source.PKCS1',
'-DPDU=Certificate'
])
sources.append('cx509.c')
sources.remove(os.path.normpath('asn1c/examples/sample.source.PKIX1/converter-sample.c'))
setup(
name="cx509",
version=__version__,
author="Dave Baggett",
author_email="[email protected]",
url="http://www.arcode.com/",
description="X.509 certificate parsing using parser generated by asn1c.",
license="MIT",
platforms=["Platform Independent"],
ext_modules=[Extension(
name='cx509',
sources=sources,
extra_compile_args=extra_flags,
extra_link_args=extra_flags
)],
)