setup.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import sys,os
  3. from setuptools import setup,Extension
  4. from setuptools.command.build_ext import build_ext
  5. from subprocess import run,PIPE
  6. cache_path = os.path.join(os.environ['HOME'],'.cache','mmgen')
  7. ext_path = os.path.join(cache_path,'secp256k1')
  8. def build_libsecp256k1():
  9. if not os.path.exists(cache_path):
  10. os.makedirs(cache_path)
  11. if not os.path.exists(ext_path):
  12. run(['git','clone','https://github.com/bitcoin-core/secp256k1.git'],check=True,cwd=cache_path)
  13. if not os.path.exists(os.path.join(ext_path,'.libs/libsecp256k1.a')):
  14. run(['./autogen.sh'],check=True,cwd=ext_path)
  15. run(['./configure','CFLAGS=-g -O2 -fPIC'],check=True,cwd=ext_path)
  16. run(['make','-j4'],check=True,cwd=ext_path)
  17. have_msys2 = run(['uname','-s'],stdout=PIPE,check=True).stdout.startswith(b'MSYS_NT')
  18. if have_msys2:
  19. print('MSYS2 system detected')
  20. class my_build_ext(build_ext):
  21. def build_extension(self,ext):
  22. build_libsecp256k1()
  23. build_ext.build_extension(self,ext)
  24. setup(
  25. cmdclass = { 'build_ext': my_build_ext },
  26. ext_modules = [Extension(
  27. name = 'mmgen.secp256k1',
  28. sources = ['extmod/secp256k1mod.c'],
  29. libraries = ([],['gmp'])[have_msys2],
  30. extra_objects = [os.path.join(ext_path,'.libs/libsecp256k1.a')],
  31. include_dirs = [os.path.join(ext_path,'include')],
  32. )]
  33. )