setup.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. import os,platform
  11. from pathlib import Path
  12. from subprocess import run,PIPE
  13. from setuptools import setup,Extension
  14. from setuptools.command.build_ext import build_ext
  15. def build_libsecp256k1():
  16. home = Path(os.environ['HOME'])
  17. cache_path = home.joinpath('.cache','mmgen')
  18. src_path = home.joinpath('.cache','mmgen','secp256k1')
  19. lib_file = src_path.joinpath('.libs', 'libsecp256k1.dll.a')
  20. root = Path().resolve().anchor
  21. installed_lib_file = Path(root, 'msys64', 'ucrt64', 'lib', 'libsecp256k1.dll.a')
  22. if installed_lib_file.exists():
  23. return
  24. # fix broken aclocal path:
  25. os.environ['ACLOCAL_PATH'] = '/C/msys64/ucrt64/share/aclocal:/C/msys64/usr/share/aclocal'
  26. if not src_path.exists():
  27. cache_path.mkdir(parents=True)
  28. print('\nCloning libsecp256k1')
  29. run(['git','clone','https://github.com/bitcoin-core/secp256k1.git'],check=True,cwd=cache_path)
  30. if not lib_file.exists():
  31. print(f'\nBuilding libsecp256k1 (cwd={str(src_path)})')
  32. cmds = (
  33. ['sh','./autogen.sh'],
  34. ['sh','./configure','CFLAGS=-g -O2 -fPIC','--disable-dependency-tracking'],
  35. ['mingw32-make','MAKE=mingw32-make'])
  36. for cmd in cmds:
  37. print('Executing {}'.format(' '.join(cmd)))
  38. run(cmd,check=True,cwd=src_path)
  39. if not installed_lib_file.exists():
  40. run(['mingw32-make','install','MAKE=mingw32-make'],check=True,cwd=src_path)
  41. class my_build_ext(build_ext):
  42. def build_extension(self,ext):
  43. if platform.system() == 'Windows':
  44. build_libsecp256k1()
  45. build_ext.build_extension(self,ext)
  46. setup(
  47. cmdclass = { 'build_ext': my_build_ext },
  48. ext_modules = [Extension(
  49. name = 'mmgen.proto.secp256k1.secp256k1',
  50. sources = ['extmod/secp256k1mod.c'],
  51. libraries = ['gmp','secp256k1'] if platform.system() == 'Windows' else ['secp256k1']
  52. )]
  53. )