2018-10-30 16:23:12 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-10-11 12:58:47 +00:00
|
|
|
#
|
|
|
|
|
# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
|
2024-01-19 11:05:10 +00:00
|
|
|
# Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
|
2023-10-11 12:58:47 +00:00
|
|
|
# Licensed under the GNU General Public License, Version 3:
|
|
|
|
|
# https://www.gnu.org/licenses
|
|
|
|
|
# Public project repositories:
|
2023-11-17 13:35:42 +00:00
|
|
|
# https://github.com/mmgen/mmgen-wallet
|
|
|
|
|
# https://gitlab.com/mmgen/mmgen-wallet
|
2015-01-10 18:52:30 +03:00
|
|
|
|
2024-09-02 09:43:47 +00:00
|
|
|
import sys, os
|
2023-11-13 11:17:28 +00:00
|
|
|
from pathlib import Path
|
2023-10-11 12:58:48 +00:00
|
|
|
from subprocess import run,PIPE
|
2021-09-23 21:15:33 +00:00
|
|
|
from setuptools import setup,Extension
|
2021-09-24 20:07:06 +00:00
|
|
|
from setuptools.command.build_ext import build_ext
|
2019-02-06 10:33:36 +00:00
|
|
|
|
2023-11-13 13:44:53 +00:00
|
|
|
def build_libsecp256k1():
|
2023-11-13 11:17:28 +00:00
|
|
|
|
2023-11-15 10:20:19 +00:00
|
|
|
home = Path(os.environ['HOME'])
|
|
|
|
|
cache_path = home.joinpath('.cache','mmgen')
|
|
|
|
|
src_path = home.joinpath('.cache','mmgen','secp256k1')
|
|
|
|
|
lib_file = src_path.joinpath('.libs', 'libsecp256k1.dll.a')
|
2023-11-13 11:17:29 +00:00
|
|
|
root = Path().resolve().anchor
|
|
|
|
|
installed_lib_file = Path(root, 'msys64', 'ucrt64', 'lib', 'libsecp256k1.dll.a')
|
2023-05-19 20:29:09 +00:00
|
|
|
|
2023-11-13 13:44:53 +00:00
|
|
|
if installed_lib_file.exists():
|
2023-11-13 11:17:29 +00:00
|
|
|
return
|
|
|
|
|
|
2023-11-13 13:44:53 +00:00
|
|
|
# fix broken aclocal path:
|
|
|
|
|
os.environ['ACLOCAL_PATH'] = '/C/msys64/ucrt64/share/aclocal:/C/msys64/usr/share/aclocal'
|
2023-05-19 20:29:09 +00:00
|
|
|
|
2023-11-13 11:17:28 +00:00
|
|
|
if not src_path.exists():
|
2023-11-13 13:44:53 +00:00
|
|
|
cache_path.mkdir(parents=True)
|
2022-05-06 12:52:41 +00:00
|
|
|
print('\nCloning libsecp256k1')
|
2021-09-24 20:07:06 +00:00
|
|
|
run(['git','clone','https://github.com/bitcoin-core/secp256k1.git'],check=True,cwd=cache_path)
|
2023-05-19 20:29:09 +00:00
|
|
|
|
2023-11-13 11:17:28 +00:00
|
|
|
if not lib_file.exists():
|
|
|
|
|
print(f'\nBuilding libsecp256k1 (cwd={str(src_path)})')
|
2023-11-13 13:44:53 +00:00
|
|
|
cmds = (
|
|
|
|
|
['sh','./autogen.sh'],
|
|
|
|
|
['sh','./configure','CFLAGS=-g -O2 -fPIC','--disable-dependency-tracking'],
|
|
|
|
|
['mingw32-make','MAKE=mingw32-make'])
|
2021-09-26 21:16:55 +00:00
|
|
|
for cmd in cmds:
|
|
|
|
|
print('Executing {}'.format(' '.join(cmd)))
|
2023-11-13 11:17:28 +00:00
|
|
|
run(cmd,check=True,cwd=src_path)
|
2017-07-07 16:09:28 +03:00
|
|
|
|
2023-11-13 13:44:53 +00:00
|
|
|
if not installed_lib_file.exists():
|
2023-11-13 11:17:29 +00:00
|
|
|
run(['mingw32-make','install','MAKE=mingw32-make'],check=True,cwd=src_path)
|
|
|
|
|
|
2021-09-24 20:07:06 +00:00
|
|
|
class my_build_ext(build_ext):
|
|
|
|
|
def build_extension(self,ext):
|
2024-09-02 09:43:47 +00:00
|
|
|
if sys.platform == 'win32':
|
2023-11-13 13:44:53 +00:00
|
|
|
build_libsecp256k1()
|
2021-09-24 20:07:06 +00:00
|
|
|
build_ext.build_extension(self,ext)
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
|
cmdclass = { 'build_ext': my_build_ext },
|
|
|
|
|
ext_modules = [Extension(
|
2023-11-15 10:20:19 +00:00
|
|
|
name = 'mmgen.proto.secp256k1.secp256k1',
|
|
|
|
|
sources = ['extmod/secp256k1mod.c'],
|
2024-09-02 09:43:47 +00:00
|
|
|
libraries = ['gmp', 'secp256k1'] if sys.platform == 'win32' else ['secp256k1'],
|
|
|
|
|
include_dirs = ['/usr/local/include'] if sys.platform == 'darwin' else [],
|
|
|
|
|
library_dirs = ['/usr/local/lib'] if sys.platform == 'darwin' else [],
|
2021-09-24 20:07:06 +00:00
|
|
|
)]
|
|
|
|
|
)
|